[Orxonox-commit 4756] r9425 - in data/trunk: materials programs
davidsa at orxonox.net
davidsa at orxonox.net
Wed Oct 31 18:02:06 CET 2012
Author: davidsa
Date: 2012-10-31 18:02:05 +0100 (Wed, 31 Oct 2012)
New Revision: 9425
Modified:
data/trunk/materials/glow.material
data/trunk/programs/ps_glow.cg
data/trunk/programs/vs_glow.cg
Log:
Improved glow effect, added some minor documentation to the glow.material file.
Modified: data/trunk/materials/glow.material
===================================================================
--- data/trunk/materials/glow.material 2012-10-29 16:04:10 UTC (rev 9424)
+++ data/trunk/materials/glow.material 2012-10-31 17:02:05 UTC (rev 9425)
@@ -1,45 +1,49 @@
vertex_program glow_vs cg
{
- source vs_glow.cg
- entry_point main
- profiles vs_1_1 arbvp1
+ source vs_glow.cg
+ entry_point main
+ profiles vs_1_1 arbvp1
}
fragment_program glow_ps cg
{
- source ps_glow.cg
- entry_point main
- profiles ps_2_0 arbfp1
+ source ps_glow.cg
+ entry_point main
+ profiles ps_2_0 arbfp1
}
-
material glow
{
- technique
- {
- pass
- {
- scene_blend alpha_blend
- depth_check on
- lighting off
- emissive 0.5 0.9 1.0 0.0
-
- vertex_program_ref glow_vs
- {
- param_named_auto worldViewProjMatrix worldviewproj_matrix
- param_named size_value float 0.3
- param_named_auto time time_0_x 50
- }
-
- fragment_program_ref glow_ps
- {
- param_named alpha_value float 0.4
- param_named_auto time time_0_x 50
- param_named_auto color surface_emissive_colour
- }
- }
-
- }
+ technique
+ {
+ pass
+ {
+ scene_blend alpha_blend
+ depth_check on
+ depth_func less_equal
+ lighting off
+ emissive 0.5 0.9 1.0 0.0 //what color should the glow be, emissive light can be changed through ogre as well
+
+ vertex_program_ref glow_vs
+ {
+ param_named_auto iWorldTMatrix inverse_transpose_world_matrix //don't worry about auto parameters here, they are given
+ param_named_auto iViewMatrix inverse_view_matrix
+ param_named_auto worldMatrix world_matrix
+ param_named_auto viewProjMatrix viewproj_matrix
+ param_named inflate float 0.05 //how much should the glow expand from the model, usually a small value
+ }
+
+ fragment_program_ref glow_ps
+ {
+ param_named alphaValue float 0.5 //base alpha value of glow
+ param_named cutoffAngle float 70.0 //from which view to surface normal angle on should the intensity of the glow decrease
+ param_named exponent float 2.5 //by which exponent should the intensity decrease
+ param_named_auto time time_0_x 50 //how fast should the light pulsate
+ param_named_auto color surface_emissive_colour //don't worry about this one, it makes sure we use the emissive color value
+ }
+ }
+
+ }
}
material glow/drone
@@ -66,14 +70,18 @@
vertex_program_ref glow_vs
{
- param_named_auto worldViewProjMatrix worldviewproj_matrix
- param_named size_value float 0.2
- param_named_auto time time_0_x 50
+ param_named_auto iWorldTMatrix inverse_transpose_world_matrix
+ param_named_auto iViewMatrix inverse_view_matrix
+ param_named_auto worldMatrix world_matrix
+ param_named_auto viewProjMatrix viewproj_matrix
+ param_named inflate float 0.2
}
fragment_program_ref glow_ps
{
- param_named alpha_value float 0.4
+ param_named alphaValue float 0.4
+ param_named cutoffAngle float 70.0
+ param_named exponent float 2.5
param_named_auto time time_0_x 50
param_named_auto color surface_emissive_colour
}
Modified: data/trunk/programs/ps_glow.cg
===================================================================
--- data/trunk/programs/ps_glow.cg 2012-10-29 16:04:10 UTC (rev 9424)
+++ data/trunk/programs/ps_glow.cg 2012-10-31 17:02:05 UTC (rev 9425)
@@ -1,5 +1,26 @@
-float4 main(uniform float alpha_value, uniform float time, uniform float4 color) : COLOR
+struct vertexOut
{
- color.w = alpha_value * ((sin(time * 5.0) / 3.14 + 1.0) / 2.0 );
+ float4 position : POSITION;
+ float2 uv : TEXCOORD0;
+ float3 worldNormal : TEXCOORD1;
+ float3 worldView : TEXCOORD2;
+};
+
+float4 main(vertexOut input, uniform float alphaValue, uniform float cutoffAngle, uniform float exponent, uniform float time, uniform float4 color) : COLOR
+{
+ float3 Nn = normalize(input.worldNormal);
+ float3 Vn = normalize(input.worldView);
+ float alphaMod = dot(Nn, Vn);//this is a measure for how close we are to the edge of a model according to our view
+ float cutoff=cos(cutoffAngle * 3.14 / 180.0);//pi divided by 180
+ if(alphaMod<cutoff)//transform output range so it only affects angles close to 90 degrees
+ {
+ alphaMod/=cutoff;
+ }
+ else
+ {
+ alphaMod=1.0;
+ }
+ alphaMod = pow(alphaMod,exponent); //how fast should the intensity of the glow decrease
+ color.w = alphaMod * alphaValue * ((sin(time)/3.14 + 1.0) / 2.0 + 0.1);
return color;
-}
+}
\ No newline at end of file
Modified: data/trunk/programs/vs_glow.cg
===================================================================
--- data/trunk/programs/vs_glow.cg 2012-10-29 16:04:10 UTC (rev 9424)
+++ data/trunk/programs/vs_glow.cg 2012-10-31 17:02:05 UTC (rev 9425)
@@ -1,8 +1,28 @@
-void main(float4 position : POSITION, float3 normal : NORMAL, float2 uv : TEXCOORD0, out float4 oPosition : POSITION, out float2 oUv : TEXCOORD0, out float4 colour : COLOR,
- uniform float4x4 worldViewProjMatrix, uniform float size_value, uniform float time )
+struct vertexIn
{
- float4 myPosition = position;
- myPosition.xyz += size_value * (1.0 + (sin(time * 5.0) + 1.0) / 5.0 ) * normal;
- oPosition = mul(worldViewProjMatrix, myPosition);
-}
+ float4 position : POSITION;
+ float4 normal : NORMAL;
+ float2 uv : TEXCOORD0;
+};
+struct vertexOut
+{
+ float4 position : POSITION; //<! transformed position
+ float2 uv : TEXCOORD0; //<! passing on uv information
+ float3 worldNormal : TEXCOORD1; //<! surface normal transformed into world
+ float3 worldView : TEXCOORD2; //<! view direction transformed into world
+};
+
+vertexOut main(vertexIn input, uniform float4x4 iWorldTMatrix, uniform float4x4 iViewMatrix, uniform float4x4 worldMatrix, uniform float4x4 viewProjMatrix, uniform float inflate )
+{
+ vertexOut output;
+ float4 myPosition = input.position;
+ output.worldNormal=mul(iWorldTMatrix, input.normal).xyz; //transforming the normal
+ input.normal = normalize(float4(input.normal.xyz,0)); //normalizing the normal according to the three relevant parts
+ myPosition.xyz += inflate * input.normal; //inflating the model into a bigger shape
+ myPosition = mul(worldMatrix, myPosition); //transforming position into world
+ output.worldView = normalize(float3(iViewMatrix[0].w, iViewMatrix[1].w, iViewMatrix[2].w) - myPosition.xyz);//view direction according to world
+ output.position = mul(viewProjMatrix, myPosition); //finish transformation of the position into the projection space
+ output.uv = input.uv; //passing on uv information
+ return output;
+}
\ No newline at end of file
More information about the Orxonox-commit
mailing list