From 0104dd8ada5afb2807b65c31552792d72cbbaba5 Mon Sep 17 00:00:00 2001 From: Dave Griffiths Date: Mon, 28 Sep 2009 10:30:09 +0100 Subject: [PATCH] added missing shaders --- plant-eyes/scripts/view.ss | 4 +- plant-eyes/shaders/plant-eyes.scm~ | 0 plant-eyes/shaders/twig.frag.glsl | 58 +++++++++++++++++++++++++++ plant-eyes/shaders/twig.frag.glsl_old | 36 +++++++++++++++++ plant-eyes/shaders/twig.vert.glsl | 18 +++++++++ plant-eyes/shaders/twig.vert.glsl_old | 16 ++++++++ 6 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 plant-eyes/shaders/plant-eyes.scm~ create mode 100644 plant-eyes/shaders/twig.frag.glsl create mode 100644 plant-eyes/shaders/twig.frag.glsl_old create mode 100644 plant-eyes/shaders/twig.vert.glsl create mode 100644 plant-eyes/shaders/twig.vert.glsl_old diff --git a/plant-eyes/scripts/view.ss b/plant-eyes/scripts/view.ss index 9940170..c9ac9ac 100644 --- a/plant-eyes/scripts/view.ss +++ b/plant-eyes/scripts/view.ss @@ -17,7 +17,7 @@ (define (ornament-colour) (vector 0.7 0.7 0.7)) (define (pickup-colour) (vector 1 1 1)) -(define (earth-colour) (vector 0.1 0.1 0.1)) +(define (earth-colour) (vector 0.2 0.15 0.1)) (define (dust-colour) (vmul (vector 0.05 0.05 0.05) (* 2 (rndf)))) (define (stones-colour) (vmul (vector 0.5 0.5 0.5) (* (crndf) 0.5))) (define (alive-colour) (vmul (vector 1 1 1) (+ 0.5 (* (rndf) 0.5)))) @@ -34,7 +34,7 @@ (define fin-grow-prob 200) (define max-fins-per-twig 5) -(define above-fog-col (vector 1 1 1)) +(define above-fog-col (vector 0.9 1 0.95)) (define above-fog-strength 0.01) (define ground-change-duration 4) diff --git a/plant-eyes/shaders/plant-eyes.scm~ b/plant-eyes/shaders/plant-eyes.scm~ new file mode 100644 index 0000000..e69de29 diff --git a/plant-eyes/shaders/twig.frag.glsl b/plant-eyes/shaders/twig.frag.glsl new file mode 100644 index 0000000..0bd1a26 --- /dev/null +++ b/plant-eyes/shaders/twig.frag.glsl @@ -0,0 +1,58 @@ +varying vec3 N; +varying vec3 L; +varying vec3 V; +varying vec2 T; +uniform sampler2D Maps[3]; +uniform sampler2D NormalMap; +uniform float Time; + +void main() +{ + vec3 bump = normalize(texture2D(NormalMap,T).xyz*2.0-1.0)-vec3(0,0,1); + vec3 n = normalize(N); + vec3 bn = normalize(N);//+bump*2.0); + vec3 l = normalize(L); + vec3 v = normalize(V); + + float HighlightSize=0.1; + float ShadowSize=0.2; + float OutlineWidth=0.2; + + vec4 MidColour=gl_FrontMaterial.diffuse; + vec4 HighlightColour=MidColour*1.3; + vec4 ShadowColour=MidColour*0.6; + MidColour.a=1.0; + HighlightColour.a=1.0; + ShadowColour.a=1.0; + + vec4 texture; + float t = fract(Time*0.1)*3.0; + if (t<1.0) // mix bet 0 and 1 + { + texture = mix(texture2D(Maps[0], T*10),texture2D(Maps[1], T*10),t); + } + else if (t<2.0 && t>1.0) // mix bet 1 and 2 + { + texture = mix(texture2D(Maps[1], T*10),texture2D(Maps[2], T*10),t-1.0); + } + else // mix bet 2 and 0 + { + texture = mix(texture2D(Maps[2], T*10),texture2D(Maps[0], T*10),t-2.0); + } + + float lambert = dot(l,bn); + vec4 colour = MidColour; + if (lambert > 1.0-HighlightSize) colour = HighlightColour; + if (lambert < ShadowSize) colour = ShadowColour; + + if (dot(n,v) < OutlineWidth) colour = vec4(0,0,0,1); + + + if (dot(n,v) < 0.0) colour = MidColour*texture*0.5; + + // add linear fog + //float fog_factor = clamp((gl_Fog.end - gl_FogFragCoord) * gl_Fog.scale, 0.0, 1.0); + //gl_FragColor = mix(gl_Fog.color, colour, fog_factor); + gl_FragColor = colour; + +} diff --git a/plant-eyes/shaders/twig.frag.glsl_old b/plant-eyes/shaders/twig.frag.glsl_old new file mode 100644 index 0000000..92d2c4e --- /dev/null +++ b/plant-eyes/shaders/twig.frag.glsl_old @@ -0,0 +1,36 @@ +varying vec3 N; +varying vec3 L; +varying vec3 V; +varying vec2 T; +uniform sampler2D BaseMap; +uniform sampler2D AltMap; +uniform sampler2D NormalMap; + +void main() +{ + vec3 bump = normalize(texture2D(NormalMap,T).xyz*2.0-1.0)-vec3(0,0,1); + vec3 n = normalize(N)//+bump*5.0); + vec3 l = normalize(L); + vec3 v = normalize(V); + + float HighlightSize=0.1; + float ShadowSize=0.2; + float OutlineWidth=0.2; + + vec4 MidColour=gl_FrontMaterial.diffuse; + vec4 HighlightColour=MidColour*2.0; + vec4 ShadowColour=MidColour*0.5; + HighlightColour.a=1.0; + ShadowColour.a=1.0; + + float lambert = dot(l,n); + vec4 colour = vec4(MidColour.xyz*lambert,1); + if (lambert > 1.0-HighlightSize) colour = HighlightColour; + if (lambert < ShadowSize) colour = ShadowColour; + if (dot(n,v) < OutlineWidth) colour = vec4(0,0,0,1); + if (dot(n,v) < 0.0) colour = MidColour;//*texture2D(BaseMap, T); + + colour = mix(colour+texture2D(AltMap, T*10.0),colour,smoothstep(4.0,8.0,length(V))); + colour.a *= smoothstep(2.0,6.0,length(V)); + gl_FragColor = colour; +} diff --git a/plant-eyes/shaders/twig.vert.glsl b/plant-eyes/shaders/twig.vert.glsl new file mode 100644 index 0000000..f469755 --- /dev/null +++ b/plant-eyes/shaders/twig.vert.glsl @@ -0,0 +1,18 @@ +// Copyright (C) 2007 Dave Griffiths +// Licence: GPLv2 (see COPYING) +varying vec3 N; +varying vec3 P; +varying vec3 V; +varying vec3 L; +varying vec2 T; + +void main() +{ + N = normalize(gl_NormalMatrix*gl_Normal); + P = gl_Vertex.xyz; + V = -vec3(gl_ModelViewMatrix*gl_Vertex); + vec4 LightPos = gl_LightSource[1].position; + L = vec3((LightPos-gl_Vertex)); + T = gl_MultiTexCoord0.xy; + gl_Position = ftransform(); +} diff --git a/plant-eyes/shaders/twig.vert.glsl_old b/plant-eyes/shaders/twig.vert.glsl_old new file mode 100644 index 0000000..d74a30e --- /dev/null +++ b/plant-eyes/shaders/twig.vert.glsl_old @@ -0,0 +1,16 @@ +varying vec3 N; +varying vec3 P; +varying vec3 V; +varying vec3 L; +varying vec2 T; + +void main() +{ + N = normalize(gl_NormalMatrix*gl_Normal); + P = gl_Vertex.xyz; + V = -vec3(gl_ModelViewMatrix*gl_Vertex); + vec4 LightPos = gl_LightSource[1].position; + L = vec3(gl_ModelViewMatrix*(LightPos-gl_Vertex)); + T = gl_MultiTexCoord0.xy; + gl_Position = ftransform(); +}