From 3db77a1625bab9ceda10f5fa66e38bbc0e42393f Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Fri, 22 Mar 2013 17:29:32 -0700 Subject: anholt: Switch the shaders from my demo to shader_test files. --- shaders/anholt/12.shader_test | 23 ++++++ shaders/anholt/15.shader_test | 17 ++++ shaders/anholt/18.shader_test | 24 ++++++ shaders/anholt/3.shader_test | 151 ++++++++++++++++++++++++++++++++++ shaders/anholt/6.shader_test | 59 +++++++++++++ shaders/anholt/9.shader_test | 16 ++++ shaders/anholt/glass.frag | 113 ------------------------- shaders/anholt/ground.frag | 21 ----- shaders/anholt/shadow.frag | 3 - shaders/anholt/shadowmap_display.frag | 7 -- 10 files changed, 290 insertions(+), 144 deletions(-) create mode 100644 shaders/anholt/12.shader_test create mode 100644 shaders/anholt/15.shader_test create mode 100644 shaders/anholt/18.shader_test create mode 100644 shaders/anholt/3.shader_test create mode 100644 shaders/anholt/6.shader_test create mode 100644 shaders/anholt/9.shader_test delete mode 100644 shaders/anholt/glass.frag delete mode 100644 shaders/anholt/ground.frag delete mode 100644 shaders/anholt/shadow.frag delete mode 100644 shaders/anholt/shadowmap_display.frag (limited to 'shaders') diff --git a/shaders/anholt/12.shader_test b/shaders/anholt/12.shader_test new file mode 100644 index 0000000..73d9ec8 --- /dev/null +++ b/shaders/anholt/12.shader_test @@ -0,0 +1,23 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +uniform sampler2D shadow_sampler; +varying vec2 texcoord; + +void main() +{ + gl_FragColor = texture2D(shadow_sampler, texcoord); +} + +[vertex shader] +#version 120 + +varying vec2 texcoord; + +void main() +{ + gl_Position = gl_Vertex; + texcoord = (gl_Vertex.xy + vec2(1, 1)) / 2.0; +} + diff --git a/shaders/anholt/15.shader_test b/shaders/anholt/15.shader_test new file mode 100644 index 0000000..30ba541 --- /dev/null +++ b/shaders/anholt/15.shader_test @@ -0,0 +1,17 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +uniform vec4 color; +void main() +{ + gl_FragColor = color; +} + +[vertex shader] +attribute vec4 position; +void main() +{ + gl_Position = position; +} + diff --git a/shaders/anholt/18.shader_test b/shaders/anholt/18.shader_test new file mode 100644 index 0000000..e59381e --- /dev/null +++ b/shaders/anholt/18.shader_test @@ -0,0 +1,24 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +#version 130 +uniform ivec4 color; +out ivec4 out_color; + +void main() +{ + out_color = color; +} + +[vertex shader] +#version 130 +in vec4 position; +void main() +{ + gl_Position = position; +} + +event = 0x0001 +event = 0x0001 +300 frames in 5.40 secs: 55.6 fps diff --git a/shaders/anholt/3.shader_test b/shaders/anholt/3.shader_test new file mode 100644 index 0000000..0a0c5a1 --- /dev/null +++ b/shaders/anholt/3.shader_test @@ -0,0 +1,151 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +#version 120 + +#define I965_HACK 1 + +varying vec3 light_surf; +varying vec3 eye_surf; +varying vec3 tangent_surf; +varying vec4 shadow_coords; +varying vec2 texcoord; +uniform sampler2D normal_sampler; +uniform sampler2D heightmap_sampler; +uniform sampler2DShadow shadow_sampler; +uniform float F0, ni, ward_mm_inv, ward_mn_inv, ward_nn_inv; + +float schlick_fresnel(float n_dot_l) +{ + return F0 + (1 - F0) * pow(1 - n_dot_l, 5); +} + +void main() +{ + float shadow = shadow2DProj(shadow_sampler, shadow_coords).x; + const vec4 material_color = vec4(0.7, 0.5, 0.3, 0.0); + vec4 color; + float s = .7; + float d = 1 - s; + float Ii = 0.9; /*intensity of incoming light */ + float Iia = .1 * Ii; /*intensity of ambient light */ + + float Rs = 0; + float D; + + float Rd = (1 - F0) * 2; + + /* Calculate ambient lighting. */ + + /* Ambient occlusion factor -- sample the height map we + * used to generate the normal map, and reduce intensity in + * the valleys. + */ + float heightmap = texture2D(heightmap_sampler, texcoord).x; + float Ra = Rd * (.8 + .2 * heightmap); + color = material_color * Iia * Ra; + + /* Calculate specular and diffuse lighting */ +#if !I965_HACK + if (shadow > 0) { +#endif + vec3 l = normalize(light_surf); + vec3 v = normalize(eye_surf); + vec3 h = normalize(l + v); + vec3 t = normalize(tangent_surf); + vec3 n = texture2D(normal_sampler, texcoord).xyz * 2 - 1; + /* Hack: Reduce the significance of our normal map, which + * otherwise looks incongruous with the straight edges. + */ + n = normalize(n + vec3(0,0,1)); + + float n_dot_l = dot(n, l); + float n_dot_v = dot(n, v); + float n_dot_h = dot(n, h); + float v_dot_h = dot(v, h); + float cos2_alpha = n_dot_h * n_dot_h; + float tan2_alpha = (1 - cos2_alpha) / cos2_alpha; + + /* Aniso BRDF from Ward's "Measuring and Modeling + * Anisotropic Reflection". + */ + + /* Make phi be the angle between the projections of + * the tangent and half-angle vectors onto the + * surface plane (z=0). Doing it right would involve + * projecting onto the plane defined by n. + */ + float cos_phi = dot(normalize(t.xy), normalize(h.xy)); + + float cos2_phi_over_m2 = (cos_phi * cos_phi) * ward_mm_inv; + float sin2_phi_over_n2 = (1 - cos_phi * cos_phi) * ward_nn_inv; + D = exp(-tan2_alpha * (cos2_phi_over_m2 + sin2_phi_over_n2)); + Rs = 2 * schlick_fresnel(n_dot_l) * D * + inversesqrt(n_dot_l * n_dot_v) * ward_mn_inv; + Rs *= s; + + color += max(0, n_dot_l) * step(0, n_dot_v) * + vec4(material_color.xyz * + ((Rd * d + Rs) * Ii * shadow), + material_color.w); +#if !I965_HACK + } +#endif + + gl_FragColor = color; + + /* Debugging scalars -- Map [0,1] to [0.5,1] to catch negative + * values. Multiply by the step function to catch when + * the scalar won't come into play because Rs == 0. + */ +#if 0 + /* Constant visualization */ + gl_FragColor = vec4(vec3(F0 / 2 + .5), 1); +#endif +#if 0 + /* Normal visualization */ + gl_FragColor = vec4((normal.x + 1) / 2, + (normal.y + 1) / 2, + (normal.z + 1) / 2, + 0); +#endif +#if 0 + /* Sampler visualization */ + gl_FragColor = texture2D(normal_sampler, texcoord); +#endif +} + +[vertex shader] +#version 120 + +uniform vec3 light_eye; +varying vec2 texcoord; +varying vec3 light_surf; +varying vec3 eye_surf; +varying vec3 tangent_surf; +varying vec4 shadow_coords; +uniform mat4 mvp, mv, light_mvp; + +void main() +{ + mat3 mv3 = mat3(mv); + vec3 t = (mv3 * gl_MultiTexCoord1.xyz); + vec3 n = (mv3 * gl_Normal); + + gl_Position = mvp * gl_Vertex; + + mat3 tbn = mat3(t, + cross(n, t), + n + ); + + vec3 vertex_eye = vec3(mv * gl_Vertex); + shadow_coords = light_mvp * gl_Vertex; + + texcoord = gl_MultiTexCoord0.xy; + light_surf = normalize((light_eye - vertex_eye) * tbn); + eye_surf = normalize((-vertex_eye) * tbn); + tangent_surf = gl_MultiTexCoord1.xyz * tbn; +} + diff --git a/shaders/anholt/6.shader_test b/shaders/anholt/6.shader_test new file mode 100644 index 0000000..9e7084b --- /dev/null +++ b/shaders/anholt/6.shader_test @@ -0,0 +1,59 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +#version 120 + +uniform vec3 light_eye; +varying vec4 shadow_coords; +varying vec3 vertex_eye; +uniform sampler2DShadow shadow_sampler; + +void main() +{ + vec3 normal = vec3(0.0, 0.0, 1.0); + vec4 material_color = vec4(1.0, 0.7, 0.5, 1.0); + float shadow = shadow2DProj(shadow_sampler, shadow_coords).x; + vec3 l = normalize(light_eye - vertex_eye); + vec3 v = normalize(-vertex_eye); + vec3 h = normalize(l + v); + float n_dot_l = dot(normal, l); + vec3 diffuse = material_color.xyz * n_dot_l; + float specular = pow(dot(normal, h), 16.0); + gl_FragColor = step(0.0, n_dot_l) * + vec4((diffuse + vec3(specular)) * shadow, material_color.w); +} + +[vertex shader] +/*uniform vec3 light_eye; +varying vec2 texcoord; +varying vec3 light_surf; +varying vec3 eye_surf; +varying vec3 tangent_surf; +*/ +varying vec3 vertex_eye; +varying vec4 shadow_coords; +uniform mat4 mvp, mv, light_mvp; + +void main() +{ +/* vec3 t = (mv * vec4(1.0,, 0.0)).xyz; + vec3 n = (mv * vec4(gl_Normal, 0.0)).xyz; +*/ + gl_Position = mvp * gl_Vertex; + vertex_eye = vec3(mv * gl_Vertex); + shadow_coords = light_mvp * gl_Vertex; +/* + mat3 tbn = mat3(t, + cross(n, t), + n + ); + + + texcoord = vec2(gl_MultiTexCoord0.x * 4, gl_MultiTexCoord0.y); + light_surf = normalize((light_eye - vertex_eye) * tbn); + eye_surf = normalize((-vertex_eye) * tbn); + tangent_surf = gl_MultiTexCoord1.xyz * tbn; +*/ +} + diff --git a/shaders/anholt/9.shader_test b/shaders/anholt/9.shader_test new file mode 100644 index 0000000..63eb250 --- /dev/null +++ b/shaders/anholt/9.shader_test @@ -0,0 +1,16 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +void main() +{ +} + +[vertex shader] +uniform mat4 mvp, mv; + +void main() +{ + gl_Position = mvp * gl_Vertex; +} + diff --git a/shaders/anholt/glass.frag b/shaders/anholt/glass.frag deleted file mode 100644 index 88c29b8..0000000 --- a/shaders/anholt/glass.frag +++ /dev/null @@ -1,113 +0,0 @@ -#version 120 - -#define I965_HACK 1 - -varying vec3 light_surf; -varying vec3 eye_surf; -varying vec3 tangent_surf; -varying vec4 shadow_coords; -varying vec2 texcoord; -uniform sampler2D normal_sampler; -uniform sampler2D heightmap_sampler; -uniform sampler2DShadow shadow_sampler; -uniform float F0, ni, ward_mm_inv, ward_mn_inv, ward_nn_inv; - -float schlick_fresnel(float n_dot_l) -{ - return F0 + (1 - F0) * pow(1 - n_dot_l, 5); -} - -void main() -{ - float shadow = shadow2DProj(shadow_sampler, shadow_coords).x; - const vec4 material_color = vec4(0.7, 0.5, 0.3, 0.0); - vec4 color; - float s = .7; - float d = 1 - s; - float Ii = 0.9; /*intensity of incoming light */ - float Iia = .1 * Ii; /*intensity of ambient light */ - - float Rs = 0; - float D; - - float Rd = (1 - F0) * 2; - - /* Calculate ambient lighting. */ - - /* Ambient occlusion factor -- sample the height map we - * used to generate the normal map, and reduce intensity in - * the valleys. - */ - float heightmap = texture2D(heightmap_sampler, texcoord).x; - float Ra = Rd * (.8 + .2 * heightmap); - color = material_color * Iia * Ra; - - /* Calculate specular and diffuse lighting */ -#if !I965_HACK - if (shadow > 0) { -#endif - vec3 l = normalize(light_surf); - vec3 v = normalize(eye_surf); - vec3 h = normalize(l + v); - vec3 t = normalize(tangent_surf); - vec3 n = texture2D(normal_sampler, texcoord).xyz * 2 - 1; - /* Hack: Reduce the significance of our normal map, which - * otherwise looks incongruous with the straight edges. - */ - n = normalize(n + vec3(0,0,1)); - - float n_dot_l = dot(n, l); - float n_dot_v = dot(n, v); - float n_dot_h = dot(n, h); - float v_dot_h = dot(v, h); - float cos2_alpha = n_dot_h * n_dot_h; - float tan2_alpha = (1 - cos2_alpha) / cos2_alpha; - - /* Aniso BRDF from Ward's "Measuring and Modeling - * Anisotropic Reflection". - */ - - /* Make phi be the angle between the projections of - * the tangent and half-angle vectors onto the - * surface plane (z=0). Doing it right would involve - * projecting onto the plane defined by n. - */ - float cos_phi = dot(normalize(t.xy), normalize(h.xy)); - - float cos2_phi_over_m2 = (cos_phi * cos_phi) * ward_mm_inv; - float sin2_phi_over_n2 = (1 - cos_phi * cos_phi) * ward_nn_inv; - D = exp(-tan2_alpha * (cos2_phi_over_m2 + sin2_phi_over_n2)); - Rs = 2 * schlick_fresnel(n_dot_l) * D * - inversesqrt(n_dot_l * n_dot_v) * ward_mn_inv; - Rs *= s; - - color += max(0, n_dot_l) * step(0, n_dot_v) * - vec4(material_color.xyz * - ((Rd * d + Rs) * Ii * shadow), - material_color.w); -#if !I965_HACK - } -#endif - - gl_FragColor = color; - - /* Debugging scalars -- Map [0,1] to [0.5,1] to catch negative - * values. Multiply by the step function to catch when - * the scalar won't come into play because Rs == 0. - */ -#if 0 - /* Constant visualization */ - gl_FragColor = vec4(vec3(F0 / 2 + .5), 1); -#endif -#if 0 - /* Normal visualization */ - gl_FragColor = vec4((normal.x + 1) / 2, - (normal.y + 1) / 2, - (normal.z + 1) / 2, - 0); -#endif -#if 0 - /* Sampler visualization */ - gl_FragColor = texture2D(normal_sampler, texcoord); -#endif -} diff --git a/shaders/anholt/ground.frag b/shaders/anholt/ground.frag deleted file mode 100644 index 60d0c09..0000000 --- a/shaders/anholt/ground.frag +++ /dev/null @@ -1,21 +0,0 @@ -#version 120 - -uniform vec3 light_eye; -varying vec4 shadow_coords; -varying vec3 vertex_eye; -uniform sampler2DShadow shadow_sampler; - -void main() -{ - vec3 normal = vec3(0.0, 0.0, 1.0); - vec4 material_color = vec4(1.0, 0.7, 0.5, 1.0); - float shadow = shadow2DProj(shadow_sampler, shadow_coords).x; - vec3 l = normalize(light_eye - vertex_eye); - vec3 v = normalize(-vertex_eye); - vec3 h = normalize(l + v); - float n_dot_l = dot(normal, l); - vec3 diffuse = material_color.xyz * n_dot_l; - float specular = pow(dot(normal, h), 16.0); - gl_FragColor = step(0.0, n_dot_l) * - vec4((diffuse + vec3(specular)) * shadow, material_color.w); -} diff --git a/shaders/anholt/shadow.frag b/shaders/anholt/shadow.frag deleted file mode 100644 index 9198103..0000000 --- a/shaders/anholt/shadow.frag +++ /dev/null @@ -1,3 +0,0 @@ -void main() -{ -} diff --git a/shaders/anholt/shadowmap_display.frag b/shaders/anholt/shadowmap_display.frag deleted file mode 100644 index 8db3446..0000000 --- a/shaders/anholt/shadowmap_display.frag +++ /dev/null @@ -1,7 +0,0 @@ -uniform sampler2D shadow_sampler; -varying vec2 texcoord; - -void main() -{ - gl_FragColor = texture2D(shadow_sampler, texcoord); -} -- cgit v1.2.3