|
@@ -1,23 +1,3 @@
|
|
|
-/**
|
|
|
- * Film grain & scanlines shader
|
|
|
- *
|
|
|
- * - ported from HLSL to WebGL / GLSL
|
|
|
- * https://web.archive.org/web/20210226214859/http://www.truevision3d.com/forums/showcase/staticnoise_colorblackwhite_scanline_shaders-t18698.0.html
|
|
|
- *
|
|
|
- * Screen Space Static Postprocessor
|
|
|
- *
|
|
|
- * Produces an analogue noise overlay similar to a film grain / TV static
|
|
|
- *
|
|
|
- * Original implementation and noise algorithm
|
|
|
- * Pat 'Hawthorne' Shearon
|
|
|
- *
|
|
|
- * Optimized scanlines + noise version with intensity scaling
|
|
|
- * Georg 'Leviathan' Steinrohder
|
|
|
- *
|
|
|
- * This version is provided under a Creative Commons Attribution 3.0 License
|
|
|
- * http://creativecommons.org/licenses/by/3.0/
|
|
|
- */
|
|
|
-
|
|
|
const FilmShader = {
|
|
|
|
|
|
name: 'FilmShader',
|
|
@@ -26,10 +6,8 @@ const FilmShader = {
|
|
|
|
|
|
'tDiffuse': { value: null },
|
|
|
'time': { value: 0.0 },
|
|
|
- 'nIntensity': { value: 0.5 },
|
|
|
- 'sIntensity': { value: 0.05 },
|
|
|
- 'sCount': { value: 4096 },
|
|
|
- 'grayscale': { value: 1 }
|
|
|
+ 'intensity': { value: 0.5 },
|
|
|
+ 'grayscale': { value: false }
|
|
|
|
|
|
},
|
|
|
|
|
@@ -48,19 +26,9 @@ const FilmShader = {
|
|
|
|
|
|
#include <common>
|
|
|
|
|
|
- // control parameter
|
|
|
- uniform float time;
|
|
|
-
|
|
|
+ uniform float intensity;
|
|
|
uniform bool grayscale;
|
|
|
-
|
|
|
- // noise effect intensity value (0 = no effect, 1 = full effect)
|
|
|
- uniform float nIntensity;
|
|
|
-
|
|
|
- // scanlines effect intensity value (0 = no effect, 1 = full effect)
|
|
|
- uniform float sIntensity;
|
|
|
-
|
|
|
- // scanlines effect count value (0 = no effect, 4096 = full effect)
|
|
|
- uniform float sCount;
|
|
|
+ uniform float time;
|
|
|
|
|
|
uniform sampler2D tDiffuse;
|
|
|
|
|
@@ -68,32 +36,21 @@ const FilmShader = {
|
|
|
|
|
|
void main() {
|
|
|
|
|
|
- // sample the source
|
|
|
- vec4 cTextureScreen = texture2D( tDiffuse, vUv );
|
|
|
-
|
|
|
- // make some noise
|
|
|
- float dx = rand( vUv + time );
|
|
|
-
|
|
|
- // add noise
|
|
|
- vec3 cResult = cTextureScreen.rgb + cTextureScreen.rgb * clamp( 0.1 + dx, 0.0, 1.0 );
|
|
|
+ vec4 base = texture2D( tDiffuse, vUv );
|
|
|
|
|
|
- // get us a sine and cosine
|
|
|
- vec2 sc = vec2( sin( vUv.y * sCount ), cos( vUv.y * sCount ) );
|
|
|
+ float noise = rand( vUv + time );
|
|
|
|
|
|
- // add scanlines
|
|
|
- cResult += cTextureScreen.rgb * vec3( sc.x, sc.y, sc.x ) * sIntensity;
|
|
|
+ vec3 color = base.rgb + base.rgb * clamp( 0.1 + noise, 0.0, 1.0 );
|
|
|
|
|
|
- // interpolate between source and result by intensity
|
|
|
- cResult = cTextureScreen.rgb + clamp( nIntensity, 0.0,1.0 ) * ( cResult - cTextureScreen.rgb );
|
|
|
+ color = mix( base.rgb, color, intensity );
|
|
|
|
|
|
- // convert to grayscale if desired
|
|
|
- if( grayscale ) {
|
|
|
+ if ( grayscale ) {
|
|
|
|
|
|
- cResult = vec3( cResult.r * 0.3 + cResult.g * 0.59 + cResult.b * 0.11 );
|
|
|
+ color = vec3( luminance( color ) ); // assuming linear-srgb
|
|
|
|
|
|
}
|
|
|
|
|
|
- gl_FragColor = vec4( cResult, cTextureScreen.a );
|
|
|
+ gl_FragColor = vec4( color, base.a );
|
|
|
|
|
|
}`,
|
|
|
|