From c383cda2c606f68966c914db905f6e769dd1f41f Mon Sep 17 00:00:00 2001 From: Vivian Meazza Date: Tue, 23 Aug 2011 22:51:14 +0100 Subject: [PATCH] Add support for transparent materials and .dds normal maps. Signed-off-by: Vivian Meazza --- Effects/reflect-bump-spec.eff | 224 ++++++++++++++++++++++++--------- Shaders/reflect-bump-spec.frag | 26 ++-- Shaders/reflect.frag | 12 +- 3 files changed, 187 insertions(+), 75 deletions(-) diff --git a/Effects/reflect-bump-spec.eff b/Effects/reflect-bump-spec.eff index 794e4ee38..fb230aed7 100644 --- a/Effects/reflect-bump-spec.eff +++ b/Effects/reflect-bump-spec.eff @@ -4,9 +4,9 @@ PARAMETERS: There are two forms of cube map texture:- vertical cross and 6 images. Either can be used - alternative forms are shown in and in -The reflection is set proportional to the shininess of the material. Thus by -varying the material shininess value over or between objects the amount of -refection can be controlled. The overall amount of reflection may be +The reflection is set proportional to the shininess of the material. Thus by +varying the material shininess value over or between objects the amount of +refection can be controlled. The overall amount of reflection may be adjusted by the use of -1.0 (fully transparent)- 1.0 (fully opaque). The overall values of the noisiness, coloured fringing or fresnel effect may be adjusted @@ -16,33 +16,35 @@ If your result is too dark/too light the overall ambient light value can be adju by the use of . This correction also takes out some of the blueness added as default to compensate for the lack of reflection. -To use a reflection map set to 1,and the path to the map texture in +To use a reflection map set to 1,and the path to the map texture in A default, null, bumpspec is specified as texture unit 4. To provide a custom bumpspec map, define in the derived effect file -USE: To use the default reflection effect (controlled by material shininess values) use - +If you are using Direct Draw Surface (.dds) files for your bumpmap set to 1. + +USE: To use the default reflection effect (controlled by material shininess values) use + Effects/reflect-bump-spec Fuselage - + To use your own reflection effect, use - + Aircraft/Lightning/Models/Effects/lightningreflect Fuselage - + in your model file. To use your own effect place your efffect file containing something like this: Effects/lightningreflect Effects/reflect-bump-spec - + and the the modified tags in the path as above EXAMPLES: You can find examples of both usages in the Hunter and Lightning models. @@ -104,13 +106,14 @@ EXAMPLES: You can find examples of both usages in the Hunter and Lightning model 0.0 0.05 0 + 0 6 7 - + @@ -133,77 +136,157 @@ EXAMPLES: You can find examples of both usages in the Hunter and Lightning model true - material/active - material/ambient - material/diffuse - material/specular - material/emissive - material/shininess - material/color-mode + + material/active + + + material/ambient + + + material/diffuse + + + material/specular + + + material/emissive + + + material/shininess + + + material/color-mode + - blend/active - blend/source - blend/destination + + blend/active + + + blend/source + + + blend/destination + - shade-model - cull-face - rendering-hint + + 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 + + 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 + + texture[4]/image + + + texture[4]/filter + + + texture[4]/wrap-s + + + texture[4]/wrap-t + + + texture[4]/internal-format + - + 5 - texture[5]/type + + texture[5]/type + - texture[5]/images + + texture[5]/images + 6 - texture[6]/type - texture[6]/image - texture[6]/filter - texture[6]/wrap-s - texture[6]/wrap-t + + 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 + + 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 + + texture[8]/image + + + texture[8]/filter + + + texture[8]/wrap-s + + + texture[8]/wrap-t + + + texture[0]/internal-format + @@ -271,46 +354,67 @@ EXAMPLES: You can find examples of both usages in the Hunter and Lightning model rainbowiness float - rainbowiness + + rainbowiness + fresneliness float - fresneliness + + fresneliness + noisiness float - noisiness + + noisiness + - refl_correction float - refl_correction + + refl_correction + ambient_correction float - ambient_correction + + ambient_correction + reflect_map float - reflect_map + + reflect_map + + + + + + normalmap_dds + float + + normalmap_dds + - + \ No newline at end of file diff --git a/Shaders/reflect-bump-spec.frag b/Shaders/reflect-bump-spec.frag index 30179ff48..4dfb052d6 100644 --- a/Shaders/reflect-bump-spec.frag +++ b/Shaders/reflect-bump-spec.frag @@ -1,6 +1,6 @@ // -*- mode: C; -*- // Licence: GPL v2 -// Author: Vivian Meazza. +// Author: Vivian Meazza. #version 120 @@ -30,6 +30,7 @@ uniform float fresneliness; uniform float noisiness; uniform float ambient_correction; uniform float reflect_map; +uniform float normalmap_dds; void main (void) { @@ -45,6 +46,12 @@ void main (void) 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); + + //fix dds normal + if (normalmap_dds > 0.0) { + n = -n; + } + NdotL = max(0.0, dot(n, lightDir)); // calculate the specular light @@ -58,10 +65,11 @@ void main (void) * pow(NdotHV, gl_FrontMaterial.shininess)); } - color.a = alpha; - color = clamp(color, 0.0, 1.0); + //color.a = alpha; vec4 texel = texture2D(BaseTex, gl_TexCoord[0].st); - vec4 texelcolor = color * texel + specular; + //vec4 texelcolor = color * texel + specular; + color.a = texel.a * alpha; + color = clamp(color, 0.0, 1.0); // calculate the fog factor const float LOG2 = 1.442695; @@ -89,12 +97,12 @@ void main (void) float reflFactor = 0.0; if(reflect_map > 0.0){ - // map the shininess of the object with user input + // 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 + // set the reflectivity proportional to shininess with user input reflFactor = (gl_FrontMaterial.shininess / 128.0) * ns.a + transparency_offset; } @@ -105,7 +113,7 @@ void main (void) 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 + // map noise vector vec4 noisevec = texture3D(Noise, rawpos.xyz); // add fringing fresnel and rainbow effects and modulate by reflection @@ -117,9 +125,9 @@ void main (void) vec4 mixedcolor = mix(texel, raincolor, reflFactor); // the final reflection - vec4 reflColor = vec4(color.rgb * mixedcolor.rgb + specular.rgb + ambient_Correction.rgb, alpha); + vec4 reflColor = vec4(color.rgb * mixedcolor.rgb + specular.rgb + ambient_Correction.rgb, color.a); reflColor = clamp(reflColor, 0.0, 1.0); gl_FragColor = mix(gl_Fog.color, reflColor, fogFactor); -} +} \ No newline at end of file diff --git a/Shaders/reflect.frag b/Shaders/reflect.frag index 422284ad5..16a0d247d 100644 --- a/Shaders/reflect.frag +++ b/Shaders/reflect.frag @@ -51,10 +51,10 @@ void main (void) * 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; +// vec4 texelcolor = color * texel + specular; + color.a = texel.a * alpha; + color = clamp(color, 0.0, 1.0); // calculate the fog factor const float LOG2 = 1.442695; @@ -77,7 +77,7 @@ void main (void) // map the refection of the environment vec4 reflection = textureCube(Environment, reflVec); - // set the user shininess offse + // set the user shininess offset float transparency_offset = clamp(refl_correction, -1.0, 1.0); float reflFactor = 0.0; @@ -100,7 +100,7 @@ void main (void) // vec4 ambient_Correction = vec4(ambient_Correction.rgb, 0.5); ambient_Correction = clamp(ambient_Correction, -1.0, 1.0); - // map noise vectore + // map noise vector vec4 noisevec = texture3D(Noise, rawpos.xyz); // add fringing fresnel and rainbow effects and modulate by reflection @@ -112,7 +112,7 @@ void main (void) vec4 mixedcolor = mix(texel, raincolor, reflFactor); // the final reflection - vec4 reflColor = vec4(color.rgb * mixedcolor.rgb + specular.rgb + ambient_Correction.rgb, alpha); + vec4 reflColor = vec4(color.rgb * mixedcolor.rgb + specular.rgb + ambient_Correction.rgb, color.a); reflColor = clamp(reflColor, 0.0, 1.0); gl_FragColor = mix(gl_Fog.color, reflColor, fogFactor);