Bloom controls
This commit is contained in:
parent
802418219b
commit
f3d709a48d
6 changed files with 48 additions and 22 deletions
|
@ -3,18 +3,20 @@
|
||||||
layout( location = 0 ) uniform sampler2D u_MainInput;
|
layout( location = 0 ) uniform sampler2D u_MainInput;
|
||||||
layout( location = 1 ) uniform sampler2D u_BlurInput;
|
layout( location = 1 ) uniform sampler2D u_BlurInput;
|
||||||
layout( location = 2 ) uniform vec2 u_OutputSize;
|
layout( location = 2 ) uniform vec2 u_OutputSize;
|
||||||
|
layout( location = 3 ) uniform vec2 u_Parameters;
|
||||||
|
|
||||||
layout( location = 0 ) out vec3 color;
|
layout( location = 0 ) out vec3 color;
|
||||||
|
|
||||||
void main( void )
|
void main( void )
|
||||||
{
|
{
|
||||||
vec2 tmp = gl_FragCoord.xy / u_OutputSize;
|
vec2 tmp = gl_FragCoord.xy / u_OutputSize;
|
||||||
float f = .7;
|
float f = u_Parameters.x;
|
||||||
color = textureLod( u_MainInput , tmp , 0 ).rgb;
|
color = textureLod( u_MainInput , tmp , 0 ).rgb;
|
||||||
for ( int i = 0 ; i < 5 ; i ++ ) {
|
for ( int i = 0 ; i < 5 ; i ++ ) {
|
||||||
color += f * textureLod( u_BlurInput , tmp , i ).rgb;
|
color += f * textureLod( u_BlurInput , tmp , i ).rgb;
|
||||||
f *= .7;
|
f *= u_Parameters.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
color = color / ( color + 1. );
|
color = color / ( color + 1. );
|
||||||
color = pow( color , vec3( 2.2 ) );
|
color = pow( color , vec3( 2.2 ) );
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,5 +11,5 @@ layout( location = 0 ) out vec3 color;
|
||||||
void main( void )
|
void main( void )
|
||||||
{
|
{
|
||||||
vec3 c = textureLod( u_Input , gl_FragCoord.xy / u_InputSize.xy , u_LOD ).xyz;
|
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 );
|
||||||
}
|
}
|
||||||
|
|
36
bloom.cc
36
bloom.cc
|
@ -19,7 +19,13 @@ T_BloomPass::T_BloomPass(
|
||||||
rtInput_( T_RendertargetSetup( ).add( txInput_ , 0 ).create( ) ) ,
|
rtInput_( T_RendertargetSetup( ).add( txInput_ , 0 ).create( ) ) ,
|
||||||
//
|
//
|
||||||
txBlur0_( width , height , E_TexType::RGB16F , BloomLevels ) ,
|
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 );
|
txInput_.wrap( E_TexWrap::CLAMP_BORDER ).samplingMode( E_TexSampling::LINEAR );
|
||||||
txBlur0_.wrap( E_TexWrap::CLAMP_EDGE ).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 ,
|
glUniform2f( U_INPUT_SIZE ,
|
||||||
input_.width( ) ,
|
input_.width( ) ,
|
||||||
input_.height( ) );
|
input_.height( ) );
|
||||||
glUniform3f( U_PARAMS , 1.6 , 1.2 , .95 );
|
glUniform3fv( U_PARAMS , 1 , filterParams_ );
|
||||||
glRectf( -1, -1 , 1 , 1 );
|
glRectf( -1, -1 , 1 , 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +75,7 @@ void T_BloomPass::render( )
|
||||||
U_DIRECTION = 4 ,
|
U_DIRECTION = 4 ,
|
||||||
U_WEIGHTS = 5 ,
|
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 ++ ) {
|
for ( int i = 0 ; i < 5 ; i ++ ) {
|
||||||
// IB RMO B0 B1 B0 B1 B0
|
// IB RMO B0 B1 B0 B1 B0
|
||||||
// OB B0/0 B1/0 B0/1 B1/1 B0/2 B1/2
|
// 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 );
|
T_TextureBinding tb( 0 );
|
||||||
uint32_t w , h;
|
uint32_t w , h;
|
||||||
if ( i == 0 ) {
|
if ( i == 0 ) {
|
||||||
tb.set( U_TEXTURE , input_ );
|
tb.set( U_TEXTURE , txInput_ );
|
||||||
w = input_.width( );
|
w = txInput_.width( );
|
||||||
h = input_.height( );
|
h = txInput_.height( );
|
||||||
} else {
|
} else {
|
||||||
tb.set( U_TEXTURE , txBlur1_ );
|
tb.set( U_TEXTURE , txBlur1_ );
|
||||||
w = txBlur1_.width( ) >> ( i - 1 );
|
w = txBlur1_.width( ) >> ( i - 1 );
|
||||||
|
@ -95,14 +101,14 @@ void T_BloomPass::render( )
|
||||||
glUniform1i( U_SOURCE_LOD , slod );
|
glUniform1i( U_SOURCE_LOD , slod );
|
||||||
glUniform2f( U_INPUT_SIZE , w , h );
|
glUniform2f( U_INPUT_SIZE , w , h );
|
||||||
|
|
||||||
glUniform2f( U_DIRECTION , 1 , 0 );
|
glUniform2f( U_DIRECTION , blurSize_ , 0 );
|
||||||
tb.bind( );
|
tb.bind( );
|
||||||
glRectf( -1 , -1 , 1 , 1 );
|
glRectf( -1 , -1 , 1 , 1 );
|
||||||
|
|
||||||
rtBlur1_[ i ].activate( );
|
rtBlur1_[ i ].activate( );
|
||||||
tb.set( U_TEXTURE , txBlur0_ );
|
tb.set( U_TEXTURE , txBlur0_ );
|
||||||
tb.bind( );
|
tb.bind( );
|
||||||
glUniform2f( U_DIRECTION , 0 , 1 );
|
glUniform2f( U_DIRECTION , 0 , blurSize_ );
|
||||||
glUniform1i( U_SOURCE_LOD , i );
|
glUniform1i( U_SOURCE_LOD , i );
|
||||||
glUniform2f( U_INPUT_SIZE ,
|
glUniform2f( U_INPUT_SIZE ,
|
||||||
rtBlur0_[ i ].width( ) ,
|
rtBlur0_[ i ].width( ) ,
|
||||||
|
@ -121,7 +127,21 @@ void T_BloomPass::render( )
|
||||||
blur.set( 1 , txBlur1_ );
|
blur.set( 1 , txBlur1_ );
|
||||||
blur.bind( );
|
blur.bind( );
|
||||||
glUniform2f( 2 , input_.width( ) , input_.height( ) );
|
glUniform2f( 2 , input_.width( ) , input_.height( ) );
|
||||||
|
glUniform2f( 3 , combineStrength_ , 1 - combineAttenuation_ );
|
||||||
glRectf( -1, -1 , 1 , 1 );
|
glRectf( -1, -1 , 1 , 1 );
|
||||||
glBindTexture( GL_TEXTURE_2D , 0 );
|
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 );
|
||||||
|
}
|
||||||
|
|
8
bloom.hh
8
bloom.hh
|
@ -23,7 +23,7 @@ struct T_BloomPass
|
||||||
__rw__ T_Texture& input );
|
__rw__ T_Texture& input );
|
||||||
|
|
||||||
void render( );
|
void render( );
|
||||||
|
void makeUI( );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
T_Texture& input_;
|
T_Texture& input_;
|
||||||
|
@ -37,4 +37,10 @@ struct T_BloomPass
|
||||||
|
|
||||||
T_Texture txBlur0_ , txBlur1_;
|
T_Texture txBlur0_ , txBlur1_;
|
||||||
std::vector< T_Rendertarget > rtBlur0_ , rtBlur1_;
|
std::vector< T_Rendertarget > rtBlur0_ , rtBlur1_;
|
||||||
|
|
||||||
|
float filterParams_[ 3 ];
|
||||||
|
float blurWeights_[ 4 ];
|
||||||
|
float blurSize_;
|
||||||
|
float combineStrength_;
|
||||||
|
float combineAttenuation_;
|
||||||
};
|
};
|
||||||
|
|
|
@ -12,21 +12,18 @@ layout( location = 0 ) out vec3 color;
|
||||||
void main( void )
|
void main( void )
|
||||||
{
|
{
|
||||||
vec2 tmp = gl_FragCoord.xy / u_OutputSize;
|
vec2 tmp = gl_FragCoord.xy / u_OutputSize;
|
||||||
const float disp = 4;
|
vec2 disp = u_Direction / u_OutputSize;
|
||||||
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;
|
|
||||||
float wt = u_Weights.x + u_Weights.y * 2 + u_Weights.z * 2 + u_Weights.w * 2;
|
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
|
color = u_Weights.x * textureLod( u_InputTexture , tmp , u_SourceLOD ).xyz
|
||||||
+ u_Weights.y * (
|
+ u_Weights.y * (
|
||||||
textureLod( u_InputTexture , tmp + displace1 , u_SourceLOD ).xyz
|
textureLod( u_InputTexture , tmp + disp , u_SourceLOD ).xyz
|
||||||
+ textureLod( u_InputTexture , tmp - displace1 , u_SourceLOD ).xyz )
|
+ textureLod( u_InputTexture , tmp - disp , u_SourceLOD ).xyz )
|
||||||
+ u_Weights.z * (
|
+ u_Weights.z * (
|
||||||
textureLod( u_InputTexture , tmp + displace2 , u_SourceLOD ).xyz
|
textureLod( u_InputTexture , tmp + disp * 2 , u_SourceLOD ).xyz
|
||||||
+ textureLod( u_InputTexture , tmp - displace2 , u_SourceLOD ).xyz )
|
+ textureLod( u_InputTexture , tmp - disp * 2 , u_SourceLOD ).xyz )
|
||||||
+ u_Weights.w * (
|
+ u_Weights.w * (
|
||||||
textureLod( u_InputTexture , tmp + displace3 , u_SourceLOD ).xyz
|
textureLod( u_InputTexture , tmp + disp * 3 , u_SourceLOD ).xyz
|
||||||
+ textureLod( u_InputTexture , tmp - displace3 , u_SourceLOD ).xyz )
|
+ textureLod( u_InputTexture , tmp - disp * 3 , u_SourceLOD ).xyz )
|
||||||
;
|
;
|
||||||
color /= wt;
|
color /= wt;
|
||||||
}
|
}
|
||||||
|
|
1
main.cc
1
main.cc
|
@ -166,6 +166,7 @@ void T_Main::makeUI( )
|
||||||
ImGui::Begin( "Yay! Demo!" );
|
ImGui::Begin( "Yay! Demo!" );
|
||||||
|
|
||||||
camera.makeUI( );
|
camera.makeUI( );
|
||||||
|
bloomPass->makeUI( );
|
||||||
|
|
||||||
ImGui::End( );
|
ImGui::End( );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue