Vignette effect
This commit is contained in:
parent
3e6e9e1ba8
commit
942a4fea21
3 changed files with 77 additions and 17 deletions
shaders
|
@ -5,22 +5,54 @@
|
|||
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 = 3 ) uniform vec2 u_Bloom;
|
||||
|
||||
layout( location = 0 ) out vec3 color;
|
||||
// Vignette parameters
|
||||
// 1.x = shape multiplier
|
||||
// 1.y = shape power
|
||||
// 1.z = aspect ratio
|
||||
// 1.w = reverse power multiplier
|
||||
// 2.x = apply base
|
||||
// 2.y = apply max
|
||||
layout( location = 4 ) uniform vec4 u_Vignette1;
|
||||
layout( location = 5 ) uniform vec2 u_Vignette2;
|
||||
|
||||
#define uVigShapeMul (u_Vignette1.x)
|
||||
#define uVigShapePow (u_Vignette1.y)
|
||||
#define uVigAspect (u_Vignette1.z)
|
||||
#define uVigShapeReverse (u_Vignette1.w)
|
||||
#define uVigApplyBase (u_Vignette2.x)
|
||||
#define uVigApplyMax (u_Vignette2.y)
|
||||
|
||||
|
||||
layout( location = 0 ) out vec3 o_Color;
|
||||
|
||||
void main( void )
|
||||
{
|
||||
vec2 tmp = gl_FragCoord.xy / u_OutputSize;
|
||||
float f = u_Parameters.x;
|
||||
color = textureLod( u_MainInput , tmp , 0 ).rgb;
|
||||
vec2 pos = gl_FragCoord.xy / u_OutputSize;
|
||||
float f = u_Bloom.x;
|
||||
o_Color = textureLod( u_MainInput , pos , 0 ).rgb;
|
||||
|
||||
// Bloom
|
||||
vec3 bloom = vec3( 0 );
|
||||
for ( int i = 0 ; i < 6 ; i ++ ) {
|
||||
bloom += f * textureLod( u_BlurInput , tmp , i ).rgb;
|
||||
f = pow( f , u_Parameters.y + 1 );
|
||||
bloom += f * textureLod( u_BlurInput , pos , i ).rgb;
|
||||
f = pow( f , u_Bloom.y + 1 );
|
||||
}
|
||||
color = color + bloom / 2.2;
|
||||
o_Color = o_Color + bloom / 2.2;
|
||||
|
||||
color = color / ( color + 1. );
|
||||
color = pow( color , vec3( 1.0 / 2.2 ) );
|
||||
// Vignette
|
||||
vec2 vShape = pow( abs( pos * 2 - 1 ) * uVigShapeMul ,
|
||||
vec2( uVigShapePow ) );
|
||||
float vignette = 1 - pow(
|
||||
2 * ( uVigAspect * vShape.x + ( 1 - uVigAspect) * vShape.y ) ,
|
||||
1 / ( uVigShapePow * uVigShapeReverse ) );
|
||||
o_Color *= uVigApplyBase + smoothstep(
|
||||
uVigApplyBase , uVigApplyBase + uVigApplyMax , vignette );
|
||||
|
||||
// Reinhart
|
||||
o_Color = o_Color / ( o_Color + 1. );
|
||||
|
||||
// Gamma
|
||||
o_Color = pow( o_Color , vec3( 1.0 / 2.2 ) );
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue