Moved shaders to subdir

This commit is contained in:
Emmanuel BENOîT 2017-10-02 09:31:50 +02:00
parent 2318cf5871
commit f79cc70d44
13 changed files with 3 additions and 4 deletions

View file

@ -0,0 +1,15 @@
#version 450 core
layout( location = 0 ) uniform sampler2D u_Input;
layout( location = 1 ) uniform int u_LOD;
layout( location = 2 ) uniform vec2 u_InputSize;
layout( location = 3 ) uniform vec3 u_FilterParams;
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 );
}

28
shaders/blur-pass.glsl Normal file
View file

@ -0,0 +1,28 @@
#version 450 core
layout( location = 0 ) uniform sampler2D u_InputTexture;
layout( location = 1 ) uniform vec2 u_OutputSize;
layout( location = 2 ) uniform int u_SourceLOD;
layout( location = 3 ) uniform vec2 u_Direction;
layout( location = 4 ) uniform vec4 u_Weights;
layout( location = 0 ) out vec3 color;
void main( void )
{
vec2 tmp = gl_FragCoord.xy / 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 + disp , u_SourceLOD ).xyz
+ textureLod( u_InputTexture , tmp - disp , u_SourceLOD ).xyz )
+ u_Weights.z * (
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 + disp * 3 , u_SourceLOD ).xyz
+ textureLod( u_InputTexture , tmp - disp * 3 , u_SourceLOD ).xyz )
;
color /= wt;
}

24
shaders/combine.glsl Normal file
View file

@ -0,0 +1,24 @@
#version 450 core
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 = u_Parameters.x;
color = textureLod( u_MainInput , tmp , 0 ).rgb;
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 );
}
color = color + bloom / 2.2;
color = color / ( color + 1. );
color = pow( color , vec3( 1.0 / 2.2 ) );
}

20
shaders/copy.glsl Normal file
View file

@ -0,0 +1,20 @@
#version 450 core
layout( location = 0 ) uniform sampler2D u_InputTexture;
layout( location = 1 ) uniform int u_LOD;
layout( location = 0 ) out vec4 color;
void main( void )
{
#if 1
vec2 ts = textureSize( u_InputTexture , u_LOD );
vec2 tmp = gl_FragCoord.xy / vec2( 1280. , 720. );
ivec2 pos = ivec2( ts * tmp );
color = texelFetch( u_InputTexture , pos , u_LOD );
#else
vec2 tmp = gl_FragCoord.xy / vec2( 1280. , 720. );
color = textureLod( u_InputTexture , tmp , float( u_LOD ) );
#endif
}

61
shaders/dof-common.glsl Normal file
View file

@ -0,0 +1,61 @@
#version 450 core
//#define USE_RANDOM
layout( location = 0 ) uniform sampler2D u_Input;
layout( location = 1 ) uniform sampler2D u_Depth;
layout( location = 2 ) uniform vec4 u_Parameters;
layout( location = 3 ) uniform float u_Samples;
layout( location = 4 ) uniform vec3 u_ResolutionTime;
#define uSharpDist (u_Parameters.x)
#define uSharpRange (u_Parameters.y)
#define uBlurFalloff (u_Parameters.z)
#define uMaxBlur (u_Parameters.w)
#define uResolution (u_ResolutionTime.xy)
#define uTime (u_ResolutionTime.z)
float CoC( float z )
{
return uMaxBlur * min( 1 ,
max( 0 , abs( z - uSharpDist ) - uSharpRange ) / uBlurFalloff );
}
layout( location = 0 ) out vec3 o_Color;
float hash1( vec2 p )
{
p = fract(p * vec2(5.3987, 5.4421));
p += dot(p.yx, p.xy + vec2(21.5351, 14.3137));
return fract(p.x * p.y * 95.4307);
}
// z: z at UV
// coc: blur radius at UV
// uv: initial coordinate
// blurvec: smudge direction
vec3 depthDirectionalBlur( float z , float coc , vec2 uv , vec2 blurvec )
{
vec3 sumcol = vec3( 0. );
for ( int i = 0 ; i < u_Samples ; i++ ) {
float r = i;
#ifdef USE_RANDOM
r += hash1( uv + float( i + uTime ) ) - .5;
#endif
r = r / float( u_Samples - 1 ) - .5;
vec2 p = uv + r * coc * blurvec;
vec3 smpl = texture( u_Input , p ).xyz;
float sz = texture( u_Depth , p ).x;
if ( sz < z ) {
// if sample is closer consider it's CoC
p = uv + r * min( coc , CoC( sz ) ) * blurvec;
p = uv + r * CoC( sz ) * blurvec;
smpl = texture( u_Input , p ).xyz;
}
sumcol += smpl;
}
sumcol /= float( u_Samples );
sumcol = max( sumcol , 0. );
return sumcol;
}

8
shaders/dof-pass1.glsl Normal file
View file

@ -0,0 +1,8 @@
void main()
{
vec2 uv = gl_FragCoord.xy / uResolution;
vec2 blurvec = vec2( 0 , 1 ) / uResolution;
float z = texture( u_Depth , uv ).x;
o_Color = depthDirectionalBlur( z , CoC( z ) , uv , blurvec );
}

15
shaders/dof-pass2.glsl Normal file
View file

@ -0,0 +1,15 @@
void main()
{
vec2 uv = gl_FragCoord.xy / uResolution;
float z = texture( u_Depth , uv ).x;
vec2 blurdir = vec2( 1.0 , 0.577350269189626 );
vec2 blurvec = normalize( blurdir ) / uResolution;
vec3 color0 = depthDirectionalBlur( z , CoC( z ) , uv , blurvec );
blurdir.x = -1;
blurvec = normalize( blurdir ) / uResolution;
vec3 color1 = depthDirectionalBlur( z , CoC( z ) , uv , blurvec );
o_Color = min( color0 , color1 );
}

18
shaders/downsample.glsl Normal file
View file

@ -0,0 +1,18 @@
#version 450 core
layout( location = 0 ) uniform sampler2D u_InputTexture;
layout( location = 1 ) uniform vec2 u_OutputSize;
layout( location = 2 ) uniform int u_SourceLOD;
layout( location = 0 ) out vec3 color;
void main( void )
{
const vec2 c = gl_FragCoord.xy;
color = ( .25 * (
textureLod( u_InputTexture , ( c + vec2( .5 , .5 ) ) / u_OutputSize , u_SourceLOD )
+ textureLod( u_InputTexture , ( c + vec2(-.5 , .5 ) ) / u_OutputSize , u_SourceLOD )
+ textureLod( u_InputTexture , ( c + vec2( .5 ,-.5 ) ) / u_OutputSize , u_SourceLOD )
+ textureLod( u_InputTexture , ( c + vec2(-.5 ,-.5 ) ) / u_OutputSize , u_SourceLOD )
) ).rgb;
}

12
shaders/fsquad.glsl Normal file
View file

@ -0,0 +1,12 @@
#version 450 core
out gl_PerVertex {
vec4 gl_Position;
};
void main( void )
{
gl_Position = vec4(
vec2( gl_VertexID >> 1 , gl_VertexID & 1 ) * 2 - 1 ,
0 , 1 );
}

6
shaders/map.glsl Normal file
View file

@ -0,0 +1,6 @@
vec2 map( vec3 pos )
{
vec3 q = pos;
q.xy = mod( q.xy + 4. , 8. ) - 4.;
return vec2( length( q ) - 1.8 , step( 0. , 1.9 - length( pos.xy ) ) );
}

View file

@ -0,0 +1,24 @@
#version 450
layout( location = 0 ) uniform float u_Time;
layout( location = 1 ) uniform vec2 u_Resolution;
layout( location = 2 ) uniform vec3 u_CamPos;
layout( location = 3 ) uniform vec3 u_LookAt;
layout( location = 4 ) uniform vec3 u_CamUp;
layout( location = 5 ) uniform float u_NearPlane;
layout( location = 6 ) uniform vec3 u_LightDir;
layout( location = 7 ) uniform vec4 u_Render;
vec3 camPos , lookAt , camUp;
float nearPlane;
layout( location = 0 ) out vec3 o_Color;
layout( location = 1 ) out float o_Z;
void setCamFromUniforms( ) {
camPos = u_CamPos;
lookAt = u_LookAt;
camUp = u_CamUp;
nearPlane = u_NearPlane;
}

164
shaders/raymarcher.glsl Normal file
View file

@ -0,0 +1,164 @@
vec3 getNormal( vec3 pos )
{
vec2 v = vec2( .01 , 0 );
return normalize( vec3(
map( pos + v.xyy ).x - map( pos - v.xyy ).x ,
map( pos + v.yxy ).x - map( pos - v.xyx ).x ,
map( pos + v.yyx ).x - map( pos - v.yyx ).x ) );
}
// -----------------------------------------------------------------------------
vec3 march( vec3 o , vec3 d , int steps , float factor )
{
int i = 0;
float dist = .01 , mat = -1;
for ( ; i < steps ; ++ i ) {
vec2 res = map( o + d * dist );
if ( abs( res.x ) < u_Render.z || dist > u_Render.w ) {
break;
}
dist += res.x * factor;
mat = res.y;
}
return vec3( dist , dist >= u_Render.w ? -1 : mat , i );
}
// -----------------------------------------------------------------------------
/*
float computeIsolines( in float value , in float dist )
{
float f0 = u_DebugPlaneLines.w , f1 = f0 * f0 , f2 = f1 * f0;
vec3 iso = vec3(
fract( value * f0 ) * 2 - 1 ,
fract( value * f1 ) * 2 - 1 ,
fract( value * f2 ) * 2 - 1 );
iso = pow( abs( iso ) , 100 / vec3( f0 , f1 , f2 ) )
* pow( 1 - dist * .02 , 8 );
return mix( mix( iso.z , iso.y , step( 1 / f1 , value ) ) ,
iso.x , step( 1 / f0 , value ) );
}
*/
// -----------------------------------------------------------------------------
void main( )
{
setCamFromUniforms( );
vec2 uv = ( gl_FragCoord.xy / u_Resolution ) * 2 - 1;
vec3 camDir = normalize( lookAt - camPos );
vec3 side = normalize( cross( camUp , camDir ) );
vec3 up = normalize( cross( camDir , side ) );
vec3 rayDir = normalize( camDir * nearPlane
+ uv.x * side * u_Resolution.x / u_Resolution.y
+ uv.y * up );
vec3 r = march( camPos , rayDir , int( u_Render.x ) , u_Render.y );
vec3 hitPos = camPos + rayDir * r.x;
vec3 bc;
if ( r.y >= 0. ) {
bc = vec3( 1. , 1. , 0. );
vec3 hvec = normalize( rayDir - u_LightDir ) ,
norm = getNormal( hitPos );
float ndotl = dot( norm , -normalize( u_LightDir ) ) ,
ndoth = dot( norm , hvec );
float si = pow( clamp( ndoth , 0 , 1 ) , 4 ) ,
di = .6 + .3 * clamp( ndotl , 0 , 1 );
bc = mix( bc * di , vec3( 1. ) , si );
if ( r.y >= 1. ) {
bc += vec3( 5. , .1 , 4. ) * 4;
}
} else {
bc = vec3( 0. );
}
o_Color = bc;
o_Z = r.x;
/*
if ( r.y == -2 ) {
// Debug plane
float v = map( hitPos ).x;
vec3 pc = mix( mix( mix(
vec3( .4 , .05 , .4 ) ,
vec3( .6 , .2 , .2 ) ,
smoothstep( 0 , 1 , v ) ) ,
vec3( 1 , .8 , .4 ) ,
smoothstep( 1 , 2 , v ) ) ,
vec3( 1 ) , smoothstep( 2 , 3 , v ) );
color = vec4( mix( pc , u_DebugPlaneLines.rgb ,
computeIsolines( v , r.x ) ) , 1 );
} else if ( r.y == -1 ) {
color = vec4( 0 , 0 , 0 , 1 );
} else {
// Base color
vec3 bc;
if ( dispMode == 1 ) {
// Single color mode
bc = u_ObjColor;
} else if ( dispMode == 2 ) {
// Iterations
bc = mix( u_ObjColor , u_ObjColor2 , r.z / u_Render.x );
} else {
// Distance
bc = mix( u_ObjColor , u_ObjColor2 , r.x / u_Render.w );
}
// Grid
if ( ( u_DebugFeatures.x & 0x04 ) != 0 ) {
vec3 hpf = fract( hitPos / u_DebugGrid.x ) * 2 - 1;
hpf = 1 - smoothstep( vec3( 1 - .01 / u_DebugGrid.x ) ,
vec3( 1 ) , abs( hpf ) );
bc = mix( u_DebugGrid.yzw , bc ,
hpf.x * hpf.y * hpf.z );
}
if ( ( u_DebugFeatures & 0x20 ) != 0 ) {
vec3 hvec = normalize( rayDir - u_LightDir ) ,
norm = getNormal( hitPos );
float ndotl = dot( norm , -normalize( u_LightDir ) ) ,
ndoth = dot( norm , hvec );
float si = pow( clamp( ndoth , 0 , 1 ) , 4 ) ,
di = .6 + .3 * clamp( ndotl , 0 , 1 );
bc = mix( bc * di , vec3( u_ObjColor ) , si );
}
color = vec4( bc , 1 );
}
*/
// Translucent isolines
/*
if ( ( u_DebugFeatures.x & 3 ) == 2 ) {
float pint = dot( rayDir , u_DebugPlane.xyz );
if ( abs( pint ) > .0001 ) {
float pdist = u_DebugPlane.w - .5 * u_DebugPlaneTrans.x * u_DebugPlaneTrans.y;
float cpdotpn = dot( camPos , u_DebugPlane.xyz );
int nbp = int( u_DebugPlaneTrans.x );
for ( int i = 0 ; i < nbp ; i ++ ) {
float t = ( pdist - cpdotpn ) / pint;
if ( t > .0001 && ( t < r.x || r.y == -1. ) ) {
float v = map( camPos + t * rayDir ).x;
bool inside = v <= 0;
vec3 col = inside
? ( vec3(1) - u_DebugPlaneLines.rgb )
: u_DebugPlaneLines.rgb;
color.rgb += mix(
vec3( .05 ) ,
col * u_DebugPlaneTrans.w ,
computeIsolines( v , t ) )
* ( 1 - min( 1 , abs( v ) / u_DebugPlaneTrans.z ) );
}
pdist += u_DebugPlaneTrans.y;
}
}
}
*/
}