diff --git a/bloom-combine.glsl b/bloom-combine.glsl index 6d3559a..c8e5965 100644 --- a/bloom-combine.glsl +++ b/bloom-combine.glsl @@ -3,18 +3,20 @@ layout( location = 0 ) uniform sampler2D u_MainInput; layout( location = 1 ) uniform sampler2D u_BlurInput; layout( location = 2 ) uniform vec2 u_OutputSize; +layout( location = 3 ) uniform vec2 u_Parameters; layout( location = 0 ) out vec3 color; void main( void ) { vec2 tmp = gl_FragCoord.xy / u_OutputSize; - float f = .7; + float f = u_Parameters.x; color = textureLod( u_MainInput , tmp , 0 ).rgb; for ( int i = 0 ; i < 5 ; i ++ ) { color += f * textureLod( u_BlurInput , tmp , i ).rgb; - f *= .7; + f *= u_Parameters.y; } + color = color / ( color + 1. ); color = pow( color , vec3( 2.2 ) ); } diff --git a/bloom-highpass.glsl b/bloom-highpass.glsl index 0722000..c8806d3 100644 --- a/bloom-highpass.glsl +++ b/bloom-highpass.glsl @@ -11,5 +11,5 @@ layout( location = 0 ) out vec3 color; void main( void ) { vec3 c = textureLod( u_Input , gl_FragCoord.xy / u_InputSize.xy , u_LOD ).xyz; - color = max( vec3(0) , ( pow( c , vec3(u_FilterParams.x) ) * u_FilterParams.y - c ) / u_FilterParams.z ); + color = max( vec3(0) , ( pow( c , vec3( u_FilterParams.x ) ) * u_FilterParams.y - c ) / u_FilterParams.z ); } diff --git a/bloom.cc b/bloom.cc index edf83b1..4a19d53 100644 --- a/bloom.cc +++ b/bloom.cc @@ -19,7 +19,13 @@ T_BloomPass::T_BloomPass( rtInput_( T_RendertargetSetup( ).add( txInput_ , 0 ).create( ) ) , // txBlur0_( width , height , E_TexType::RGB16F , BloomLevels ) , - txBlur1_( width , height , E_TexType::RGB16F , BloomLevels ) + txBlur1_( width , height , E_TexType::RGB16F , BloomLevels ) , + // + filterParams_{ 1.6 , 1.2 , .95 } , + blurWeights_{ 0.324 , 0.232 , 0.0855 , 0.0205 } , + blurSize_{ 2. } , + combineStrength_( 0.7 ) , + combineAttenuation_( 0.3 ) { txInput_.wrap( E_TexWrap::CLAMP_BORDER ).samplingMode( E_TexSampling::LINEAR ); txBlur0_.wrap( E_TexWrap::CLAMP_EDGE ).samplingMode( E_TexSampling::LINEAR ); @@ -56,7 +62,7 @@ void T_BloomPass::render( ) glUniform2f( U_INPUT_SIZE , input_.width( ) , input_.height( ) ); - glUniform3f( U_PARAMS , 1.6 , 1.2 , .95 ); + glUniform3fv( U_PARAMS , 1 , filterParams_ ); glRectf( -1, -1 , 1 , 1 ); } @@ -69,7 +75,7 @@ void T_BloomPass::render( ) U_DIRECTION = 4 , U_WEIGHTS = 5 , }; - glUniform4f( U_WEIGHTS , 0.324 , 0.232 , 0.0855 , 0.0205 ); + glUniform4fv( U_WEIGHTS , 1 , blurWeights_ ); for ( int i = 0 ; i < 5 ; i ++ ) { // IB RMO B0 B1 B0 B1 B0 // OB B0/0 B1/0 B0/1 B1/1 B0/2 B1/2 @@ -79,9 +85,9 @@ void T_BloomPass::render( ) T_TextureBinding tb( 0 ); uint32_t w , h; if ( i == 0 ) { - tb.set( U_TEXTURE , input_ ); - w = input_.width( ); - h = input_.height( ); + tb.set( U_TEXTURE , txInput_ ); + w = txInput_.width( ); + h = txInput_.height( ); } else { tb.set( U_TEXTURE , txBlur1_ ); w = txBlur1_.width( ) >> ( i - 1 ); @@ -95,14 +101,14 @@ void T_BloomPass::render( ) glUniform1i( U_SOURCE_LOD , slod ); glUniform2f( U_INPUT_SIZE , w , h ); - glUniform2f( U_DIRECTION , 1 , 0 ); + glUniform2f( U_DIRECTION , blurSize_ , 0 ); tb.bind( ); glRectf( -1 , -1 , 1 , 1 ); rtBlur1_[ i ].activate( ); tb.set( U_TEXTURE , txBlur0_ ); tb.bind( ); - glUniform2f( U_DIRECTION , 0 , 1 ); + glUniform2f( U_DIRECTION , 0 , blurSize_ ); glUniform1i( U_SOURCE_LOD , i ); glUniform2f( U_INPUT_SIZE , rtBlur0_[ i ].width( ) , @@ -121,7 +127,21 @@ void T_BloomPass::render( ) blur.set( 1 , txBlur1_ ); blur.bind( ); glUniform2f( 2 , input_.width( ) , input_.height( ) ); + glUniform2f( 3 , combineStrength_ , 1 - combineAttenuation_ ); glRectf( -1, -1 , 1 , 1 ); glBindTexture( GL_TEXTURE_2D , 0 ); } } + +void T_BloomPass::makeUI( ) +{ + if ( !ImGui::CollapsingHeader( "Bloom" ) ) { + return; + } + + ImGui::DragFloat3( "Filter" , filterParams_ , .01f , 0.1 , 10 ); + ImGui::DragFloat4( "Weights" , blurWeights_ , .001f , 0. , 10 ); + ImGui::DragFloat( "Blur size" , &blurSize_ , .001f , 0. , 10 ); + ImGui::DragFloat( "Initial strength" , &combineStrength_ , .001f , 0. , 10 ); + ImGui::DragFloat( "Attenuation" , &combineAttenuation_ , .001f , 0. , 1 ); +} diff --git a/bloom.hh b/bloom.hh index 6fa0d5d..45d3ea1 100644 --- a/bloom.hh +++ b/bloom.hh @@ -23,7 +23,7 @@ struct T_BloomPass __rw__ T_Texture& input ); void render( ); - + void makeUI( ); private: T_Texture& input_; @@ -37,4 +37,10 @@ struct T_BloomPass T_Texture txBlur0_ , txBlur1_; std::vector< T_Rendertarget > rtBlur0_ , rtBlur1_; + + float filterParams_[ 3 ]; + float blurWeights_[ 4 ]; + float blurSize_; + float combineStrength_; + float combineAttenuation_; }; diff --git a/blur-pass.glsl b/blur-pass.glsl index ac0e2e3..7b4299d 100644 --- a/blur-pass.glsl +++ b/blur-pass.glsl @@ -12,21 +12,18 @@ layout( location = 0 ) out vec3 color; void main( void ) { vec2 tmp = gl_FragCoord.xy / u_OutputSize; - const float disp = 4; - vec2 displace1 = vec2( disp * 1 ) * u_Direction / u_OutputSize; - vec2 displace2 = vec2( disp * 2 ) * u_Direction / u_OutputSize; - vec2 displace3 = vec2( disp * 3 ) * u_Direction / u_OutputSize; + vec2 disp = u_Direction / u_OutputSize; float wt = u_Weights.x + u_Weights.y * 2 + u_Weights.z * 2 + u_Weights.w * 2; color = u_Weights.x * textureLod( u_InputTexture , tmp , u_SourceLOD ).xyz + u_Weights.y * ( - textureLod( u_InputTexture , tmp + displace1 , u_SourceLOD ).xyz - + textureLod( u_InputTexture , tmp - displace1 , u_SourceLOD ).xyz ) + textureLod( u_InputTexture , tmp + disp , u_SourceLOD ).xyz + + textureLod( u_InputTexture , tmp - disp , u_SourceLOD ).xyz ) + u_Weights.z * ( - textureLod( u_InputTexture , tmp + displace2 , u_SourceLOD ).xyz - + textureLod( u_InputTexture , tmp - displace2 , u_SourceLOD ).xyz ) + textureLod( u_InputTexture , tmp + disp * 2 , u_SourceLOD ).xyz + + textureLod( u_InputTexture , tmp - disp * 2 , u_SourceLOD ).xyz ) + u_Weights.w * ( - textureLod( u_InputTexture , tmp + displace3 , u_SourceLOD ).xyz - + textureLod( u_InputTexture , tmp - displace3 , u_SourceLOD ).xyz ) + textureLod( u_InputTexture , tmp + disp * 3 , u_SourceLOD ).xyz + + textureLod( u_InputTexture , tmp - disp * 3 , u_SourceLOD ).xyz ) ; color /= wt; } diff --git a/main.cc b/main.cc index 252dcfa..dad8395 100644 --- a/main.cc +++ b/main.cc @@ -166,6 +166,7 @@ void T_Main::makeUI( ) ImGui::Begin( "Yay! Demo!" ); camera.makeUI( ); + bloomPass->makeUI( ); ImGui::End( ); }