shattered_ogrerb 0.5.0.1 → 0.5.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/shattered_ogrerb/mesh_instance.rb +9 -0
- data/vendor/Navi/js3250.dll +0 -0
- data/vendor/Navi/nspr4.dll +0 -0
- data/vendor/Navi/plc4.dll +0 -0
- data/vendor/Navi/plds4.dll +0 -0
- data/vendor/Navi/xpcom.dll +0 -0
- data/vendor/Navi/xul.dll +0 -0
- data/vendor/ogrerb/CHANGELOG +7 -0
- data/vendor/ogrerb/README +7 -2
- data/vendor/ogrerb/Rakefile +98 -10
- data/vendor/ogrerb/build/ogre/extconf.rb +6 -0
- data/vendor/ogrerb/build/ois/extconf.rb +8 -1
- data/vendor/ogrerb/doc_src/ogre.rb +97 -3
- data/vendor/ogrerb/lib/OIS.so +0 -0
- data/vendor/ogrerb/{samples → lib}/application.rb +0 -0
- data/vendor/ogrerb/{samples → lib}/application_frame_listener.rb +1 -1
- data/vendor/ogrerb/{samples → lib}/application_loading_bar.rb +12 -12
- data/vendor/ogrerb/lib/constants.rb +16 -0
- data/vendor/ogrerb/lib/method_fixes.rb +42 -0
- data/vendor/ogrerb/lib/navi.dll +0 -0
- data/vendor/ogrerb/lib/ogre.dll +0 -0
- data/vendor/ogrerb/lib/ogre.so +0 -0
- data/vendor/ogrerb/lib/ruby_ois.dll +0 -0
- data/vendor/ogrerb/lib/ruby_ois.so +0 -0
- data/vendor/ogrerb/ogre/OgreAxisAlignedBox.i +6 -0
- data/vendor/ogrerb/ogre/OgreHardwareIndexBuffer.i +14 -0
- data/vendor/ogrerb/ogre/OgreHardwareVertexBuffer.i +33 -1
- data/vendor/ogrerb/ogre/OgreMaterialManager.i +1 -1
- data/vendor/ogrerb/ogre/OgreMesh.i +32 -0
- data/vendor/ogrerb/ogre/OgreQuaternion.i +5 -0
- data/vendor/ogrerb/ogre/OgreRenderSystemCapabilities.i +4 -0
- data/vendor/ogrerb/ogre/OgreShadowTextureManager.i +6 -1
- data/vendor/ogrerb/ogre/OgreStaticGeometry.i +272 -0
- data/vendor/ogrerb/ogre/OgreStringVector.i +20 -0
- data/vendor/ogrerb/ogre/OgreSubMesh.i +4 -0
- data/vendor/ogrerb/ogre/OgreTextureUnitState.i +3 -0
- data/vendor/ogrerb/ogre/OgreVector4.i +4 -0
- data/vendor/ogrerb/ogre/ogre_rb.i +26 -18
- data/vendor/ogrerb/ogre.rb +5 -3
- data/vendor/ogrerb/samples/bsp.rb +2 -0
- data/vendor/ogrerb/samples/cel_shading.rb +85 -0
- data/vendor/ogrerb/samples/grass.rb +325 -0
- data/vendor/ogrerb/samples/lighting.rb +2 -0
- data/vendor/ogrerb/samples/media/materials/programs/CelShading.cg +63 -0
- data/vendor/ogrerb/samples/media/materials/programs/Grass.cg +30 -0
- data/vendor/ogrerb/samples/media/materials/programs/OffsetMapping.cg +97 -0
- data/vendor/ogrerb/samples/media/materials/programs/OffsetMapping.hlsl +135 -0
- data/vendor/ogrerb/samples/media/materials/programs/OffsetMappingFp.glsl +69 -0
- data/vendor/ogrerb/samples/media/materials/programs/OffsetMappingVp.glsl +54 -0
- data/vendor/ogrerb/samples/media/materials/programs/OffsetMapping_specular.asm +44 -0
- data/vendor/ogrerb/samples/media/materials/scripts/CelShading.material +68 -0
- data/vendor/ogrerb/samples/media/materials/scripts/CubeMapping.material +34 -0
- data/vendor/ogrerb/samples/media/materials/scripts/Grass.material +63 -0
- data/vendor/ogrerb/samples/media/materials/scripts/Offset.material +124 -0
- data/vendor/ogrerb/samples/media/materials/scripts/RZR-002.material +15 -0
- data/vendor/ogrerb/samples/media/materials/textures/RZR-002.png +0 -0
- data/vendor/ogrerb/samples/media/materials/textures/cel_shading_diffuse.png +0 -0
- data/vendor/ogrerb/samples/media/materials/textures/cel_shading_edge.png +0 -0
- data/vendor/ogrerb/samples/media/materials/textures/cel_shading_specular.png +0 -0
- data/vendor/ogrerb/samples/media/materials/textures/gras_02.png +0 -0
- data/vendor/ogrerb/samples/media/materials/textures/grass_1024.jpg +0 -0
- data/vendor/ogrerb/samples/media/materials/textures/rockwall.tga +0 -0
- data/vendor/ogrerb/samples/media/materials/textures/rockwall_NH.tga +0 -0
- data/vendor/ogrerb/samples/media/models/RZR-002.mesh +0 -0
- data/vendor/ogrerb/samples/media/models/geosphere4500.mesh +0 -0
- data/vendor/ogrerb/samples/media/models/geosphere8000.mesh +0 -0
- data/vendor/ogrerb/samples/media/models/sphere.mesh +0 -0
- data/vendor/ogrerb/samples/media/overlays/CubeMapping.overlay +139 -0
- data/vendor/ogrerb/samples/media.cfg +22 -0
- data/vendor/ogrerb/samples/plugins.cfg +1 -0
- data/vendor/ogrerb/samples/render_to_texture.rb +2 -0
- data/vendor/ogrerb/samples/resources.cfg +2 -0
- data/vendor/ogrerb/samples/sky_box.rb +2 -0
- data/vendor/ogrerb/samples/sky_dome.rb +2 -0
- data/vendor/ogrerb/samples/sky_plane.rb +3 -0
- data/vendor/ogrerb/samples/smoke.rb +2 -0
- data/vendor/ogrerb/samples/work/cube_mapping.rb +686 -0
- data/vendor/ogrerb/src_headers/wrappers/IndexBufferProxy.h +49 -0
- data/vendor/ogrerb/src_headers/wrappers/StaticGeometryProxies.h +867 -0
- data/vendor/ogrerb/src_headers/wrappers/VertexBufferProxy.h +245 -0
- data/vendor/ogrerb/website/index.html +9 -0
- metadata +54 -6
@@ -0,0 +1,325 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
|
3
|
+
$: << File.dirname(__FILE__) + "/.."
|
4
|
+
require 'ogre'
|
5
|
+
require 'application'
|
6
|
+
include Ogre
|
7
|
+
|
8
|
+
GRASS_HEIGHT = 300
|
9
|
+
GRASS_WIDTH = 250
|
10
|
+
GRASS_MESH_NAME = "grassblades"
|
11
|
+
GRASS_MATERIAL = "GrassBlades"
|
12
|
+
OFFSET_PARAM = 999
|
13
|
+
|
14
|
+
$anim_state = nil
|
15
|
+
$static_geom = nil
|
16
|
+
|
17
|
+
class GrassListener < ApplicationFrameListener
|
18
|
+
|
19
|
+
def initialize(root, win, cam, scene_manager)
|
20
|
+
super(root, win, cam)
|
21
|
+
@scene_manager = scene_manager
|
22
|
+
@show_bbs = false
|
23
|
+
|
24
|
+
@xinc = Math::PI * 0.4
|
25
|
+
@zinc = Math::PI * 0.55
|
26
|
+
@xpos = Ogre::Math.range_random(-Math::PI, Math::PI)
|
27
|
+
@zpos = Ogre::Math.range_random(-Math::PI, Math::PI)
|
28
|
+
@offset = Vector4.new(0,0,0,0)
|
29
|
+
|
30
|
+
@time_delay = 0.0
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
def wave_grass(time_elapsed)
|
35
|
+
# May not be setup yet
|
36
|
+
return if $static_geom.nil?
|
37
|
+
|
38
|
+
@xpos += @xinc * time_elapsed
|
39
|
+
@zpos += @zinc * time_elapsed
|
40
|
+
|
41
|
+
rit = $static_geom.get_region_iterator
|
42
|
+
|
43
|
+
while rit.has_more_elements
|
44
|
+
reg = rit.get_next
|
45
|
+
|
46
|
+
@xpos += reg.get_centre.x * 0.001
|
47
|
+
@zpos += reg.get_centre.z * 0.001
|
48
|
+
@offset.x = Ogre::Math.sin(@xpos) * 0.5
|
49
|
+
@offset.z = Ogre::Math.sin(@zpos) * 0.05
|
50
|
+
|
51
|
+
lod_it = reg.get_lod_iterator
|
52
|
+
|
53
|
+
while lod_it.has_more_elements
|
54
|
+
lod = lod_it.get_next
|
55
|
+
mat_it = lod.get_material_iterator
|
56
|
+
while mat_it.has_more_elements
|
57
|
+
mat = mat_it.get_next
|
58
|
+
geom_it = mat.get_geometry_iterator
|
59
|
+
while geom_it.has_more_elements
|
60
|
+
geom = geom_it.get_next
|
61
|
+
geom.as_renderable.set_custom_parameter(OFFSET_PARAM, @offset)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def frame_started(event)
|
69
|
+
return false unless super
|
70
|
+
|
71
|
+
@time_delay -= event.time_since_last_frame
|
72
|
+
|
73
|
+
if $anim_state
|
74
|
+
$anim_state.add_time(event.time_since_last_frame)
|
75
|
+
end
|
76
|
+
|
77
|
+
if keyboard.key_down?(OIS::KC_B) && time_delay <= 0
|
78
|
+
@time_delay = 1
|
79
|
+
@show_bbs = !@show_bbs
|
80
|
+
@scene_manager.show_bounding_boxes(@show_bbs)
|
81
|
+
end
|
82
|
+
|
83
|
+
wave_grass(event.time_since_last_frame)
|
84
|
+
|
85
|
+
true
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
class GrassApplication < Application
|
90
|
+
def create_grass_mesh
|
91
|
+
mesh = MeshManager.instance.create_manual(GRASS_MESH_NAME,
|
92
|
+
ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME)
|
93
|
+
sm = mesh.create_sub_mesh
|
94
|
+
sm.use_shared_vertices = false
|
95
|
+
sm.vertex_data = VertexData.new
|
96
|
+
sm.vertex_data.vertex_start = 0
|
97
|
+
sm.vertex_data.vertex_count = 12
|
98
|
+
|
99
|
+
decl = sm.vertex_data.vertex_declaration
|
100
|
+
offset = 0
|
101
|
+
|
102
|
+
decl.add_element(0, offset, VET_FLOAT3, VES_POSITION)
|
103
|
+
offset += VertexElement.get_type_size(VET_FLOAT3)
|
104
|
+
decl.add_element(0, offset, VET_FLOAT3, VES_NORMAL)
|
105
|
+
offset += VertexElement.get_type_size(VET_FLOAT3)
|
106
|
+
decl.add_element(0, offset, VET_FLOAT2, VES_TEXTURE_COORDINATES)
|
107
|
+
offset += VertexElement.get_type_size(VET_FLOAT2)
|
108
|
+
|
109
|
+
vbuf = HardwareBufferManager.instance.create_vertex_buffer(
|
110
|
+
offset, 12, HardwareBuffer::HBU_STATIC_WRITE_ONLY)
|
111
|
+
reals = vbuf.lock(HardwareBuffer::HBL_DISCARD)
|
112
|
+
|
113
|
+
base_vec = Vector3.new(GRASS_WIDTH / 2, 0, 0)
|
114
|
+
vec = Vector3.new(GRASS_WIDTH / 2, 0, 0)
|
115
|
+
rot = Quaternion.new
|
116
|
+
rot.from_angle_axis(Degree.new(60), Vector3.UNIT_Y)
|
117
|
+
|
118
|
+
3.times do |i|
|
119
|
+
x = i * 32
|
120
|
+
# Position
|
121
|
+
reals[x + 0] = -vec.x
|
122
|
+
reals[x + 1] = GRASS_HEIGHT
|
123
|
+
reals[x + 2] = -vec.z
|
124
|
+
# Normal
|
125
|
+
reals[x + 3] = 0
|
126
|
+
reals[x + 4] = 1
|
127
|
+
reals[x + 5] = 0
|
128
|
+
# UV
|
129
|
+
reals[x + 6] = 0
|
130
|
+
reals[x + 7] = 0
|
131
|
+
|
132
|
+
# Position
|
133
|
+
reals[x + 8] = vec.x
|
134
|
+
reals[x + 9] = GRASS_HEIGHT
|
135
|
+
reals[x + 10] = vec.z
|
136
|
+
# Normal
|
137
|
+
reals[x + 11] = 0
|
138
|
+
reals[x + 12] = 1
|
139
|
+
reals[x + 13] = 0
|
140
|
+
# UV
|
141
|
+
reals[x + 14] = 1
|
142
|
+
reals[x + 15] = 0
|
143
|
+
|
144
|
+
# Position
|
145
|
+
reals[x + 16] = -vec.x
|
146
|
+
reals[x + 17] = 0
|
147
|
+
reals[x + 18] = -vec.z
|
148
|
+
# Normal
|
149
|
+
reals[x + 19] = 0
|
150
|
+
reals[x + 20] = 1
|
151
|
+
reals[x + 21] = 0
|
152
|
+
# UV
|
153
|
+
reals[x + 22] = 0
|
154
|
+
reals[x + 23] = 1
|
155
|
+
|
156
|
+
# Position
|
157
|
+
reals[x + 24] = vec.x
|
158
|
+
reals[x + 25] = 0
|
159
|
+
reals[x + 26] = vec.z
|
160
|
+
# Normal
|
161
|
+
reals[x + 27] = 0
|
162
|
+
reals[x + 28] = 1
|
163
|
+
reals[x + 29] = 0
|
164
|
+
# UV
|
165
|
+
reals[x + 30] = 1
|
166
|
+
reals[x + 31] = 1
|
167
|
+
|
168
|
+
vec = rot * vec
|
169
|
+
end
|
170
|
+
|
171
|
+
vbuf.unlock
|
172
|
+
|
173
|
+
sm.vertex_data.vertex_buffer_binding.set_binding(0, vbuf)
|
174
|
+
sm.index_data.index_count = 6 * 3
|
175
|
+
sm.index_data.index_buffer = HardwareBufferManager.instance.
|
176
|
+
create_index_buffer(HardwareIndexBuffer::IT_16BIT, 6 * 3,
|
177
|
+
HardwareBuffer::HBU_STATIC_WRITE_ONLY)
|
178
|
+
index = sm.index_data.index_buffer.lock(HardwareBuffer::HBL_DISCARD)
|
179
|
+
|
180
|
+
3.times do |i|
|
181
|
+
x = i * 6
|
182
|
+
off = i * 4
|
183
|
+
|
184
|
+
index[x + 0] = 0 + off
|
185
|
+
index[x + 1] = 3 + off
|
186
|
+
index[x + 2] = 1 + off
|
187
|
+
|
188
|
+
index[x + 3] = 0 + off
|
189
|
+
index[x + 4] = 2 + off
|
190
|
+
index[x + 5] = 3 + off
|
191
|
+
end
|
192
|
+
|
193
|
+
sm.index_data.index_buffer.unlock
|
194
|
+
|
195
|
+
sm.set_material_name(GRASS_MATERIAL)
|
196
|
+
mesh.load
|
197
|
+
end
|
198
|
+
|
199
|
+
def setup_lighting
|
200
|
+
scene_manager.set_ambient_light ColourValue.new(0.2, 0.2, 0.2)
|
201
|
+
|
202
|
+
# Point light, movable, reddish
|
203
|
+
@light = scene_manager.create_light("Light2")
|
204
|
+
@light.set_diffuse_colour(@min_light_colour)
|
205
|
+
@light.set_specular_colour(1, 1, 1)
|
206
|
+
@light.set_attenuation(8000, 1, 0.0005, 0)
|
207
|
+
|
208
|
+
@light_node = scene_manager.root_scene_node.create_child_scene_node("MovingLightNode")
|
209
|
+
@light_node.attach_object(@light)
|
210
|
+
|
211
|
+
bbs = scene_manager.create_billboard_set("lightbbs", 1)
|
212
|
+
bbs.set_material_name("Flare")
|
213
|
+
bb = bbs.create_billboard(0, 0, 0, @min_light_colour)
|
214
|
+
@light_node.attach_object(bbs)
|
215
|
+
|
216
|
+
# TODO Controller code
|
217
|
+
|
218
|
+
@light_node.set_position(Vector3.new(300, 250, -300))
|
219
|
+
|
220
|
+
anim = scene_manager.create_animation("LightTrack", 20)
|
221
|
+
# Spline it
|
222
|
+
anim.set_interpolation_mode(Animation::IM_SPLINE)
|
223
|
+
track = anim.create_node_track(0, @light_node)
|
224
|
+
|
225
|
+
key = track.create_node_key_frame(0)
|
226
|
+
key.set_translate(Vector3.new(300,550,-300))
|
227
|
+
key = track.create_node_key_frame(2)#B
|
228
|
+
key.set_translate(Vector3.new(150,600,-250))
|
229
|
+
key = track.create_node_key_frame(4)#C
|
230
|
+
key.set_translate(Vector3.new(-150,650,-100))
|
231
|
+
key = track.create_node_key_frame(6)#D
|
232
|
+
key.set_translate(Vector3.new(-400,500,-200))
|
233
|
+
key = track.create_node_key_frame(8)#E
|
234
|
+
key.set_translate(Vector3.new(-200,500,-400))
|
235
|
+
key = track.create_node_key_frame(10)#F
|
236
|
+
key.set_translate(Vector3.new(-100,450,-200))
|
237
|
+
key = track.create_node_key_frame(12)#G
|
238
|
+
key.set_translate(Vector3.new(-100,400,180))
|
239
|
+
key = track.create_node_key_frame(14)#H
|
240
|
+
key.set_translate(Vector3.new(0,250,600))
|
241
|
+
key = track.create_node_key_frame(16)#I
|
242
|
+
key.set_translate(Vector3.new(100,650,100))
|
243
|
+
key = track.create_node_key_frame(18)#J
|
244
|
+
key.set_translate(Vector3.new(250,600,0))
|
245
|
+
key = track.create_node_key_frame(20)#K == A
|
246
|
+
key.set_translate(Vector3.new(300,550,-300))
|
247
|
+
# Create a new animation state to track this
|
248
|
+
$anim_state = scene_manager.create_animation_state("LightTrack")
|
249
|
+
$anim_state.set_enabled(true)
|
250
|
+
end
|
251
|
+
|
252
|
+
def create_scene
|
253
|
+
@min_light_colour = ColourValue.new(0.5, 0.1, 0.0)
|
254
|
+
|
255
|
+
scene_manager.set_sky_box(true, "SpaceSkyBox")
|
256
|
+
|
257
|
+
setup_lighting
|
258
|
+
|
259
|
+
plane = Plane.new
|
260
|
+
plane.normal = Vector3.UNIT_Y
|
261
|
+
plane.d = 0
|
262
|
+
|
263
|
+
MeshManager.instance.create_plane("MyPlane",
|
264
|
+
ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, plane,
|
265
|
+
14500, 14500, 10, 10, true, 1, 50, 50, Vector3.UNIT_Z)
|
266
|
+
|
267
|
+
plane_ent = scene_manager.create_entity("plane", "MyPlane")
|
268
|
+
plane_ent.set_material_name("GrassFloor")
|
269
|
+
plane_ent.set_cast_shadows(false)
|
270
|
+
scene_manager.root_scene_node.create_child_scene_node.attach_object(plane_ent)
|
271
|
+
|
272
|
+
min_v = Vector3.new(-2000, 0, -2000)
|
273
|
+
max_v = Vector3.new(2000, 0, 2000)
|
274
|
+
|
275
|
+
create_grass_mesh
|
276
|
+
|
277
|
+
e = scene_manager.create_entity("1", GRASS_MESH_NAME)
|
278
|
+
|
279
|
+
s = scene_manager.create_static_geometry("bing")
|
280
|
+
s.set_region_dimensions(Vector3.new(1000, 1000, 1000))
|
281
|
+
s.set_origin(Vector3.new(-500, 500, -500))
|
282
|
+
|
283
|
+
-1950.step(1950, 150) do |x|
|
284
|
+
-1950.step(1950, 150) do |z|
|
285
|
+
pos = Vector3.new(x + Ogre::Math.range_random(-25, 25),
|
286
|
+
0,
|
287
|
+
z + Ogre::Math.range_random(-25, 25))
|
288
|
+
orientation = Quaternion.new
|
289
|
+
orientation.from_angle_axis(
|
290
|
+
Degree.new(Ogre::Math.range_random(0, 359)), Vector3.UNIT_Y)
|
291
|
+
scale = Vector3.new(1, Ogre::Math.range_random(0.85, 1.15), 1)
|
292
|
+
s.add_entity(e, pos, orientation, scale)
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
s.build
|
297
|
+
$static_geom = s
|
298
|
+
|
299
|
+
# Gots to have the Ogre head
|
300
|
+
m = MeshManager.instance.load("ogrehead.mesh",
|
301
|
+
ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME)
|
302
|
+
src = 0
|
303
|
+
dest = 0
|
304
|
+
ret, src, dest = m.suggest_tangent_vector_build_params(VES_TANGENT)
|
305
|
+
unless ret
|
306
|
+
m.build_tangent_vectors(VES_TANGENT, src, dest)
|
307
|
+
end
|
308
|
+
|
309
|
+
e = scene_manager.create_entity("head", "ogrehead.mesh")
|
310
|
+
e.set_material_name("OffsetMapping/Specular")
|
311
|
+
head_node = scene_manager.root_scene_node.create_child_scene_node
|
312
|
+
head_node.attach_object(e)
|
313
|
+
head_node.set_scale(7, 7, 7)
|
314
|
+
head_node.set_position(0, 200, 0)
|
315
|
+
e.set_normalise_normals(true)
|
316
|
+
camera.move(Vector3.new(0, 350, 0))
|
317
|
+
end
|
318
|
+
|
319
|
+
def create_frame_listener
|
320
|
+
self.frame_listener = GrassListener.new(root, window, camera, scene_manager)
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
app = GrassApplication.new
|
325
|
+
app.go
|
@@ -0,0 +1,63 @@
|
|
1
|
+
|
2
|
+
/* Cel shading vertex program for single-pass rendering
|
3
|
+
In this program, we want to calculate the diffuse and specular
|
4
|
+
ramp components, and the edge factor (for doing simple outlining)
|
5
|
+
For the outlining to look good, we need a pretty well curved model.
|
6
|
+
*/
|
7
|
+
void main_vp(float4 position : POSITION,
|
8
|
+
float3 normal : NORMAL,
|
9
|
+
// outputs
|
10
|
+
out float4 oPosition : POSITION,
|
11
|
+
out float diffuse : TEXCOORD0,
|
12
|
+
out float specular : TEXCOORD1,
|
13
|
+
out float edge : TEXCOORD2,
|
14
|
+
// parameters
|
15
|
+
uniform float3 lightPosition, // object space
|
16
|
+
uniform float3 eyePosition, // object space
|
17
|
+
uniform float4 shininess,
|
18
|
+
uniform float4x4 worldViewProj)
|
19
|
+
{
|
20
|
+
// calculate output position
|
21
|
+
oPosition = mul(worldViewProj, position);
|
22
|
+
|
23
|
+
// calculate light vector
|
24
|
+
float3 N = normalize(normal);
|
25
|
+
float3 L = normalize(lightPosition - position.xyz);
|
26
|
+
|
27
|
+
// Calculate diffuse component
|
28
|
+
diffuse = max(dot(N, L) , 0);
|
29
|
+
|
30
|
+
// Calculate specular component
|
31
|
+
float3 E = normalize(eyePosition - position.xyz);
|
32
|
+
float3 H = normalize(L + E);
|
33
|
+
specular = pow(max(dot(N, H), 0), shininess);
|
34
|
+
// Mask off specular if diffuse is 0
|
35
|
+
if (diffuse == 0) specular = 0;
|
36
|
+
|
37
|
+
// Edge detection, dot eye and normal vectors
|
38
|
+
edge = max(dot(N, E), 0);
|
39
|
+
}
|
40
|
+
|
41
|
+
void main_fp(float diffuseIn : TEXCOORD0,
|
42
|
+
float specularIn : TEXCOORD1,
|
43
|
+
float edge : TEXCOORD2,
|
44
|
+
|
45
|
+
out float4 colour : COLOR,
|
46
|
+
|
47
|
+
uniform float4 diffuse,
|
48
|
+
uniform float4 specular,
|
49
|
+
|
50
|
+
uniform sampler1D diffuseRamp,
|
51
|
+
uniform sampler1D specularRamp,
|
52
|
+
uniform sampler1D edgeRamp)
|
53
|
+
{
|
54
|
+
// Step functions from textures
|
55
|
+
diffuseIn = tex1D(diffuseRamp, diffuseIn).x;
|
56
|
+
specularIn = tex1D(specularRamp, specularIn).x;
|
57
|
+
edge = tex1D(edgeRamp, edge).x;
|
58
|
+
|
59
|
+
colour = edge * ((diffuse * diffuseIn) +
|
60
|
+
(specular * specularIn));
|
61
|
+
}
|
62
|
+
|
63
|
+
|
@@ -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
|
+
|