From 06e0e5a05710a5034265d20986f3abf527c27207 Mon Sep 17 00:00:00 2001 From: Vivian Meazza Date: Thu, 1 Dec 2011 20:52:59 +0000 Subject: [PATCH] Standardized fog Signed-off-by: Vivian Meazza --- Shaders/tree.frag | 25 +++++++++++++++++++------ Shaders/tree.vert | 18 ++++++++++++++---- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/Shaders/tree.frag b/Shaders/tree.frag index 9dba6fccc..30b7ceaa2 100644 --- a/Shaders/tree.frag +++ b/Shaders/tree.frag @@ -1,9 +1,22 @@ -uniform sampler2D baseTexture; -varying float fogFactor; +#version 120 +uniform sampler2D baseTexture; +//varying float fogFactor; +//varying vec4 PointPos; +//varying vec4 EyePos; -void main(void) -{ +////fog "include" ///// +uniform int fogType; + +vec3 fog_Func(vec3 color, int type); +////////////////////// + +void main(void) +{ vec4 base = texture2D( baseTexture, gl_TexCoord[0].st); - vec4 finalColor = base * gl_Color; - gl_FragColor = mix(gl_Fog.color, finalColor, fogFactor ); + if (base.a <= 0.01) + discard; + vec4 fragColor = base * gl_Color; + //gl_FragColor = vec4(mix(gl_Fog.color.rgb, finalColor.rgb, fogFactor ), finalColor.a); + fragColor.rgb = fog_Func(fragColor.rgb, fogType); + gl_FragColor = fragColor; } diff --git a/Shaders/tree.vert b/Shaders/tree.vert index 8b098175e..51526f655 100644 --- a/Shaders/tree.vert +++ b/Shaders/tree.vert @@ -3,8 +3,15 @@ // normal - x y scaling, z number of varieties // fog coord - rotation // color - xyz of tree quad origin, replicated 4 times. +#version 120 +//varying float fogCoord; +varying vec3 PointPos; +//varying vec4 EyePos; +////fog "include"//////// +uniform int fogType; -varying float fogFactor; +void fog_Func(int type); +///////////////////////// void main(void) { @@ -30,7 +37,10 @@ void main(void) vec4 ambientColor = gl_FrontLightModelProduct.sceneColor + gl_LightSource[0].ambient * gl_FrontMaterial.ambient; gl_FrontColor = ambientColor + gl_LightSource[0].diffuse * vec4(diffuse, 1.0); - float fogCoord = abs(ecPosition.z); - fogFactor = exp( -gl_Fog.density * gl_Fog.density * fogCoord * fogCoord); - fogFactor = clamp(fogFactor, 0.0, 1.0); + //fogCoord = abs(ecPosition.z); + //fogFactor = exp( -gl_Fog.density * gl_Fog.density * fogCoord * fogCoord); + //fogFactor = clamp(fogFactor, 0.0, 1.0); +// fog_Func(fogType); + PointPos = ecPosition; + //EyePos = gl_ModelViewMatrixInverse * vec4(0.0,0.0,0.0,1.0); }