ogre.rb 0.1-i386-mswin32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. data/README +79 -0
  2. data/Rakefile +291 -0
  3. data/doc_src/ogre.rb +246 -0
  4. data/doc_src/ois.rb +67 -0
  5. data/lib/application.rb +146 -0
  6. data/lib/application_frame_listener.rb +302 -0
  7. data/lib/application_loading_bar.rb +115 -0
  8. data/lib/constants.rb +51 -0
  9. data/lib/method_fixes.rb +42 -0
  10. data/lib/ogre.dll +0 -0
  11. data/lib/ruby_ois.dll +0 -0
  12. data/ogre.rb +25 -0
  13. data/platform.rb +23 -0
  14. data/samples/Ogre.log +279 -0
  15. data/samples/bsp.rb +76 -0
  16. data/samples/cg.dll +0 -0
  17. data/samples/grass.rb +325 -0
  18. data/samples/js3250.dll +0 -0
  19. data/samples/lighting.rb +138 -0
  20. data/samples/media/materials/programs/Grass.cg +30 -0
  21. data/samples/media/materials/programs/OffsetMapping.cg +97 -0
  22. data/samples/media/materials/programs/OffsetMapping.hlsl +135 -0
  23. data/samples/media/materials/programs/OffsetMappingFp.glsl +69 -0
  24. data/samples/media/materials/programs/OffsetMappingVp.glsl +54 -0
  25. data/samples/media/materials/programs/OffsetMapping_specular.asm +44 -0
  26. data/samples/media/materials/scripts/CloudySky.material +17 -0
  27. data/samples/media/materials/scripts/CubeMapping.material +34 -0
  28. data/samples/media/materials/scripts/Flare.material +17 -0
  29. data/samples/media/materials/scripts/Grass.material +63 -0
  30. data/samples/media/materials/scripts/Knot.material +14 -0
  31. data/samples/media/materials/scripts/MorningSkyBox.material +17 -0
  32. data/samples/media/materials/scripts/Offset.material +124 -0
  33. data/samples/media/materials/scripts/Ogre.material +119 -0
  34. data/samples/media/materials/scripts/RZR-002.material +15 -0
  35. data/samples/media/materials/scripts/Razor.material +14 -0
  36. data/samples/media/materials/scripts/Ribbon.material +19 -0
  37. data/samples/media/materials/scripts/RustySteel.material +14 -0
  38. data/samples/media/materials/scripts/SpaceSkyBox.material +17 -0
  39. data/samples/media/materials/scripts/SpaceSkyPlane.material +17 -0
  40. data/samples/media/materials/scripts/TextureEffects.material +15 -0
  41. data/samples/media/materials/scripts/dragon.material +42 -0
  42. data/samples/media/materials/scripts/smoke.material +18 -0
  43. data/samples/media/materials/textures/GreenSkin.jpg +0 -0
  44. data/samples/media/materials/textures/MtlPlat2.jpg +0 -0
  45. data/samples/media/materials/textures/RZR-002.png +0 -0
  46. data/samples/media/materials/textures/RustedMetal.jpg +0 -0
  47. data/samples/media/materials/textures/RustySteel.jpg +0 -0
  48. data/samples/media/materials/textures/Thumbs.db +0 -0
  49. data/samples/media/materials/textures/Water02.jpg +0 -0
  50. data/samples/media/materials/textures/WeirdEye.png +0 -0
  51. data/samples/media/materials/textures/clouds.jpg +0 -0
  52. data/samples/media/materials/textures/cursor.png +0 -0
  53. data/samples/media/materials/textures/dirt01.jpg +0 -0
  54. data/samples/media/materials/textures/flare.png +0 -0
  55. data/samples/media/materials/textures/gras_02.png +0 -0
  56. data/samples/media/materials/textures/grass_1024.jpg +0 -0
  57. data/samples/media/materials/textures/ogreborder.png +0 -0
  58. data/samples/media/materials/textures/ogreborderUp.png +0 -0
  59. data/samples/media/materials/textures/ribbonband.png +0 -0
  60. data/samples/media/materials/textures/rockwall.tga +0 -0
  61. data/samples/media/materials/textures/rockwall_NH.tga +0 -0
  62. data/samples/media/materials/textures/smoke.png +0 -0
  63. data/samples/media/materials/textures/smokecolors.png +0 -0
  64. data/samples/media/materials/textures/spacesky.jpg +0 -0
  65. data/samples/media/materials/textures/spheremap.png +0 -0
  66. data/samples/media/materials/textures/texmap2.jpg +0 -0
  67. data/samples/media/models/RZR-002.mesh +0 -0
  68. data/samples/media/models/geosphere4500.mesh +0 -0
  69. data/samples/media/models/geosphere8000.mesh +0 -0
  70. data/samples/media/models/knot.mesh +0 -0
  71. data/samples/media/models/ogrehead.mesh +0 -0
  72. data/samples/media/models/razor.mesh +0 -0
  73. data/samples/media/models/sphere.mesh +0 -0
  74. data/samples/media/overlays/CubeMapping.overlay +139 -0
  75. data/samples/media/packs/OgreCore.zip +0 -0
  76. data/samples/media/packs/chiropteraDM.pk3 +0 -0
  77. data/samples/media/packs/chiropteraDM.txt +99 -0
  78. data/samples/media/packs/cubemap.zip +0 -0
  79. data/samples/media/packs/cubemapsJS.zip +0 -0
  80. data/samples/media/packs/dragon.zip +0 -0
  81. data/samples/media/packs/skybox.zip +0 -0
  82. data/samples/media/particles/smoke.particle +43 -0
  83. data/samples/media.cfg +22 -0
  84. data/samples/ogre.cfg +19 -0
  85. data/samples/plugins.cfg +12 -0
  86. data/samples/quake3settings.cfg +2 -0
  87. data/samples/render_to_texture.rb +161 -0
  88. data/samples/resources.cfg +16 -0
  89. data/samples/sky_box.rb +107 -0
  90. data/samples/sky_dome.rb +86 -0
  91. data/samples/sky_plane.rb +27 -0
  92. data/samples/smoke.rb +23 -0
  93. data/samples/work/cube_mapping.rb +686 -0
  94. metadata +149 -0
@@ -0,0 +1,138 @@
1
+ #!/usr/bin/ruby -w
2
+
3
+ $: << File.dirname(__FILE__) + "/.."
4
+ require 'ogre'
5
+ require 'application'
6
+ include Ogre
7
+
8
+ $animation_state_list = []
9
+
10
+ class LightingListener < ApplicationFrameListener
11
+ def frame_started(event)
12
+ return false unless super(event)
13
+
14
+ $animation_state_list.each do |anim|
15
+ anim.add_time(event.time_since_last_frame)
16
+ end
17
+
18
+ true
19
+ end
20
+ end
21
+
22
+ class LightingApplication < Application
23
+
24
+ def create_scene
25
+ scene_manager.set_ambient_light ColourValue.new(0.5, 0.5, 0.5)
26
+ scene_manager.set_sky_box(true, "SpaceSkyBox")
27
+ head = scene_manager.create_entity("head", "ogrehead.mesh")
28
+
29
+ scene_manager.root_scene_node.attach_object(head)
30
+
31
+ ## Set up light ribbons
32
+ dir = Vector3.new(-1, -1, 0.5)
33
+ dir.normalise!
34
+
35
+ l = scene_manager.create_light("light1")
36
+ l.set_type Light::LT_DIRECTIONAL
37
+ l.set_direction dir
38
+
39
+ trail = scene_manager.create_movable_object("RibbonTrail1", "RibbonTrail",
40
+ {"numberOfChains" => "2", "maxElements" => "80"})
41
+ trail.set_material_name "LightRibbonTrail"
42
+ trail.set_trail_length 400
43
+
44
+ puts trail
45
+
46
+ scene_manager.root_scene_node.create_child_scene_node.attach_object(trail)
47
+
48
+ anim_node = scene_manager.root_scene_node.create_child_scene_node
49
+ anim_node.set_position Vector3.new(50,30,0)
50
+ anim = scene_manager.create_animation("an1", 14)
51
+ anim.set_interpolation_mode Animation::IM_SPLINE
52
+ track = anim.create_node_track(1, anim_node)
53
+ kf = track.create_node_key_frame(0)
54
+ kf.set_translate Vector3.new(50,30,0)
55
+ kf = track.create_node_key_frame(2)
56
+ kf.set_translate Vector3.new(100, -30, 0)
57
+ kf = track.create_node_key_frame(4)
58
+ kf.set_translate Vector3.new(120, -100, 150)
59
+ kf = track.create_node_key_frame(6)
60
+ kf.set_translate Vector3.new(30, -100, 50)
61
+ kf = track.create_node_key_frame(8)
62
+ kf.set_translate Vector3.new(-50, 30, -50)
63
+ kf = track.create_node_key_frame(10)
64
+ kf.set_translate Vector3.new(-150, -20, -100)
65
+ kf = track.create_node_key_frame(12)
66
+ kf.set_translate Vector3.new(-50, -30, 0)
67
+ kf = track.create_node_key_frame(14)
68
+ kf.set_translate Vector3.new(50,30,0)
69
+
70
+ anim_state = scene_manager.create_animation_state("an1")
71
+ anim_state.set_enabled true
72
+ $animation_state_list << anim_state
73
+
74
+ trail.set_initial_colour(0, 1.0, 0.8, 0)
75
+ trail.set_colour_change(0, 0.5, 0.5, 0.5, 0.5)
76
+ trail.set_initial_width(0, 5)
77
+ trail.add_node(anim_node)
78
+
79
+ # Add light
80
+ l2 = scene_manager.create_light("l2")
81
+ l2.set_diffuse_colour trail.get_initial_colour(0)
82
+ anim_node.attach_object(l2)
83
+
84
+ # Add billboard
85
+ bbs = scene_manager.create_billboard_set("bb", 1)
86
+ bbs.create_billboard(Vector3.ZERO, trail.get_initial_colour(0))
87
+ bbs.set_material_name "Flare"
88
+ anim_node.attach_object(bbs)
89
+
90
+ anim_node = scene_manager.root_scene_node.create_child_scene_node
91
+ anim_node.set_position Vector3.new(-50,100,0)
92
+ anim = scene_manager.create_animation("an2", 10)
93
+ anim.set_interpolation_mode Animation::IM_SPLINE
94
+ track = anim.create_node_track(1, anim_node)
95
+ kf = track.create_node_key_frame(0)
96
+ kf.set_translate Vector3.new(-50,100,0)
97
+ kf = track.create_node_key_frame(2)
98
+ kf.set_translate Vector3.new(-100, 150, -30)
99
+ kf = track.create_node_key_frame(4)
100
+ kf.set_translate Vector3.new(-200, 0, 40)
101
+ kf = track.create_node_key_frame(6)
102
+ kf.set_translate Vector3.new(0, -150, 70)
103
+ kf = track.create_node_key_frame(8)
104
+ kf.set_translate Vector3.new(50, 0, 30)
105
+ kf = track.create_node_key_frame(10)
106
+ kf.set_translate Vector3.new(-50,100,0)
107
+
108
+ anim_state = scene_manager.create_animation_state("an2")
109
+ anim_state.set_enabled true
110
+ $animation_state_list << anim_state
111
+
112
+ trail.set_initial_colour(1, 0.0, 1.0, 0.4)
113
+ trail.set_colour_change(1, 0.5, 0.5, 0.5, 0.5)
114
+ trail.set_initial_width(1, 5)
115
+ trail.add_node(anim_node)
116
+
117
+
118
+ # Add light
119
+ l2 = scene_manager.create_light("l3")
120
+ l2.set_diffuse_colour trail.get_initial_colour(1)
121
+ anim_node.attach_object(l2)
122
+
123
+ # Add billboard
124
+ bbs = scene_manager.create_billboard_set("bb2", 1)
125
+ bbs.create_billboard(Vector3.ZERO, trail.get_initial_colour(1))
126
+ bbs.set_material_name "Flare"
127
+ anim_node.attach_object(bbs)
128
+
129
+ end
130
+
131
+ def create_frame_listener
132
+ self.frame_listener = LightingListener.new(root, window, camera)
133
+ #root.addFrameListener(self.frame_listener)
134
+ end
135
+ end
136
+
137
+ app = LightingApplication.new
138
+ app.go
@@ -0,0 +1,30 @@
1
+ // Vertex program to wave some grass about
2
+ // Simplistic, assumes base of the grass at 0
3
+ void grass_vp(float4 position : POSITION,
4
+ float3 normal : NORMAL,
5
+ float2 uv : TEXCOORD0,
6
+ out float4 oPosition : POSITION,
7
+ out float2 oUv : TEXCOORD0,
8
+ out float4 colour : COLOR,
9
+
10
+ uniform float4x4 worldViewProj,
11
+ uniform float4 ambient,
12
+ uniform float4 objSpaceLight,
13
+ uniform float4 lightColour,
14
+ uniform float4 offset)
15
+ {
16
+ float4 mypos = position;
17
+ //offset = float4(0.5, 0, 0, 0);
18
+ mypos = mypos + offset * mypos.yyyy;
19
+ oPosition = mul(worldViewProj, mypos);
20
+
21
+ oUv = uv;
22
+ // get vertex light direction (support directional and point)
23
+ float3 light = normalize(
24
+ objSpaceLight.xyz - (position.xyz * objSpaceLight.w));
25
+ float diffuseFactor = max(dot(normal, light), 0);
26
+
27
+
28
+ colour = ambient + diffuseFactor * lightColour;
29
+ }
30
+
@@ -0,0 +1,97 @@
1
+ /* Bump mapping with Parallax offset vertex program
2
+ In this program, we want to calculate the tangent space light end eye vectors
3
+ which will get passed to the fragment program to produce the per-pixel bump map
4
+ with parallax offset effect.
5
+ */
6
+
7
+ /* Vertex program that moves light and eye vectors into texture tangent space at vertex */
8
+
9
+ void main_vp(float4 position : POSITION,
10
+ float3 normal : NORMAL,
11
+ float2 uv : TEXCOORD0,
12
+ float3 tangent : TANGENT0,
13
+ // outputs
14
+ out float4 oPosition : POSITION,
15
+ out float2 oUv : TEXCOORD0,
16
+ out float3 oLightDir : TEXCOORD1, // tangent space
17
+ out float3 oEyeDir : TEXCOORD2, // tangent space
18
+ out float3 oHalfAngle : TEXCOORD3, //
19
+ // parameters
20
+ uniform float4 lightPosition, // object space
21
+ uniform float3 eyePosition, // object space
22
+ uniform float4x4 worldViewProj)
23
+ {
24
+ // calculate output position
25
+ oPosition = mul(worldViewProj, position);
26
+
27
+ // pass the main uvs straight through unchanged
28
+ oUv = uv;
29
+
30
+ // calculate tangent space light vector
31
+ // Get object space light direction
32
+ float3 lightDir = normalize(lightPosition.xyz - (position * lightPosition.w));
33
+ float3 eyeDir = eyePosition - position.xyz;
34
+
35
+ // Calculate the binormal (NB we assume both normal and tangent are
36
+ // already normalised)
37
+ // NB looks like nvidia cross params are BACKWARDS to what you'd expect
38
+ // this equates to NxT, not TxN
39
+ float3 binormal = cross(tangent, normal);
40
+
41
+ // Form a rotation matrix out of the vectors
42
+ float3x3 rotation = float3x3(tangent, binormal, normal);
43
+
44
+ // Transform the light vector according to this matrix
45
+ lightDir = normalize(mul(rotation, lightDir));
46
+ eyeDir = normalize(mul(rotation, eyeDir));
47
+
48
+ oLightDir = lightDir;
49
+ oEyeDir = eyeDir;
50
+ oHalfAngle = normalize(eyeDir + lightDir);
51
+ }
52
+
53
+ // General functions
54
+
55
+ // Expand a range-compressed vector
56
+ float3 expand(float3 v)
57
+ {
58
+ return (v - 0.5) * 2;
59
+ }
60
+
61
+ void main_fp(float2 uv : TEXCOORD0,
62
+ float3 lightDir : TEXCOORD1,
63
+ float3 eyeDir : TEXCOORD2,
64
+ float3 halfAngle : TEXCOORD3,
65
+ uniform float3 lightDiffuse,
66
+ uniform float3 lightSpecular,
67
+ uniform float4 scaleBias,
68
+ uniform sampler2D normalHeightMap,
69
+ uniform sampler2D diffuseMap,
70
+ out float4 oColor : COLOR)
71
+ {
72
+ // get the height using the tex coords
73
+ float height = tex2D(normalHeightMap, uv).a;
74
+
75
+ // scale and bias factors
76
+ float scale = scaleBias.x;
77
+ float bias = scaleBias.y;
78
+
79
+ // calculate displacement
80
+ float displacement = (height * scale) + bias;
81
+
82
+ float3 uv2 = float3(uv, 1);
83
+
84
+ // calculate the new tex coord to use for normal and diffuse
85
+ float2 newTexCoord = ((eyeDir * displacement) + uv2).xy;
86
+
87
+ // get the new normal and diffuse values
88
+ float3 normal = expand(tex2D(normalHeightMap, newTexCoord).xyz);
89
+ float3 diffuse = tex2D(diffuseMap, newTexCoord).xyz;
90
+
91
+ float3 specular = pow(saturate(dot(normal, halfAngle)), 32) * lightSpecular;
92
+ float3 col = diffuse * saturate(dot(normal, lightDir)) * lightDiffuse + specular;
93
+
94
+ oColor = float4(col, 1);
95
+ }
96
+
97
+
@@ -0,0 +1,135 @@
1
+ /* Offset mapping including a shadow element and multiple lights in one pass */
2
+ void integratedshadows_vp(float4 position : POSITION,
3
+ float3 normal : NORMAL,
4
+ float2 uv : TEXCOORD0,
5
+ float3 tangent : TANGENT0,
6
+ // outputs
7
+ out float4 oPosition : POSITION,
8
+ out float2 oUv : TEXCOORD0,
9
+ out float3 oLightDir : TEXCOORD1, // tangent space
10
+ out float3 oEyeDir : TEXCOORD2, // tangent space
11
+ out float3 oSpotDirection : TEXCOORD3, // tangent space
12
+ out float3 oLightDir1 : TEXCOORD4, // tangent space
13
+ out float3 oSpotDirection1 : TEXCOORD5, // tangent space
14
+ out float4 oShadowUV1 : TEXCOORD6,
15
+ out float4 oShadowUV2 : TEXCOORD7,
16
+ // parameters
17
+ uniform float4 lightPosition, // object space
18
+ uniform float4 lightPosition1, // object space
19
+ uniform float3 eyePosition, // object space
20
+ uniform float3 spotDirection, // object space
21
+ uniform float3 spotDirection1, // object space
22
+ uniform float4x4 worldViewProj,
23
+ uniform float4x4 worldMatrix,
24
+ uniform float4x4 texViewProj1,
25
+ uniform float4x4 texViewProj2)
26
+ {
27
+ // calculate output position
28
+ oPosition = mul(worldViewProj, position);
29
+
30
+ float4 worldPos = mul(worldMatrix, position);
31
+ oShadowUV1 = mul(texViewProj1, worldPos);
32
+ oShadowUV2 = mul(texViewProj2, worldPos);
33
+
34
+
35
+
36
+ // pass the main uvs straight through unchanged
37
+ oUv = uv;
38
+
39
+ // calculate tangent space light vector
40
+ // Get object space light direction
41
+ float3 lightDir = normalize(lightPosition.xyz - (position * lightPosition.w));
42
+ float3 lightDir1 = normalize(lightPosition1.xyz - (position * lightPosition1.w));
43
+ float3 eyeDir = eyePosition - position.xyz;
44
+
45
+ // Calculate the binormal (NB we assume both normal and tangent are
46
+ // already normalised)
47
+ // NB looks like nvidia cross params are BACKWARDS to what you'd expect
48
+ // this equates to NxT, not TxN
49
+ float3 binormal = cross(tangent, normal);
50
+
51
+ // Form a rotation matrix out of the vectors
52
+ float3x3 rotation = float3x3(tangent, binormal, normal);
53
+
54
+ // Transform the light vector according to this matrix
55
+ lightDir = normalize(mul(rotation, lightDir));
56
+ lightDir1 = normalize(mul(rotation, lightDir1));
57
+ eyeDir = normalize(mul(rotation, eyeDir));
58
+
59
+ oLightDir = lightDir;
60
+ oLightDir1 = lightDir1;
61
+ oEyeDir = eyeDir;
62
+ oSpotDirection = normalize(mul(rotation, -spotDirection));
63
+ oSpotDirection1 = normalize(mul(rotation, -spotDirection1));
64
+ }
65
+
66
+ // Expand a range-compressed vector
67
+ float3 expand(float3 v)
68
+ {
69
+ return (v - 0.5) * 2;
70
+ }
71
+
72
+ void integratedshadows_fp(
73
+ float2 uv : TEXCOORD0,
74
+ float3 lightDir : TEXCOORD1,
75
+ float3 eyeDir : TEXCOORD2,
76
+ float3 spotDir : TEXCOORD3,
77
+ float3 lightDir1 : TEXCOORD4,
78
+ float3 spotDir1 : TEXCOORD5,
79
+ float4 shadowUV1 : TEXCOORD6,
80
+ float4 shadowUV2 : TEXCOORD7,
81
+ uniform float3 lightDiffuse,
82
+ uniform float4 scaleBias,
83
+ uniform float4 spotParams,
84
+ uniform float3 lightDiffuse1,
85
+ uniform float4 spotParams1,
86
+ uniform sampler2D normalHeightMap : register(s0),
87
+ uniform sampler2D diffuseMap : register(s1),
88
+ uniform sampler2D shadowMap1 : register(s2),
89
+ uniform sampler2D shadowMap2 : register(s3),
90
+ out float4 oColour : COLOR)
91
+ {
92
+ // get the height using the tex coords
93
+ float height = tex2D(normalHeightMap, uv).a;
94
+
95
+ // scale and bias factors
96
+ float scale = scaleBias.x;
97
+ float bias = scaleBias.y;
98
+
99
+ // calculate displacement
100
+ float displacement = (height * scale) + bias;
101
+
102
+ float3 uv2 = float3(uv, 1);
103
+
104
+ float3 scaledEyeDir = eyeDir * displacement;
105
+
106
+ // calculate the new tex coord to use for normal and diffuse
107
+ float2 newTexCoord = (scaledEyeDir + uv2).xy;
108
+
109
+ // get the new normal and diffuse values
110
+ float3 normal = expand(tex2D(normalHeightMap, newTexCoord).xyz);
111
+ float3 diffuse = tex2D(diffuseMap, newTexCoord).xyz;
112
+
113
+ float3 col1 = diffuse * saturate(dot(normal, lightDir)) * lightDiffuse;
114
+ // factor in spotlight angle
115
+ float rho = saturate(dot(spotDir, lightDir));
116
+ // factor = (rho - cos(outer/2) / cos(inner/2) - cos(outer/2)) ^ falloff
117
+ float spotFactor = pow(
118
+ saturate(rho - spotParams.y) / (spotParams.x - spotParams.y), spotParams.z);
119
+ col1 = col1 * spotFactor;
120
+ float3 col2 = diffuse * saturate(dot(normal, lightDir1)) * lightDiffuse1;
121
+ // factor in spotlight angle
122
+ rho = saturate(dot(spotDir1, lightDir1));
123
+ // factor = (rho - cos(outer/2) / cos(inner/2) - cos(outer/2)) ^ falloff
124
+ spotFactor = pow(
125
+ saturate(rho - spotParams1.y) / (spotParams1.x - spotParams1.y), spotParams1.z);
126
+ col2 = col2 * spotFactor;
127
+
128
+ // shadow textures
129
+ col1 = col1 * tex2Dproj(shadowMap1, shadowUV1);
130
+ col2 = col2 * tex2Dproj(shadowMap2, shadowUV2);
131
+
132
+ oColour = float4(col1 + col2, 1);
133
+
134
+ }
135
+
@@ -0,0 +1,69 @@
1
+ uniform vec4 lightDiffuse;
2
+ uniform vec4 scaleBias;
3
+ uniform vec4 spotParams;
4
+ uniform vec4 lightDiffuse1;
5
+ uniform vec4 spotParams1;
6
+
7
+ uniform sampler2D normalHeightMap;
8
+ uniform sampler2D diffuseMap;
9
+ uniform sampler2D shadowMap1;
10
+ uniform sampler2D shadowMap2;
11
+
12
+
13
+
14
+ varying vec3 tangentEyeDir;
15
+ varying vec3 tangentLightDir[2];
16
+ varying vec3 tangentSpotDir[2];
17
+ varying vec4 shadowUV[2];
18
+
19
+
20
+ // Expand a range-compressed vector
21
+ vec3 expand(vec3 v)
22
+ {
23
+ return (v - 0.5) * 2.0;
24
+ }
25
+
26
+
27
+ void main()
28
+ {
29
+ // get the height using the tex coords
30
+ float height = texture2D(normalHeightMap, gl_TexCoord[0].xy).a;
31
+ // scale and bias factors
32
+ float scale = scaleBias.x;
33
+ float bias = scaleBias.y;
34
+
35
+ // calculate displacement
36
+ float displacement = (height * scale) + bias;
37
+ //float displacement = (height * 0.04) - 0.02;
38
+
39
+ vec3 scaledEyeDir = tangentEyeDir * displacement;
40
+
41
+ // calculate the new tex coord to use for normal and diffuse
42
+ vec2 newTexCoord = (scaledEyeDir + gl_TexCoord[0].xyz).xy;
43
+
44
+ // get the new normal and diffuse values
45
+ vec3 normal = expand(texture2D(normalHeightMap, newTexCoord).xyz);
46
+ vec4 diffuse = texture2D(diffuseMap, newTexCoord);
47
+
48
+ vec4 col1 = diffuse * clamp(dot(normal, tangentLightDir[0]),0.0,1.0) * lightDiffuse;
49
+ // factor in spotlight angle
50
+ float rho = clamp(dot(tangentSpotDir[0], tangentLightDir[0]),0.0,1.0);
51
+ // factor = (rho - cos(outer/2) / cos(inner/2) - cos(outer/2)) ^ falloff
52
+ float spotFactor = pow(
53
+ clamp(rho - spotParams.y,0.0,1.0) / (spotParams.x - spotParams.y), spotParams.z);
54
+ col1 = col1 * spotFactor;
55
+ vec4 col2 = diffuse * clamp(dot(normal, tangentLightDir[1]),0.0,1.0) * lightDiffuse1;
56
+ // factor in spotlight angle
57
+ rho = clamp(dot(tangentSpotDir[1], tangentLightDir[1]),0.0,1.0);
58
+ // factor = (rho - cos(outer/2) / cos(inner/2) - cos(outer/2)) ^ falloff
59
+ spotFactor = pow(
60
+ clamp(rho - spotParams1.y,0.0,1.0) / (spotParams1.x - spotParams1.y), spotParams1.z);
61
+ col2 = col2 * spotFactor;
62
+
63
+ // shadow textures
64
+ col1 = col1 * texture2DProj(shadowMap1, shadowUV[0]);
65
+ col2 = col2 * texture2DProj(shadowMap2, shadowUV[1]);
66
+
67
+ gl_FragColor = col1 + col2;
68
+
69
+ }
@@ -0,0 +1,54 @@
1
+ attribute vec3 tangent;
2
+
3
+ uniform vec4 lightPosition; // object space
4
+ uniform vec4 lightPosition1; // object space
5
+ uniform vec4 eyePosition; // object space
6
+ uniform vec4 spotDirection; // object space
7
+ uniform vec4 spotDirection1; // object space
8
+ uniform mat4 worldViewProj; // not actually used but here for compat with HLSL
9
+ uniform mat4 worldMatrix;
10
+ uniform mat4 texViewProj1;
11
+ uniform mat4 texViewProj2;
12
+
13
+
14
+ varying vec3 tangentEyeDir;
15
+ varying vec3 tangentLightDir[2];
16
+ varying vec3 tangentSpotDir[2];
17
+ varying vec4 shadowUV[2];
18
+
19
+ void main()
20
+ {
21
+ gl_Position = ftransform();
22
+
23
+ vec4 worldPos = worldMatrix * gl_Vertex;
24
+
25
+ shadowUV[0] = texViewProj1 * worldPos;
26
+ shadowUV[1] = texViewProj2 * worldPos;
27
+
28
+ // pass the main uvs straight through unchanged
29
+ gl_TexCoord[0] = gl_MultiTexCoord0;
30
+
31
+ // calculate tangent space light vector
32
+ // Get object space light direction
33
+ vec3 lightDir = normalize(lightPosition.xyz - (gl_Vertex.xyz * lightPosition.w));
34
+ vec3 lightDir1 = normalize(lightPosition1.xyz - (gl_Vertex.xyz * lightPosition1.w));
35
+
36
+ vec3 eyeDir = (eyePosition - gl_Vertex).xyz;
37
+
38
+ // Calculate the binormal (NB we assume both normal and tangent are
39
+ // already normalised)
40
+ vec3 binormal = cross(gl_Normal, tangent);
41
+
42
+ // Form a rotation matrix out of the vectors
43
+ mat3 rotation = mat3(tangent, binormal, gl_Normal);
44
+
45
+ // Transform the light vector according to this matrix
46
+ tangentLightDir[0] = normalize(rotation * lightDir);
47
+ tangentLightDir[1] = normalize(rotation * lightDir1);
48
+ // Invert the Y on the eye dir since we'll be using this to alter UVs and
49
+ // GL has Y inverted
50
+ tangentEyeDir = normalize(rotation * eyeDir) * vec3(1, -1, 1);
51
+
52
+ tangentSpotDir[0] = normalize(rotation * -spotDirection.xyz);
53
+ tangentSpotDir[1] = normalize(rotation * -spotDirection1.xyz);
54
+ }
@@ -0,0 +1,44 @@
1
+ // Pixel Shader for doing bump mapping with parallax plus diffuse and specular lighting by nfz
2
+
3
+ // uv TEXCOORD0
4
+ // lightDir TEXCOORD1
5
+ // eyeDir TEXCOORD2
6
+ // half TEXCOORD3
7
+
8
+ // lightDiffuse c0
9
+ // lightSpecular c1
10
+ // Parallax scale and bias c2
11
+ // normal/height map texunit 0 - height map in alpha channel
12
+ // diffuse texture texunit 1
13
+
14
+ ps.1.4
15
+
16
+
17
+ texld r0, t0 // get height
18
+ texcrd r2.xyz, t0 // get uv coordinates
19
+ texcrd r3.xyz, t2 // get eyedir vector
20
+
21
+
22
+ mad r0.xyz, r0.a, c2.x, c2.y // displacement = height * scale + bias
23
+ mad r2.xyz, r3, r0, r2 // newtexcoord = eyedir * displacement + uv
24
+
25
+ phase
26
+
27
+ texld r0, r2.xyz // get normal N using newtexcoord
28
+ texld r1, r2.xyz // get diffuse texture using newtexcoord
29
+ texcrd r4.xyz, t1 // get lightdir vector
30
+ texcrd r5.xyz, t3 // get half angle vector
31
+
32
+ dp3_sat r5.rgb, r0_bx2, r5 // N dot H - spec calc
33
+ dp3_sat r4.rgb, r0_bx2, r4 // N dot L - diffuse calc
34
+ + mul r5.a, r5.r, r5.r
35
+ mul r0.rgb, r4, r1 // colour = diffusetex * N dot L
36
+ + mul r5.a, r5.a, r5.a
37
+
38
+ mul r5.rgb, r5.a, r5.a
39
+ mul r5.rgb, r5, r5
40
+ mul r5.rgb, r5, r5
41
+ mul r5.rgb, r5, c1 // specular = (N dot H)^32 * specularlight
42
+
43
+ mad r0.rgb, r0, c0, r5 // colour = diffusetex * (N dot L)* diffuselight + specular
44
+ + mov r0.a, c2.b
@@ -0,0 +1,17 @@
1
+ material CloudySky
2
+ {
3
+ technique
4
+ {
5
+ pass
6
+ {
7
+ lighting off
8
+ depth_write off
9
+
10
+ texture_unit
11
+ {
12
+ texture clouds.jpg
13
+ scroll_anim 0.15 0
14
+ }
15
+ }
16
+ }
17
+ }
@@ -0,0 +1,34 @@
1
+ material SceneSkyBox2
2
+ {
3
+ technique
4
+ {
5
+ pass
6
+ {
7
+ lighting off
8
+ depth_write off
9
+
10
+ texture_unit
11
+ {
12
+ cubic_texture cubescene_fr.jpg cubescene_bk.jpg cubescene_lf.jpg cubescene_rt.jpg cubescene_up.jpg cubescene_dn.jpg separateUV
13
+ tex_address_mode clamp
14
+ }
15
+ }
16
+ }
17
+ }
18
+ material SceneCubeMap2
19
+ {
20
+ technique
21
+ {
22
+ pass
23
+ {
24
+ lighting off
25
+
26
+ texture_unit
27
+ {
28
+ cubic_texture cubescene.jpg combinedUVW
29
+ tex_address_mode clamp
30
+ env_map cubic_reflection
31
+ }
32
+ }
33
+ }
34
+ }
@@ -0,0 +1,17 @@
1
+ material Flare
2
+ {
3
+ technique
4
+ {
5
+ pass
6
+ {
7
+ lighting off
8
+ scene_blend add
9
+ depth_write off
10
+
11
+ texture_unit
12
+ {
13
+ texture flare.png
14
+ }
15
+ }
16
+ }
17
+ }