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

@ -22,6 +22,8 @@ To use a reflection map set <reflect_map> to 1,and the path to the map texture i
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
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 USE: To use the default reflection effect (controlled by material shininess values) use
<effect> <effect>
@ -104,6 +106,7 @@ 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>
@ -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,21 +354,27 @@ 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.
@ -294,21 +383,36 @@ EXAMPLES: You can find examples of both usages in the Hunter and Lightning model
<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>

View file

@ -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;
@ -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,7 +125,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);

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);