ogre.rb 0.1-i386-mswin32 → 0.2-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.
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/ruby -w
2
+
3
+ $: << File.dirname(__FILE__) + "/.."
4
+ require 'ogre'
5
+ require 'application'
6
+ include Ogre
7
+
8
+ CUSTOM_SHININESS = 1
9
+ CUSTOM_DIFFUSE = 2
10
+ CUSTOM_SPECULAR = 3
11
+
12
+ class SkyDomeListener < ApplicationFrameListener
13
+ def initialize(root, window, camera, scene_manager)
14
+ super(root, window, camera)
15
+ @scene_manager = scene_manager
16
+ @curvature = 1
17
+ @tiling = 15
18
+
19
+ @time_delay = 0
20
+ end
21
+
22
+ def frame_started(event)
23
+ return false unless super(event)
24
+
25
+ $rot_node.yaw(Degree.new(event.time_since_last_frame * 30))
26
+
27
+ true
28
+ end
29
+ end
30
+
31
+ class SkyDomeApplication < Ogre::Application
32
+
33
+ def create_scene
34
+ caps = root.get_render_system.get_capabilities
35
+ if !caps.has_capability?(RSC_VERTEX_PROGRAM) || !caps.has_capability?(RSC_FRAGMENT_PROGRAM)
36
+ raise "Your card does not support vertex or fragmet programs, so we cannot run this demo. Sorry"
37
+ end
38
+
39
+ light = scene_manager.create_light("MainLight")
40
+ $rot_node = scene_manager.root_scene_node.create_child_scene_node
41
+ $rot_node.create_child_scene_node(Vector3.new(20, 40, 50)).attach_object(light)
42
+
43
+ ent = scene_manager.create_entity("head", "ogrehead.mesh")
44
+
45
+ camera.set_position(20, 0, 100)
46
+ camera.look_at(0,0,0)
47
+
48
+ # eyes
49
+ sub = ent.get_sub_entity(0)
50
+ sub.set_material_name("CelShading")
51
+ sub.set_custom_parameter(CUSTOM_SHININESS, Vector4.new(35.0, 0.0, 0.0, 0.0))
52
+ sub.set_custom_parameter(CUSTOM_DIFFUSE, Vector4.new(1.0, 0.3, 0.3, 1.0))
53
+ sub.set_custom_parameter(CUSTOM_SPECULAR, Vector4.new(1.0, 0.6, 0.6, 1.0))
54
+ # skin
55
+ sub = ent.get_sub_entity(1)
56
+ sub.set_material_name("CelShading")
57
+ sub.set_custom_parameter(CUSTOM_SHININESS, Vector4.new(10.0, 0.0, 0.0, 0.0))
58
+ sub.set_custom_parameter(CUSTOM_DIFFUSE, Vector4.new(0.0, 0.5, 0.0, 1.0))
59
+ sub.set_custom_parameter(CUSTOM_SPECULAR, Vector4.new(0.3, 0.5, 0.3, 1.0))
60
+ # earring
61
+ sub = ent.get_sub_entity(2)
62
+ sub.set_material_name("CelShading")
63
+ sub.set_custom_parameter(CUSTOM_SHININESS, Vector4.new(25.0, 0.0, 0.0, 0.0))
64
+ sub.set_custom_parameter(CUSTOM_DIFFUSE, Vector4.new(1.0, 1.0, 0.0, 1.0))
65
+ sub.set_custom_parameter(CUSTOM_SPECULAR, Vector4.new(1.0, 1.0, 0.7, 1.0))
66
+ # teeth
67
+ sub = ent.get_sub_entity(3)
68
+ sub.set_material_name("CelShading")
69
+ sub.set_custom_parameter(CUSTOM_SHININESS, Vector4.new(20.0, 0.0, 0.0, 0.0))
70
+ sub.set_custom_parameter(CUSTOM_DIFFUSE, Vector4.new(1.0, 1.0, 0.7, 1.0))
71
+ sub.set_custom_parameter(CUSTOM_SPECULAR, Vector4.new(1.0, 1.0, 1.0, 1.0))
72
+
73
+ # Add entity to the root scene node
74
+ scene_manager.root_scene_node.create_child_scene_node.attach_object(ent)
75
+
76
+ window.get_viewport(0).set_background_colour(ColourValue.White)
77
+ end
78
+
79
+ def create_frame_listener
80
+ self.frame_listener = SkyDomeListener.new(root, window, camera, scene_manager)
81
+ end
82
+ end
83
+
84
+ app = SkyDomeApplication.new
85
+ app.go
data/samples/grass.rb CHANGED
@@ -74,7 +74,7 @@ class GrassListener < ApplicationFrameListener
74
74
  $anim_state.add_time(event.time_since_last_frame)
75
75
  end
76
76
 
77
- if keyboard.key_down?(OIS::KC_B) && time_delay <= 0
77
+ if keyboard.key_down?(OIS::KC_B) && @time_delay <= 0
78
78
  @time_delay = 1
79
79
  @show_bbs = !@show_bbs
80
80
  @scene_manager.show_bounding_boxes(@show_bbs)
@@ -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,68 @@
1
+ // -------------------------------
2
+ // Cel Shading Section
3
+ // -------------------------------
4
+ vertex_program Ogre/CelShadingVP cg
5
+ {
6
+ source CelShading.cg
7
+ entry_point main_vp
8
+ profiles vs_1_1 arbvp1
9
+
10
+ default_params
11
+ {
12
+ param_named_auto lightPosition light_position_object_space 0
13
+ param_named_auto eyePosition camera_position_object_space
14
+ param_named_auto worldViewProj worldviewproj_matrix
15
+ param_named shininess float 10
16
+ }
17
+ }
18
+
19
+ fragment_program Ogre/CelShadingFP cg
20
+ {
21
+ source CelShading.cg
22
+ entry_point main_fp
23
+ profiles ps_1_1 arbfp1 fp20
24
+ }
25
+
26
+
27
+ material CelShading
28
+ {
29
+ technique
30
+ {
31
+ pass
32
+ {
33
+ vertex_program_ref Ogre/CelShadingVP
34
+ {
35
+ // map shininess from custom renderable param 1
36
+ param_named_auto shininess custom 1
37
+ }
38
+ fragment_program_ref Ogre/CelShadingFP
39
+ {
40
+ // map diffuse from custom renderable param 2
41
+ param_named_auto diffuse custom 2
42
+ // map specular from custom renderable param 2
43
+ param_named_auto specular custom 3
44
+ }
45
+ texture_unit
46
+ {
47
+ texture cel_shading_diffuse.png 1d
48
+ tex_address_mode clamp
49
+ filtering none
50
+ }
51
+ texture_unit
52
+ {
53
+ texture cel_shading_specular.png 1d
54
+ tex_address_mode clamp
55
+ filtering none
56
+ tex_coord_set 1
57
+ }
58
+ texture_unit
59
+ {
60
+ texture cel_shading_edge.png 1d
61
+ tex_address_mode clamp
62
+ filtering none
63
+ tex_coord_set 2
64
+ }
65
+ }
66
+ }
67
+
68
+ }
data/samples/ogre.cfg CHANGED
@@ -16,4 +16,4 @@ Floating-point mode=Fastest
16
16
  Full Screen=No
17
17
  Rendering Device=NVIDIA GeForce 6800 Series GPU
18
18
  VSync=No
19
- Video Mode=1024 x 768 @ 32-bit colour
19
+ Video Mode=800 x 600 @ 32-bit colour