1
0
Fork 0

Tie reflectivity to material shininess, and provide more user control via parameters.

Perpare for cube cross textures.
This commit is contained in:
vmmeazza 2010-03-31 09:11:44 +00:00
parent 6e99283904
commit f71d794866
3 changed files with 105 additions and 24 deletions

View file

@ -1,4 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Reflections
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>
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 <refl_correction> -1.0 (fully transparent)- 1.0 (fully opaque).
The overall values of the coloured fringing or fresnel effect may be adjusted
by the use of <rainbowiness> and <fresneliness>.
If your result is too dark/too light the overall ambient light value can be adjusted
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.
USE: To use the default reflection effect (controlled by material shininess values) use
<effect>
<inherits-from>Effects/reflect</inherits-from>
<object-name>Fuselage</object-name>
</<effect>
To use your own reflection effectuse
<effect>
<inherits-from>Aircraft/Lightning/Models/Effects/lightningreflect</inherits-from>
<object-name>Fuselage</object-name>
</<effect>
in your model file.
To use your own effect place your efffect file containing something like this:
<name>Effects/lightningreflect</name>
<inherits-from>Effects/reflect</inherits-from>
and the the modified tags in the path as above
EXAMPLES: You can find examples of both usages in the Hunter and Lightning models.
-->
<PropertyList>
<name>Effects/reflect</name>
<inherits-from>Effects/model-default</inherits-from>
@ -6,6 +48,10 @@
<parameters>
<texture n="5">
<type>cubemap</type>
<!-- use this form for a cube cross -->
<!--<image>Aircraft/Generic/Effects/CubeCrosses/blue_sky.jpg</image>-->
<!-- use this form for a 6 image cube map -->
<images>
<positive-x>Aircraft/Generic/Effects/CubeMaps/fair-sky/fair-sky_px.png</positive-x>
<negative-x>Aircraft/Generic/Effects/CubeMaps/fair-sky/fair-sky_nx.png</negative-x>
@ -14,6 +60,7 @@
<positive-z>Aircraft/Generic/Effects/CubeMaps/fair-sky/fair-sky_pz.png</positive-z>
<negative-z>Aircraft/Generic/Effects/CubeMaps/fair-sky/fair-sky_nz.png</negative-z>
</images>
</texture>
<texture n="6">
<image>Aircraft/Generic/Effects/Rainbow.png</image>
@ -31,6 +78,10 @@
</texture>
<rendering-hint>transparent</rendering-hint>
<shade-model>smooth</shade-model>
<rainbowiness>0.075</rainbowiness>
<fresneliness>0.075</fresneliness>
<refl_correction>0.0</refl_correction>
<ambient_correction>0.1</ambient_correction>
</parameters>
<technique n="9">
@ -123,6 +174,13 @@
<type>
<use>texture[5]/type</use>
</type>
<!-- use this form for a cube cross -->
<!--<image>
<use>texture[5]/image</use>
</image>-->
<!-- use this form for a 6 image cube map -->
<images>
<use>texture[5]/images</use>
</images>
@ -212,29 +270,34 @@
<uniform>
<name>rainbowiness</name>
<type>float</type>
<value type="float">0.1</value>
<value><use>rainbowiness</use></value>
</uniform>
<!-- set the amount of fresnel effect colour 0.0 - 1.0 -->
<uniform>
<name>fresneliness</name>
<type>float</type>
<value type="float">0.1</value>
<value><use>fresneliness</use></value>
</uniform>
<!-- set the amount of tranparency 0.0 (fully tranaparent)
- 1.0 (fully opaque) -->
<!-- The reflection is set proportional to the shininess of the material.
The amount of reflection may be adjusted by the use of this correction
-1.0 (fully transparent)- 1.0 (fully opaque) -->
<uniform>
<name>transparency</name>
<name>refl_correction</name>
<type>float</type>
<value type="float">0.4</value>
<value>
<use>refl_correction</use>
</value>
</uniform>
<!-- set the amount of ambient light correction 0.0 - 1.0 -->
<uniform>
<name>correction</name>
<name>ambient_correction</name>
<type>float</type>
<value type="float">0.2</value>
<value>
<use>ambient_correction</use>
</value>
</uniform>
</pass>
</technique>

View file

@ -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)
@ -71,15 +75,25 @@ void main (void)
// 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 ;
vec4 reflColor = color * mixedcolor + specular + ambient_Correction ;
reflColor = clamp(reflColor, 0.0, 1.0);
gl_FragColor = mix(gl_Fog.color, reflColor, fogFactor);

View file

@ -1,3 +1,7 @@
// -*- mode: C; -*-
// Licence: GPL v2
// Author: Vivian Meazza.
varying vec4 ecPosition;
varying vec3 VNormal;
varying vec3 Normal;