1
0
Fork 0

Add support for transparent materials and .dds normal maps.

Signed-off-by: Vivian Meazza <vivian.meazza@lineone.net>
This commit is contained in:
Vivian Meazza 2011-08-23 22:51:14 +01:00
parent 8caf2ef24d
commit c383cda2c6
3 changed files with 187 additions and 75 deletions

View file

@ -4,9 +4,9 @@
PARAMETERS: There are two forms of cube map texture:- vertical cross and 6 images. PARAMETERS: There are two forms of cube map texture:- vertical cross and 6 images.
Either can be used - alternative forms are shown in <parameters> and in <texture-unit> Either can be used - alternative forms are shown in <parameters> and in <texture-unit>
The reflection is set proportional to the shininess of the material. Thus by 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 varying the material shininess value over or between objects the amount of
refection can be controlled. The overall amount of reflection may be refection can be controlled. The overall amount of reflection may be
adjusted by the use of <refl_correction> -1.0 (fully transparent)- 1.0 (fully opaque). adjusted by the use of <refl_correction> -1.0 (fully transparent)- 1.0 (fully opaque).
The overall values of the noisiness, coloured fringing or fresnel effect may be adjusted 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 <ambient_correction>. This correction also takes out some of the blueness by the use of <ambient_correction>. This correction also takes out some of the blueness
added as default to compensate for the lack of reflection. added as default to compensate for the lack of reflection.
To use a reflection map set <reflect_map> to 1,and the path to the map texture in To use a reflection map set <reflect_map> to 1,and the path to the map texture in
<texture n="8"> <texture n="8">
A default, null, bumpspec is specified as texture unit 4. To provide a custom bumpspec map, A default, null, bumpspec is specified as texture unit 4. To provide a custom bumpspec map,
define <texture n="4"> in the derived effect file define <texture n="4"> 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 <normalmap_dds> to 1.
USE: To use the default reflection effect (controlled by material shininess values) use
<effect> <effect>
<inherits-from>Effects/reflect-bump-spec</inherits-from> <inherits-from>Effects/reflect-bump-spec</inherits-from>
<object-name>Fuselage</object-name> <object-name>Fuselage</object-name>
</effect> </effect>
To use your own reflection effect, use To use your own reflection effect, use
<effect> <effect>
<inherits-from>Aircraft/Lightning/Models/Effects/lightningreflect</inherits-from> <inherits-from>Aircraft/Lightning/Models/Effects/lightningreflect</inherits-from>
<object-name>Fuselage</object-name> <object-name>Fuselage</object-name>
</effect> </effect>
in your model file. in your model file.
To use your own effect place your efffect file containing something like this: To use your own effect place your efffect file containing something like this:
<name>Effects/lightningreflect</name> <name>Effects/lightningreflect</name>
<inherits-from>Effects/reflect-bump-spec</inherits-from> <inherits-from>Effects/reflect-bump-spec</inherits-from>
and the the modified tags in the path as above and the the modified tags in the path as above
EXAMPLES: You can find examples of both usages in the Hunter and Lightning models. 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
<refl_correction>0.0</refl_correction> <refl_correction>0.0</refl_correction>
<ambient_correction>0.05</ambient_correction> <ambient_correction>0.05</ambient_correction>
<reflect_map>0</reflect_map> <reflect_map>0</reflect_map>
<normalmap_dds>0</normalmap_dds>
</parameters> </parameters>
<generate> <generate>
<tangent type="int">6</tangent> <tangent type="int">6</tangent>
<binormal type="int">7</binormal> <binormal type="int">7</binormal>
</generate> </generate>
<technique n="9"> <technique n="9">
<predicate> <predicate>
<and> <and>
@ -133,77 +136,157 @@ EXAMPLES: You can find examples of both usages in the Hunter and Lightning model
<pass> <pass>
<lighting>true</lighting> <lighting>true</lighting>
<material> <material>
<active><use>material/active</use></active> <active>
<ambient><use>material/ambient</use></ambient> <use>material/active</use>
<diffuse><use>material/diffuse</use></diffuse> </active>
<specular><use>material/specular</use></specular> <ambient>
<emissive><use>material/emissive</use></emissive> <use>material/ambient</use>
<shininess><use>material/shininess</use></shininess> </ambient>
<color-mode><use>material/color-mode</use></color-mode> <diffuse>
<use>material/diffuse</use>
</diffuse>
<specular>
<use>material/specular</use>
</specular>
<emissive>
<use>material/emissive</use>
</emissive>
<shininess>
<use>material/shininess</use>
</shininess>
<color-mode>
<use>material/color-mode</use>
</color-mode>
</material> </material>
<blend> <blend>
<active><use>blend/active</use></active> <active>
<source><use>blend/source</use></source> <use>blend/active</use>
<destination><use>blend/destination</use></destination> </active>
<source>
<use>blend/source</use>
</source>
<destination>
<use>blend/destination</use>
</destination>
</blend> </blend>
<shade-model><use>shade-model</use></shade-model> <shade-model>
<cull-face><use>cull-face</use></cull-face> <use>shade-model</use>
<rendering-hint><use>rendering-hint</use></rendering-hint> </shade-model>
<cull-face>
<use>cull-face</use>
</cull-face>
<rendering-hint>
<use>rendering-hint</use>
</rendering-hint>
<texture-unit> <texture-unit>
<unit>0</unit> <unit>0</unit>
<image><use>texture[0]/image</use></image> <image>
<filter><use>texture[0]/filter</use></filter> <use>texture[0]/image</use>
<wrap-s><use>texture[0]/wrap-s</use></wrap-s> </image>
<wrap-t><use>texture[0]/wrap-t</use></wrap-t> <filter>
<internal-format><use>texture[0]/internal-format</use></internal-format> <use>texture[0]/filter</use>
</filter>
<wrap-s>
<use>texture[0]/wrap-s</use>
</wrap-s>
<wrap-t>
<use>texture[0]/wrap-t</use>
</wrap-t>
<internal-format>
<use>texture[0]/internal-format</use>
</internal-format>
</texture-unit> </texture-unit>
<texture-unit> <texture-unit>
<unit>4</unit> <unit>4</unit>
<image><use>texture[4]/image</use></image> <image>
<filter><use>texture[4]/filter</use></filter> <use>texture[4]/image</use>
<wrap-s><use>texture[4]/wrap-s</use></wrap-s> </image>
<wrap-t><use>texture[4]/wrap-t</use></wrap-t> <filter>
<internal-format><use>texture[4]/internal-format</use></internal-format> <use>texture[4]/filter</use>
</filter>
<wrap-s>
<use>texture[4]/wrap-s</use>
</wrap-s>
<wrap-t>
<use>texture[4]/wrap-t</use>
</wrap-t>
<internal-format>
<use>texture[4]/internal-format</use>
</internal-format>
</texture-unit> </texture-unit>
<texture-unit> <texture-unit>
<unit>5</unit> <unit>5</unit>
<type><use>texture[5]/type</use></type> <type>
<use>texture[5]/type</use>
</type>
<!-- use this form for a cube cross --> <!-- use this form for a cube cross -->
<!--<image><use>texture[5]/image</use></image>--> <!--<image><use>texture[5]/image</use></image>-->
<!-- use this form for a 6 image cube map --> <!-- use this form for a 6 image cube map -->
<images><use>texture[5]/images</use></images> <images>
<use>texture[5]/images</use>
</images>
</texture-unit> </texture-unit>
<texture-unit> <texture-unit>
<unit>6</unit> <unit>6</unit>
<type><use>texture[6]/type</use></type> <type>
<image><use>texture[6]/image</use></image> <use>texture[6]/type</use>
<filter><use>texture[6]/filter</use></filter> </type>
<wrap-s><use>texture[6]/wrap-s</use></wrap-s> <image>
<wrap-t><use>texture[6]/wrap-t</use></wrap-t> <use>texture[6]/image</use>
</image>
<filter>
<use>texture[6]/filter</use>
</filter>
<wrap-s>
<use>texture[6]/wrap-s</use>
</wrap-s>
<wrap-t>
<use>texture[6]/wrap-t</use>
</wrap-t>
</texture-unit> </texture-unit>
<texture-unit> <texture-unit>
<unit>7</unit> <unit>7</unit>
<type><use>texture[7]/type</use></type> <type>
<image><use>texture[7]/image</use></image> <use>texture[7]/type</use>
<filter><use>texture[7]/filter</use></filter> </type>
<wrap-s><use>texture[7]/wrap-s</use></wrap-s> <image>
<wrap-t><use>texture[7]/wrap-t</use></wrap-t> <use>texture[7]/image</use>
</image>
<filter>
<use>texture[7]/filter</use>
</filter>
<wrap-s>
<use>texture[7]/wrap-s</use>
</wrap-s>
<wrap-t>
<use>texture[7]/wrap-t</use>
</wrap-t>
</texture-unit> </texture-unit>
<texture-unit> <texture-unit>
<unit>8</unit> <unit>8</unit>
<image><use>texture[8]/image</use></image> <image>
<filter><use>texture[8]/filter</use></filter> <use>texture[8]/image</use>
<wrap-s><use>texture[8]/wrap-s</use></wrap-s> </image>
<wrap-t><use>texture[8]/wrap-t</use></wrap-t> <filter>
<internal-format><use>texture[0]/internal-format</use></internal-format> <use>texture[8]/filter</use>
</filter>
<wrap-s>
<use>texture[8]/wrap-s</use>
</wrap-s>
<wrap-t>
<use>texture[8]/wrap-t</use>
</wrap-t>
<internal-format>
<use>texture[0]/internal-format</use>
</internal-format>
</texture-unit> </texture-unit>
<texture-unit> <texture-unit>
@ -271,46 +354,67 @@ EXAMPLES: You can find examples of both usages in the Hunter and Lightning model
<uniform> <uniform>
<name>rainbowiness</name> <name>rainbowiness</name>
<type>float</type> <type>float</type>
<value><use>rainbowiness</use></value> <value>
<use>rainbowiness</use>
</value>
</uniform> </uniform>
<!-- set the amount of fresnel effect colour 0.0 - 1.0 --> <!-- set the amount of fresnel effect colour 0.0 - 1.0 -->
<uniform> <uniform>
<name>fresneliness</name> <name>fresneliness</name>
<type>float</type> <type>float</type>
<value><use>fresneliness</use></value> <value>
<use>fresneliness</use>
</value>
</uniform> </uniform>
<!-- set the amount of noisiness 0.0 - 1.0 --> <!-- set the amount of noisiness 0.0 - 1.0 -->
<uniform> <uniform>
<name>noisiness</name> <name>noisiness</name>
<type>float</type> <type>float</type>
<value><use>noisiness</use></value> <value>
<use>noisiness</use>
</value>
</uniform> </uniform>
<!-- The reflection is set proportional to the shininess of the material. <!-- The reflection is set proportional to the shininess of the material.
The amount of reflection may be adjusted by the use of this correction The amount of reflection may be adjusted by the use of this correction
-1.0 (fully transparent)- 1.0 (fully opaque) --> -1.0 (fully transparent)- 1.0 (fully opaque) -->
<uniform> <uniform>
<name>refl_correction</name> <name>refl_correction</name>
<type>float</type> <type>float</type>
<value><use>refl_correction</use></value> <value>
<use>refl_correction</use>
</value>
</uniform> </uniform>
<!-- set the amount of ambient light correction 0.0 - 1.0 --> <!-- set the amount of ambient light correction 0.0 - 1.0 -->
<uniform> <uniform>
<name>ambient_correction</name> <name>ambient_correction</name>
<type>float</type> <type>float</type>
<value><use>ambient_correction</use></value> <value>
<use>ambient_correction</use>
</value>
</uniform> </uniform>
<!-- use a reflection map--> <!-- use a reflection map-->
<uniform> <uniform>
<name>reflect_map</name> <name>reflect_map</name>
<type>float</type> <type>float</type>
<value><use>reflect_map</use></value> <value>
<use>reflect_map</use>
</value>
</uniform>
<!-- normalmap is .dds-->
<uniform>
<name>normalmap_dds</name>
<type>float</type>
<value>
<use>normalmap_dds</use>
</value>
</uniform> </uniform>
</pass> </pass>
</technique> </technique>
</PropertyList> </PropertyList>

View file

@ -1,6 +1,6 @@
// -*- mode: C; -*- // -*- mode: C; -*-
// Licence: GPL v2 // Licence: GPL v2
// Author: Vivian Meazza. // Author: Vivian Meazza.
#version 120 #version 120
@ -30,6 +30,7 @@ uniform float fresneliness;
uniform float noisiness; uniform float noisiness;
uniform float ambient_correction; uniform float ambient_correction;
uniform float reflect_map; uniform float reflect_map;
uniform float normalmap_dds;
void main (void) void main (void)
{ {
@ -45,6 +46,12 @@ void main (void)
vec4 ns = texture2D(NormalTex, gl_TexCoord[0].st); vec4 ns = texture2D(NormalTex, gl_TexCoord[0].st);
vec3 n = ns.rgb * 2.0 - 1.0; vec3 n = ns.rgb * 2.0 - 1.0;
n = normalize(n.x * VTangent + n.y * VBinormal + n.z * VNormal); 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)); NdotL = max(0.0, dot(n, lightDir));
// calculate the specular light // calculate the specular light
@ -58,10 +65,11 @@ void main (void)
* pow(NdotHV, gl_FrontMaterial.shininess)); * pow(NdotHV, gl_FrontMaterial.shininess));
} }
color.a = alpha; //color.a = alpha;
color = clamp(color, 0.0, 1.0);
vec4 texel = texture2D(BaseTex, gl_TexCoord[0].st); 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 // calculate the fog factor
const float LOG2 = 1.442695; const float LOG2 = 1.442695;
@ -89,12 +97,12 @@ void main (void)
float reflFactor = 0.0; float reflFactor = 0.0;
if(reflect_map > 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); vec4 map = texture2D(Map, gl_TexCoord[0].st);
//float pam = (map.a * -2) + 1; //reverse map //float pam = (map.a * -2) + 1; //reverse map
reflFactor = map.a + transparency_offset; reflFactor = map.a + transparency_offset;
} else { } 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; 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 ; 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); ambient_Correction = clamp(ambient_Correction, -1.0, 1.0);
// map noise vectore // map noise vector
vec4 noisevec = texture3D(Noise, rawpos.xyz); vec4 noisevec = texture3D(Noise, rawpos.xyz);
// add fringing fresnel and rainbow effects and modulate by reflection // add fringing fresnel and rainbow effects and modulate by reflection
@ -117,9 +125,9 @@ void main (void)
vec4 mixedcolor = mix(texel, raincolor, reflFactor); vec4 mixedcolor = mix(texel, raincolor, reflFactor);
// the final reflection // 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); reflColor = clamp(reflColor, 0.0, 1.0);
gl_FragColor = mix(gl_Fog.color, reflColor, fogFactor); gl_FragColor = mix(gl_Fog.color, reflColor, fogFactor);
} }

View file

@ -51,10 +51,10 @@ void main (void)
* pow(NdotHV, gl_FrontMaterial.shininess)); * pow(NdotHV, gl_FrontMaterial.shininess));
} }
color.a = alpha;
color = clamp(color, 0.0, 1.0);
vec4 texel = texture2D(BaseTex, gl_TexCoord[0].st); 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 // calculate the fog factor
const float LOG2 = 1.442695; const float LOG2 = 1.442695;
@ -77,7 +77,7 @@ void main (void)
// map the refection of the environment // map the refection of the environment
vec4 reflection = textureCube(Environment, reflVec); 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 transparency_offset = clamp(refl_correction, -1.0, 1.0);
float reflFactor = 0.0; float reflFactor = 0.0;
@ -100,7 +100,7 @@ void main (void)
// vec4 ambient_Correction = vec4(ambient_Correction.rgb, 0.5); // vec4 ambient_Correction = vec4(ambient_Correction.rgb, 0.5);
ambient_Correction = clamp(ambient_Correction, -1.0, 1.0); ambient_Correction = clamp(ambient_Correction, -1.0, 1.0);
// map noise vectore // map noise vector
vec4 noisevec = texture3D(Noise, rawpos.xyz); vec4 noisevec = texture3D(Noise, rawpos.xyz);
// add fringing fresnel and rainbow effects and modulate by reflection // add fringing fresnel and rainbow effects and modulate by reflection
@ -112,7 +112,7 @@ void main (void)
vec4 mixedcolor = mix(texel, raincolor, reflFactor); vec4 mixedcolor = mix(texel, raincolor, reflFactor);
// the final reflection // 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); reflColor = clamp(reflColor, 0.0, 1.0);
gl_FragColor = mix(gl_Fog.color, reflColor, fogFactor); gl_FragColor = mix(gl_Fog.color, reflColor, fogFactor);