Skip to content

Commit

Permalink
FilmShader: Fix deterioration. (#26908)
Browse files Browse the repository at this point in the history
* 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 #26908 (comment)
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 <michael.herzog@human-interactive.org>
  • Loading branch information
kaisavi and Mugen87 committed Oct 7, 2023
1 parent af8349b commit f7b0c24
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion examples/jsm/shaders/FilmShader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit f7b0c24

Please sign in to comment.