1
0
Fork 0

Add light map to reflect shader.

Signed-off-by: Vivian Meazza <vivian.meazza@lineone.net>
This commit is contained in:
Vivian Meazza 2011-09-25 10:59:30 +01:00
parent 09cddc8ee5
commit e6fb203302
3 changed files with 356 additions and 42 deletions

View file

@ -1,54 +1,66 @@
<?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>
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 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 noisiness, coloured fringing or fresnel effect may be adjusted
by the use of <noisiness>, <rainbowiness> and <fresneliness>.
The overall values of the noisiness, coloured fringing or fresnel effect may be adjusted
by the use of <noisiness>, <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.
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.
To use a reflection map set <reflect_map> to 1,and the path to the map texture in
<texture n="8">
USE: To use the default reflection effect (controlled by material shininess values) use
To use a reflection map set <reflect_map> to 1,and the path to the map texture in
<texture n="8">
<effect>
To use a light map set <light_map> to 1,and the path to the map texture in
<texture n="2">>
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.
</<effect>
To use your own effect place your efffect file containing something like this:
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>
<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.
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>
<parameters>
<texture n="2">
<!--lightmap image -->
<image>Aircraft/Generic/Effects/greymap.png</image>
<filter>linear-mipmap-linear</filter>
<wrap-s>repeat</wrap-s>
<wrap-t>repeat</wrap-t>
<internal-format>normalized</internal-format>
</texture>
<texture n="5">
<type>cubemap</type>
<!-- use this form for a cube cross -->
@ -93,7 +105,9 @@ EXAMPLES: You can find examples of both usages in the Hunter and Lightning model
<noisiness>0.25</noisiness>
<refl_correction>0.0</refl_correction>
<ambient_correction>0.05</ambient_correction>
<reflect_map>0</reflect_map>
<reflect_map type="int">0</reflect_map>
<light_map type="int">0</light_map>
<factor>1</factor>
</parameters>
<technique n="9">
@ -181,6 +195,19 @@ EXAMPLES: You can find examples of both usages in the Hunter and Lightning model
</internal-format>
</texture-unit>
<texture-unit>
<unit>2</unit>
<type>
<use>texture[2]/type</use>
</type>
<image>
<use>texture[2]/image</use>
</image>
<filter>linear-mipmap-linear</filter>
<wrap-s>repeat</wrap-s>
<wrap-t>repeat</wrap-t>
</texture-unit>
<texture-unit>
<unit>5</unit>
<type>
@ -284,6 +311,12 @@ EXAMPLES: You can find examples of both usages in the Hunter and Lightning model
<value type="int">0</value>
</uniform>
<uniform>
<name>Lightmap</name>
<type>sampler-2d</type>
<value type="int">2</value>
</uniform>
<uniform>
<name>Environment</name>
<type>sampler-cube</type>
@ -314,6 +347,7 @@ EXAMPLES: You can find examples of both usages in the Hunter and Lightning model
<value type="int">9</value>
</uniform>
<!-- set the amount of fringing colour 0.0 - 1.0 -->
<uniform>
<name>rainbowiness</name>
@ -341,7 +375,7 @@ EXAMPLES: You can find examples of both usages in the Hunter and Lightning model
</value>
</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
-1.0 (fully transparent)- 1.0 (fully opaque) -->
<uniform>
@ -364,12 +398,30 @@ EXAMPLES: You can find examples of both usages in the Hunter and Lightning model
<!-- use a reflection map-->
<uniform>
<name>reflect_map</name>
<type>float</type>
<type>int</type>
<value>
<use>reflect_map</use>
</value>
</uniform>
<!-- use a light map-->
<uniform>
<name>light_map</name>
<type>int</type>
<value>
<use>light_map</use>
</value>
</uniform>
<uniform>
<name>lightmap_factor</name>
<type>float</type>
<value>
<use>factor</use>
</value>
</uniform>
</pass>
</technique>
</PropertyList>

View file

@ -0,0 +1,251 @@
<?xml version="1.0" ?>
<!-- created by Erik Streb del Toro -->
<!--
************************************************************************
* Bindings for Logitech WingMan Interceptor joystick (gameport).
*
*
* Axis 0: ailerons
* Axis 1: elevator
* Axis 2 (slider): throttle
* Axes 6 (left-right) and 7 (down-up) (hat): view direction
*
* Buttons according to the numbers printed in game controller properties:
* Button 1: all brakes
* Button 2: Scroll through views
* Button 4: elevator trim up
* Button 5: elevator trim down
* Button 7: flap down
* Button 6: flap up
* Button 3: Gear up
* Button 8: left brake only
* Button 9: right brake only
*
* If you have no rudder pedals you could use this as a workaround
* (you have to uncomment the definitions in this file):
* Button 8: rudder left
* Button 9: rudder right
************************************************************************
$Id$
-->
<PropertyList>
<name>Logitech WingMan Interceptor</name>
<axis n="0">
<desc>Aileron</desc>
<binding>
<command>property-scale</command>
<property>/controls/flight/aileron</property>
<squared type="bool">true</squared>
</binding>
</axis>
<axis n="1">
<desc>Elevator</desc>
<binding>
<command>property-scale</command>
<property>/controls/flight/elevator</property>
<factor type="double">-1.0</factor>
<squared type="bool">true</squared>
</binding>
</axis>
<axis n="2">
<desc>Throttle</desc>
<binding>
<command>nasal</command>
<script>controls.throttleAxis()</script>
</binding>
</axis>
<axis>
<desc>View Direction</desc>
<number>
<unix>4</unix>
<windows>6</windows>
<mac>4</mac>
</number>
<low>
<repeatable>true</repeatable>
<binding>
<command>property-adjust</command>
<property>/sim/current-view/goal-heading-offset-deg</property>
<step type="double">2.5</step>
</binding>
</low>
<high>
<repeatable>true</repeatable>
<binding>
<command>property-adjust</command>
<property>/sim/current-view/goal-heading-offset-deg</property>
<step type="double">-2.5</step>
</binding>
</high>
</axis>
<axis>
<desc>View Elevation</desc>
<number>
<unix>5</unix>
<windows>7</windows>
<mac>5</mac>
</number>
<low>
<repeatable>true</repeatable>
<binding>
<command>property-adjust</command>
<property>/sim/current-view/goal-pitch-offset-deg</property>
<step type="double">1.0</step>
</binding>
</low>
<high>
<repeatable>true</repeatable>
<binding>
<command>property-adjust</command>
<property>/sim/current-view/goal-pitch-offset-deg</property>
<step type="double">-1.0</step>
</binding>
</high>
</axis>
<button n="0">
<desc>Brakes</desc>
<binding>
<command>nasal</command>
<script>controls.applyBrakes(1)</script>
</binding>
<mod-up>
<binding>
<command>nasal</command>
<script>controls.applyBrakes(0)</script>
</binding>
</mod-up>
</button>
<button n="1">
<desc>Scroll through views</desc>
<binding>
<command>nasal</command>
<script>view.stepView(1)</script>
</binding>
</button>
<button n="4">
<desc>Elevator trim up</desc>
<repeatable type="bool">true</repeatable>
<binding>
<command>property-adjust</command>
<property>/controls/flight/elevator-trim</property>
<step type="double">0.001</step>
</binding>
</button>
<button n="3">
<desc>Elevator trim down</desc>
<repeatable type="bool">true</repeatable>
<binding>
<command>property-adjust</command>
<property>/controls/flight/elevator-trim</property>
<step type="double">-0.001</step>
</binding>
</button>
<button n="6">
<desc>Flaps down</desc>
<binding>
<command>nasal</command>
<script>controls.flapsDown(1)</script>
</binding>
<mod-up>
<binding>
<command>nasal</command>
<script>controls.flapsDown(0)</script>
</binding>
</mod-up>
</button>
<button n="5">
<desc>Flaps up</desc>
<repeatable>false</repeatable>
<binding>
<command>nasal</command>
<script>controls.flapsDown(-1)</script>
</binding>
<mod-up>
<binding>
<command>nasal</command>
<script>controls.flapsDown(0)</script>
</binding>
</mod-up>
</button>
<button n="2">
<desc>Gear up</desc>
<repeatable>false</repeatable>
<binding>
<command>nasal</command>
<script>controls.gearDown(-1)</script>
</binding>
<mod-up>
<binding>
<command>nasal</command>
<script>controls.gearDown(0)</script>
</binding>
</mod-up>
</button>
<button n="7">
<desc>Left brake</desc>
<binding>
<command>nasal</command>
<script>controls.applyBrakes(1, -1)</script>
</binding>
<mod-up>
<binding>
<command>nasal</command>
<script>controls.applyBrakes(0, -1)</script>
</binding>
</mod-up>
</button>
<button n="8">
<desc>Right brake</desc>
<binding>
<command>nasal</command>
<script>controls.applyBrakes(1, 1)</script>
</binding>
<mod-up>
<binding>
<command>nasal</command>
<script>controls.applyBrakes(0, 1)</script>
</binding>
</mod-up>
</button>
<!-- I have no rudder, so I need those "buttons" to move the rudder
<button n="7">
<desc>Rudder trim adjustment left</desc>
<repeatable type="bool">true</repeatable>
<binding>
<command>property-adjust</command>
<property>/controls/flight/rudder</property>
<step type="double">-0.01</step>
</binding>
</button>
<button n="8">
<desc>Rudder trim adjustment right</desc>
<repeatable type="bool">true</repeatable>
<binding>
<command>property-adjust</command>
<property>/controls/flight/rudder</property>
<step type="double">0.01</step>
</binding>
</button>
-->
</PropertyList>

View file

@ -1,6 +1,6 @@
// -*- mode: C; -*-
// Licence: GPL v2
// Author: Vivian Meazza.
// Author: Vivian Meazza.
#version 120
@ -20,13 +20,17 @@ uniform sampler2D BaseTex;
uniform sampler2D Fresnel;
uniform sampler2D Map;
uniform sampler3D Noise;
uniform sampler2D Lightmap;
uniform float refl_correction;
uniform float rainbowiness;
uniform float fresneliness;
uniform float noisiness;
uniform float ambient_correction;
uniform float reflect_map;
uniform float lightmap_factor;
uniform int light_map;
uniform int reflect_map;
void main (void)
{
@ -52,7 +56,7 @@ void main (void)
}
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);
@ -81,14 +85,14 @@ void main (void)
float transparency_offset = clamp(refl_correction, -1.0, 1.0);
float reflFactor = 0.0;
if(reflect_map > 0.0){
// map the shininess of the object with user input
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
// set the reflectivity proportional to shininess with user
// input
reflFactor = (gl_FrontMaterial.shininess / 128.0) + transparency_offset;
}
@ -115,5 +119,12 @@ void main (void)
vec4 reflColor = vec4(color.rgb * mixedcolor.rgb + specular.rgb + ambient_Correction.rgb, color.a);
reflColor = clamp(reflColor, 0.0, 1.0);
// add a lightmap
if ( light_map >= 1 ) {
vec3 lightmapTexel = texture2D(Lightmap, gl_TexCoord[0].st).rgb * lightmap_factor;
reflColor.rgb = max(reflColor.rgb, lightmapTexel * gl_FrontMaterial.diffuse.rgb * mixedcolor.rgb);
}
gl_FragColor = mix(gl_Fog.color, reflColor, fogFactor);
}