From f71d794866eb0d5a8b7bc3c3416b89faaec42118 Mon Sep 17 00:00:00 2001 From: vmmeazza Date: Wed, 31 Mar 2010 09:11:44 +0000 Subject: [PATCH] Tie reflectivity to material shininess, and provide more user control via parameters. Perpare for cube cross textures. --- Effects/reflect.eff | 89 +++++++++++++++++++++++++++++++++++++------- Shaders/reflect.frag | 36 ++++++++++++------ Shaders/reflect.vert | 4 ++ 3 files changed, 105 insertions(+), 24 deletions(-) diff --git a/Effects/reflect.eff b/Effects/reflect.eff index 59d45e743..25349d905 100644 --- a/Effects/reflect.eff +++ b/Effects/reflect.eff @@ -1,4 +1,46 @@ + Effects/reflect Effects/model-default @@ -6,6 +48,10 @@ cubemap + + + + Aircraft/Generic/Effects/CubeMaps/fair-sky/fair-sky_px.png Aircraft/Generic/Effects/CubeMaps/fair-sky/fair-sky_nx.png @@ -14,6 +60,7 @@ Aircraft/Generic/Effects/CubeMaps/fair-sky/fair-sky_pz.png Aircraft/Generic/Effects/CubeMaps/fair-sky/fair-sky_nz.png + Aircraft/Generic/Effects/Rainbow.png @@ -31,10 +78,14 @@ transparent smooth + 0.075 + 0.075 + 0.0 + 0.1 - + /sim/rendering/shader-effects @@ -52,7 +103,7 @@ - + true @@ -98,7 +149,7 @@ rendering-hint - + 0 @@ -117,12 +168,19 @@ texture[0]/internal-format - + 5 texture[5]/type + + + + + texture[5]/images @@ -212,29 +270,34 @@ rainbowiness float - 0.1 + rainbowiness fresneliness float - 0.1 + fresneliness - + - transparency + refl_correction float - 0.4 + + refl_correction + - + - correction + ambient_correction float - 0.2 + + ambient_correction + diff --git a/Shaders/reflect.frag b/Shaders/reflect.frag index 652effd70..37900d415 100644 --- a/Shaders/reflect.frag +++ b/Shaders/reflect.frag @@ -1,4 +1,8 @@ -#version 120 +// -*- mode: C; -*- +// Licence: GPL v2 +// Author: Vivian Meazza. + +#version 120 varying vec4 ecPosition; varying vec3 VNormal; @@ -16,10 +20,10 @@ uniform sampler2D Rainbow; uniform sampler2D BaseTex; uniform sampler2D Fresnel; -uniform float transparency; +uniform float refl_correction; uniform float rainbowiness; uniform float fresneliness; -uniform float correction; +uniform float ambient_correction; void main (void) @@ -33,7 +37,7 @@ void main (void) n = VNormal; NdotL = max(0.0, dot(n, lightDir)); - //calculate the specular light + // calculate the specular light if (NdotL > 0.0) { color += Diffuse * NdotL; halfV = normalize(halfVector); @@ -68,18 +72,28 @@ void main (void) // Map a fresnel effect vec4 fresnel = texture2D(Fresnel, vec2(v, 0.0)); - //map the refection of the environment + // map the refection of the environment vec4 reflection = textureCube(Environment, reflVec); - //add fringing fresnel and rainbow effects and modulate by transparency + // set the reflectivity proportional to shininess with user + // input ambient + float transparency_offset = clamp(refl_correction, -1.0, 1.0); + float reflFactor = (gl_FrontMaterial.shininess / 128) + transparency_offset; + reflFactor = clamp(reflFactor, 0.0, 1.0); + + // set adjust ambient ambient + float ambient_offset = clamp(ambient_correction, -1.0, 1.0); + vec4 ambient_Correction = mix(gl_LightSource[0].ambient, vec4(1.0, 1.0, 0.9, 1.0), 0.5) + * ambient_offset; + + // add fringing fresnel and rainbow effects and modulate by reflection vec4 reflcolor = mix(reflection, rainbow, rainbowiness * v); vec4 reflfrescolor = mix(reflcolor, fresnel, fresneliness * v); - vec4 raincolor = vec4(reflfrescolor.rgb, 1.0) * transparency; - vec4 mixedcolor = mix(texel, raincolor, transparency); + vec4 raincolor = vec4(reflfrescolor.rgb, 1.0) * reflFactor; + vec4 mixedcolor = mix(texel, raincolor, reflFactor); - //the final reflection - vec4 ambient_correction = mix(gl_LightSource[0].ambient, vec4(1.0, 1.0, 0.9, 1.0), 0.5) * correction; - vec4 reflColor = color * mixedcolor + specular + ambient_correction ; + // the final reflection + vec4 reflColor = color * mixedcolor + specular + ambient_Correction ; reflColor = clamp(reflColor, 0.0, 1.0); gl_FragColor = mix(gl_Fog.color, reflColor, fogFactor); diff --git a/Shaders/reflect.vert b/Shaders/reflect.vert index ea2c651b6..6c3e8fb37 100644 --- a/Shaders/reflect.vert +++ b/Shaders/reflect.vert @@ -1,3 +1,7 @@ +// -*- mode: C; -*- +// Licence: GPL v2 +// Author: Vivian Meazza. + varying vec4 ecPosition; varying vec3 VNormal; varying vec3 Normal;