From d734e32bd56ff6d6cbd3dfb2f176fdaca2182e95 Mon Sep 17 00:00:00 2001 From: Frederic Bouvier Date: Tue, 21 Sep 2010 08:23:13 +0200 Subject: [PATCH] Modified reflect effect to include bumpspec. Original effect untouched --- Aircraft/Generic/Effects/null_bumpspec.png | Bin 0 -> 178 bytes Effects/reflect-bump-spec.eff | 316 +++++++++++++++++++++ Shaders/reflect-bump-spec.frag | 123 ++++++++ Shaders/reflect-bump-spec.vert | 69 +++++ 4 files changed, 508 insertions(+) create mode 100644 Aircraft/Generic/Effects/null_bumpspec.png create mode 100644 Effects/reflect-bump-spec.eff create mode 100644 Shaders/reflect-bump-spec.frag create mode 100644 Shaders/reflect-bump-spec.vert diff --git a/Aircraft/Generic/Effects/null_bumpspec.png b/Aircraft/Generic/Effects/null_bumpspec.png new file mode 100644 index 0000000000000000000000000000000000000000..8d65741bfc3aa1898b3165fbb73ed026ad2a6b01 GIT binary patch literal 178 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx1|;Q0k92}K#X;^)4C~IxyaaOClDyqr82*Fc zg1yTp14TFsJR*x37`TN&n2}-D90{Nxdx@v7EBh@@QC2HXe~B;5Kq1Kz*N775{M_8s zyb=cIqSVBa)D(sC%#sWRcTeAd@J2pypdwyR7sn8e>&Y1zKmN-zur)FL_t + + + Effects/reflect + Effects/model-default + + + + Aircraft/Generic/Effects/null_bumpspec.png + linear-mipmap-linear + repeat + repeat + normalized + + + cubemap + + + + + + Aircraft/Generic/Effects/CubeMaps/fair-sky/fair-sky_px.png + Aircraft/Generic/Effects/CubeMaps/fair-sky/fair-sky_nx.png + Aircraft/Generic/Effects/CubeMaps/fair-sky/fair-sky_py.png + Aircraft/Generic/Effects/CubeMaps/fair-sky/fair-sky_ny.png + 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 + linear-mipmap-linear + repeat + repeat + normalized + + + Aircraft/Generic/Effects/FresnelLookUp.png + linear-mipmap-linear + repeat + repeat + normalized + + + Aircraft/737-300/Models/Effects/733LH.ReflectionMap3.png + linear-mipmap-linear + repeat + repeat + normalized + + transparent + smooth + 0.01 + 0.1 + 0.25 + 0.0 + 0.05 + 0 + + + + 6 + 7 + + + + + + /sim/rendering/shader-effects + + + 2.0 + + + + GL_ARB_shader_objects + GL_ARB_shading_language_100 + GL_ARB_vertex_shader + GL_ARB_fragment_shader + + + + + + + true + + material/active + material/ambient + material/diffuse + material/specular + material/emissive + material/shininess + material/color-mode + + + blend/active + blend/source + blend/destination + + shade-model + cull-face + rendering-hint + + + 0 + texture[0]/image + texture[0]/filter + texture[0]/wrap-s + texture[0]/wrap-t + texture[0]/internal-format + + + + 4 + texture[4]/image + texture[4]/filter + texture[4]/wrap-s + texture[4]/wrap-t + texture[4]/internal-format + + + + 5 + texture[5]/type + + + + + + texture[5]/images + + + + 6 + texture[6]/type + texture[6]/image + texture[6]/filter + texture[6]/wrap-s + texture[6]/wrap-t + + + + 7 + texture[7]/type + texture[7]/image + texture[7]/filter + texture[7]/wrap-s + texture[7]/wrap-t + + + + 8 + texture[8]/image + texture[8]/filter + texture[8]/wrap-s + texture[8]/wrap-t + texture[0]/internal-format + + + + 9 + noise + + + + + Shaders/reflect-bump-spec.vert + Shaders/reflect-bump-spec.frag + + tangent + 6 + + + binormal + 7 + + + + + BaseTex + sampler-2d + 0 + + + + NormalTex + sampler-2d + 4 + + + + Environment + sampler-cube + 5 + + + + Rainbow + sampler-2d + 6 + + + + Fresnel + sampler-2d + 7 + + + + Map + sampler-2d + 8 + + + + Noise + sampler-3d + 9 + + + + + rainbowiness + float + rainbowiness + + + + + fresneliness + float + fresneliness + + + + + noisiness + float + noisiness + + + + + refl_correction + float + refl_correction + + + + + ambient_correction + float + ambient_correction + + + + + reflect_map + float + reflect_map + + + + + diff --git a/Shaders/reflect-bump-spec.frag b/Shaders/reflect-bump-spec.frag new file mode 100644 index 000000000..5ca1a0fae --- /dev/null +++ b/Shaders/reflect-bump-spec.frag @@ -0,0 +1,123 @@ +// -*- mode: C; -*- +// Licence: GPL v2 +// Author: Vivian Meazza. + +#version 120 + +varying vec4 rawpos; +varying vec4 ecPosition; +varying vec3 VNormal; +varying vec3 VTangent; +varying vec3 VBinormal; +varying vec3 Normal; +varying vec4 constantColor; +varying vec3 vViewVec; +varying vec3 reflVec; + +varying vec4 Diffuse; +varying vec3 lightDir, halfVector; +varying float alpha, fogCoord; + +uniform samplerCube Environment; +uniform sampler2D Rainbow; +uniform sampler2D BaseTex; +uniform sampler2D Fresnel; +uniform sampler2D Map; +uniform sampler2D NormalTex; +uniform sampler3D Noise; + +uniform float refl_correction; +uniform float rainbowiness; +uniform float fresneliness; +uniform float noisiness; +uniform float ambient_correction; +uniform float reflect_map; + +void main (void) +{ + vec3 halfV; + float NdotL, NdotHV; + vec4 color = constantColor; + vec4 specular = vec4(0.0); + vec4 ns = texture2D(NormalTex, gl_TexCoord[0].st); + vec3 n = ns.rgb * 2.0 - 1.0; + n = normalize(n.x * VTangent + n.y * VBinormal + n.z * VNormal); + NdotL = max(0.0, dot(n, lightDir)); + + // calculate the specular light + if (NdotL > 0.0) { + color += Diffuse * NdotL; + halfV = normalize(halfVector); + NdotHV = max(dot(n, halfV), 0.0); + if (gl_FrontMaterial.shininess > 0.0) + specular.rgb = (gl_FrontMaterial.specular.rgb * ns.a + * gl_LightSource[0].specular.rgb + * pow(NdotHV, gl_FrontMaterial.shininess)); + } + + color.a = alpha; + color = clamp(color, 0.0, 1.0); + vec4 texel = texture2D(BaseTex, gl_TexCoord[0].st); + vec4 texelcolor = color * texel + specular; + + // calculate the fog factor + float fogCoord = ecPosition.z; + const float LOG2 = 1.442695; + float fogFactor = exp2(-gl_Fog.density * gl_Fog.density * fogCoord * fogCoord * LOG2); + fogFactor = clamp(fogFactor, 0.0, 1.0); + + if(gl_Fog.density == 1.0) + fogFactor=1.0; + + vec3 normal = normalize(VNormal); + vec3 viewVec = normalize(vViewVec); + + // Map a rainbowish color + float v = dot(viewVec, normal); + vec4 rainbow = texture2D(Rainbow, vec2(v, 0.0)); + + // Map a fresnel effect + vec4 fresnel = texture2D(Fresnel, vec2(v, 0.0)); + + // map the refection of the environment + vec4 reflection = textureCube(Environment, reflVec); + + // set the user shininess offse + float transparency_offset = clamp(refl_correction, -1.0, 1.0); + float reflFactor = 0.0; + + if(reflect_map > 0){ + // map the shininess of the object with user input + vec4 map = texture2D(Map, gl_TexCoord[0].st); + //float pam = (map.a * -2) + 1; //reverse map + reflFactor = map.a + transparency_offset; + } else { + // set the reflectivity proportional to shininess with user + // input + reflFactor = (gl_FrontMaterial.shininess / 128) + transparency_offset; + } + + reflFactor = clamp(reflFactor, 0.0, 1.0); + + // set ambient adjustment to remove bluiness with user input + float ambient_offset = clamp(ambient_correction, -1.0, 1.0); + vec4 ambient_Correction = vec4(gl_LightSource[0].ambient.rg, gl_LightSource[0].ambient.b * 0.6, 0.5) * ambient_offset ; + ambient_Correction = clamp(ambient_Correction, -1.0, 1.0); + + // map noise vectore + vec4 noisevec = texture3D(Noise, rawpos.xyz); + + // 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 noisecolor = mix(reflfrescolor, noisevec, noisiness); + vec4 raincolor = vec4(noisecolor.rgb, 1.0) * reflFactor; + + vec4 mixedcolor = mix(texel, raincolor, reflFactor); + + // 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-bump-spec.vert b/Shaders/reflect-bump-spec.vert new file mode 100644 index 000000000..f15fa4221 --- /dev/null +++ b/Shaders/reflect-bump-spec.vert @@ -0,0 +1,69 @@ +// -*- mode: C; -*- +// Licence: GPL v2 +// Author: Vivian Meazza. + +varying vec4 rawpos; +varying vec4 ecPosition; +varying vec3 VNormal; +varying vec3 VTangent;////////////// +varying vec3 VBinormal;///////////// +varying vec3 Normal; +varying vec4 constantColor; +varying vec3 vViewVec; +varying vec3 reflVec; + +varying vec4 Diffuse; +varying vec3 normal, lightDir, halfVector; +varying float alpha, fogCoord; + +uniform mat4 osg_ViewMatrixInverse; + +attribute vec3 tangent; +attribute vec3 binormal; + +void main(void) +{ + rawpos = gl_Vertex; + ecPosition = gl_ModelViewMatrix * gl_Vertex; + vec3 ecPosition3 = vec3(gl_ModelViewMatrix * gl_Vertex) / ecPosition.w; + + vec3 t = normalize(cross(gl_Normal, vec3(1.0,0.0,0.0))); + vec3 b = normalize(cross(gl_Normal,t)); + vec3 n = normalize(gl_Normal); + + VNormal = normalize(gl_NormalMatrix * gl_Normal); + VTangent = normalize(gl_NormalMatrix * tangent); + VBinormal = normalize(gl_NormalMatrix * binormal); + Normal = normalize(gl_Normal); + + lightDir = normalize(vec3(gl_LightSource[0].position)); + halfVector = normalize(gl_LightSource[0].halfVector.xyz); + Diffuse = gl_Color * gl_LightSource[0].diffuse; + //Diffuse= gl_Color.rgb * max(0.0, dot(normalize(VNormal), gl_LightSource[0].position.xyz)); + // Super hack: if diffuse material alpha is less than 1, assume a + // transparency animation is at work + if (gl_FrontMaterial.diffuse.a < 1.0) + alpha = gl_FrontMaterial.diffuse.a; + else + alpha = gl_Color.a; + + fogCoord = abs(ecPosition3.z); + + // Vertex in eye coordinates + vec3 vertVec = ecPosition.xyz; + + vViewVec.x = dot(t, vertVec); + vViewVec.y = dot(b, vertVec); + vViewVec.z = dot(n, vertVec); + + // calculate the reflection vector + vec4 reflect_eye = vec4(reflect(vertVec, VNormal), 0.0); + reflVec = normalize(gl_ModelViewMatrixInverse * reflect_eye).xyz; + + gl_FrontColor = gl_Color; + constantColor = gl_FrontMaterial.emission + + gl_Color * (gl_LightModel.ambient + gl_LightSource[0].ambient); + + gl_Position = ftransform(); + gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; +} \ No newline at end of file