From 3f1f9ffc96540404eeb0e412114164dd0cf6c682 Mon Sep 17 00:00:00 2001 From: FMS-Cat Date: Fri, 26 Mar 2021 21:22:46 +0900 Subject: [PATCH] aesthetics: add noise in post pass, cheating the bloom banding --- src/entities/Post.ts | 2 ++ src/shaders/post.frag | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/entities/Post.ts b/src/entities/Post.ts index afda106..687df28 100644 --- a/src/entities/Post.ts +++ b/src/entities/Post.ts @@ -7,6 +7,7 @@ import quadVert from '../shaders/quad.vert'; import { BufferRenderTarget } from '../heck/BufferRenderTarget'; import { quadGeometry } from '../globals/quadGeometry'; import { dummyRenderTarget } from '../globals/dummyRenderTarget'; +import { randomTexture } from '../globals/randomTexture'; export interface PostOptions { input: BufferRenderTarget; @@ -26,6 +27,7 @@ export class Post extends Entity { { initOptions: { geometry: quadGeometry, target: dummyRenderTarget } }, ); material.addUniformTexture( 'sampler0', options.input.texture ); + material.addUniformTexture( 'samplerRandom', randomTexture.texture ); if ( process.env.DEV ) { if ( module.hot ) { diff --git a/src/shaders/post.frag b/src/shaders/post.frag index f948cdf..9b0f2f4 100644 --- a/src/shaders/post.frag +++ b/src/shaders/post.frag @@ -19,6 +19,9 @@ out vec4 fragColor; uniform float time; uniform vec2 resolution; uniform sampler2D sampler0; +uniform sampler2D samplerRandom; + +#pragma glslify: prng = require( ./-prng ); vec3 colorMap( vec3 i ) { return vec3( @@ -58,7 +61,12 @@ void main() { tex = mix( vec3( 0.0 ), tex, vig ); - vec3 col = pow( saturate( tex.xyz ), vec3( 0.4545 ) ); + vec3 col = tex.xyz; + vec4 seed = texture( samplerRandom, uv ); + prng( seed ); + prng( seed ); + col += ( pow( prng( seed ), 2.2 ) - 0.25 ) * 0.002; + col = pow( saturate( col ), vec3( 0.4545 ) ); col.x = linearstep( 0.0, 1.2, col.x + 0.2 * uv.y ); col.z = linearstep( -0.1, 1.0, col.z ); col = colorMap( col );