Prechádzať zdrojové kódy

FilmShader: Fix deterioration. (#26908)

* Fix FilmShader Deterioration

Incorrect usage of the ``rand`` function causes the film effect to deteriorate with large time values. This is fixed by applying a modulus to the time value, restraining it to the expected [0,1]x[0,1] range of the ``rand`` function

https://github.com/mrdoob/three.js/blob/76e1fb171af400afebbfb851ef7d7297625c5f0a/src/renderers/shaders/ShaderChunk/common.glsl.js#L24

* Use fract() & stricter constraint

Addresses https://github.com/mrdoob/three.js/pull/26908#discussion_r1349323634
the constraining function is now fract() instead of mod(n,1.0), and wraps vUv + time instead of only time

* Update FilmShader.js

Clean up.

---------

Co-authored-by: Michael Herzog <[email protected]>
Kaisa 1 rok pred
rodič
commit
f7b0c24b6a
1 zmenil súbory, kde vykonal 1 pridanie a 1 odobranie
  1. 1 1
      examples/jsm/shaders/FilmShader.js

+ 1 - 1
examples/jsm/shaders/FilmShader.js

@@ -38,7 +38,7 @@ const FilmShader = {
 
 			vec4 base = texture2D( tDiffuse, vUv );
 
-			float noise = rand( vUv + time );
+			float noise = rand( fract( vUv + time ) );
 
 			vec3 color = base.rgb + base.rgb * clamp( 0.1 + noise, 0.0, 1.0 );