Game Programming 08 OGRE3D Material in Action 2010 년 2 학기 디지털콘텐츠전공.
Post on 04-Jan-2016
229 Views
Preview:
Transcript
Game Programming 08OGRE3D Material in Action
2010 년 2 학기디지털콘텐츠전공
Rendering in Video Games
• Depth-Buffered Triangle Rasterization– Virtual Scene– Virtual Camera– Various Light Sources– Visual Properties
Solving the Rendering Equation (Shading Equation)
Rendering in OGRE3D
• Depth-Buffered Triangle Rasterization– Virtual Scene createScene()– Virtual Camera createCamera()/
createViewport()
– Various Light Sources createScene()– Visual Properties material
Solving the Rendering Equation (OGRE3D engine)
Materials in general
• The Material controls how objects look in the scene– Basic surface properties such as:
• reflectance, diffuse color, shininess, etc.
– How to use textures• What images to be used• How many and how to blend them
– Special effects such as:• Environmental mapping• Culling mode• filtering
Materials in OGRE
• SceneManager class manages the list of materials available to the scene
• To ways of loading a material– Creating and tweaking it by a code
• MaterialManager
– Using a script to be loaded at runtime• Material Script
Material Script
• OGRE Material Script:– File name: ‘’*.material ’’ – A text file which describe a material– Easy to define a complex material– Reuse easily for different games
• How to load – OGRE looks for *.material files in all resource
locations.– Call ‘load’ method in order to complete the
loading process otherwise, the materials are not available.
Material Script: Format
// This is a commentmaterial walls/funkywall1{ // first, preferred technique technique { // first pass pass { ambient 0.5 0.5 0.5 diffuse 1.0 1.0 1.0
// Texture unit 0 texture_unit { texture wibbly.jpg scroll_anim 0.1 0.0 wave_xform scale sine 0.0 0.7 0.0 1.0 } // Texture unit 1 (this is a multitexture pass) texture_unit { texture wobbly.png rotate_anim 0.25 colour_op add } } }}
// This is a commentmaterial walls/funkywall1{ // first, preferred technique technique { // first pass pass { ambient 0.5 0.5 0.5 diffuse 1.0 1.0 1.0
// Texture unit 0 texture_unit { texture wibbly.jpg scroll_anim 0.1 0.0 wave_xform scale sine 0.0 0.7 0.0 1.0 } // Texture unit 1 (this is a multitexture pass) texture_unit { texture wobbly.png rotate_anim 0.25 colour_op add } } }}
Material Script: Name
• Material name– Should be unique – ‘/’ is used for grouping conceptually– ‘:’ can be used after the name for inherit from
other existing material
// This is a commentmaterial walls/funkywall1{
……}
// This is a commentmaterial walls/funkywall1{
……}
Material Script: Technique
• Technique– Define how the material looks– Can have multiple techniques used as a
fallback or in a different LOD level.– Each Technique is made up of multiple passes
// This is a commentmaterial walls/funkywall1{ // first, preferred technique technique {
……… } // second, preferred technique technique {
……… }
}
// This is a commentmaterial walls/funkywall1{ // first, preferred technique technique {
……… } // second, preferred technique technique {
……… }
}
Material Script: Pass
• Single Pass– One single rendering with a given setup– A pass has global attributes such as ambient, diffuse, etc.– A pass can have a texture unit or multiple texture units
• Multiple Passes (1~16 passes)– Rendering can be done multiple times with different setup – The final rendering result will be obtained by compositing
every results from the passes.
material walls/funkywall1{ technique { // first pass pass {
…… } }}
material walls/funkywall1{ technique { // first pass pass {
…… } }}
Material Script: Pass• Global attributes
– Ambient color• Format: ambient (<red> <green> <blue> [<alpha>]| vertexcolour)• Example: ambient 0.0 0.8 0.0 • Default: ambient 1.0 1.0 1.0 1.0
– Diffuse color• Format: diffuse (<red> <green> <blue> [<alpha>]| vertexcolour)• Example: diffuse 1.0 0.5 0.5• Default: diffuse 1.0 1.0 1.0 1.0
– Specular color• Format: specular (<red> <green> <blue> [<alpha>]| vertexcolour)
<shininess>
• Example: specular 1.0 1.0 1.0 12.5• Shininess: any value between 0~128 (the bigger, the sharper)• Default: specular 0.0 0.0 0.0 0.0 0.0
Material Script: Pass• Global attributes
– scene_blend• How to blend the pass with the existing scene content• Flexible version:
– Format: scene_blend <src_factor> <dest_factor>– Meaning: (pass_result * sourceFactor) + (scene_pixel * destFactor)– Factors: one | zero | src_color | one_minus_src_colour |
dest_colour | one_minus_dest_colour | dest_alpha | one_minus_dest_alpha | src_alpha | one_minus_src_alpha
– Example: scene_blend one one_minus_dest_alpha
• Simpler version– Format2: scene_blend <add | modulate | alpha_blend | colour_blend>– Meaning:
» add: 'scene_blend one one‘ (explosions, flares, lights, ghosts)» modulate: 'scene_blend dest_colour zero‘ (darkening, smoked glass)» colour_blend: 'scene_blend src_colour one_minus_src_colour' » alpha_blend: 'scene_blend src_alpha one_minus_src_alpha‘
– Example: scene_blend add
– scene_blend_op• Specify the operation in scene blending• Format: scene_blend_op <add | subtract | reverse_subtract | min | max>• Meaning: (pass_result * sourceFactor) +(-) (scene_pixel * destFactor)• Default: scene_blend_op add
Material Script: Pass• Global attributes
– Lighting on/off• Format: lighting <on | off>• If off, all objects will be fully lit.• Default: lighting on
– Shading• Format: shading <flat | gouraud | phong>• Default: shading gouraud
– Polygon mode• Format: polygon_mode <solid | wireframe | points>• Default: polygon_mode solid
Material Script: Pass• Global attributes
– Depth check• Format: depth_check <on|off>• Default: depth_check on
– Depth write• Format: depth_write <on|off>• Default: depth_write on
– Depth function• Determine how to check the depth • Format: depth_func <func>• <func>
– always_fail : Never writes a pixel to the render target – always_pass : Always writes a pixel to the render target – less : Write if (new_Z < existing_Z) – less_equal : Write if (new_Z <= existing_Z) – equal : Write if (new_Z == existing_Z) – not_equal : Write if (new_Z != existing_Z) – greater_equal : Write if (new_Z >= existing_Z) – greater :Write if (new_Z >existing_Z)
• Default: depth_func less_equal
Material Script: texture_unit• Texture
– Set name of the texture image • Format: texture <texturename> [<type>] [unlimited | numMipMaps]
[alpha] [<PixelFormat>] [gamma]• Example: texture funkywall.jpg
• Animated texture– Set the images to be used in animated texture
• Format1 (short): anim_texture <base_name> <num_frames> <duration>
• Example: anim_texture flame.jpg 3 1.5• Meaning: load 3 frames (frame_0.jpg, frame_1.jpg, frame_2.jpg) for
1.5 sec.
• Format2 (long): anim_texture <frame1> <frame2> ... <duration>• Example: anim_texture flamestart.jpg flamemore.png flameagain.jpg
1.5
Material Script: texture_unit• Texture coordinate set
– Sets which texture coordinate set is to be used• Format: tex_coord_set <set_num>• Example: tex_coord_set 2
• Texture address mode– Defines what happens when uv values exceed 1.0
• Simple Format: tex_address_mode <uv_mode> • Extended Format: tex_address_mode <u_mode> <v_mode> • Mode: <wrap | clamp | mirror | border>
• Texture border color– Set the border color when thexture address mode is
border• Format: tex_border_colour <red> <green> <blue> [<alpha>]• Example: tex_border_colour 0.0 1.0 0.3
Material Script: texture_unit
• Color operation– Determines how the color of this texture layer is
combined with the one below it– Format: colour_op <operation_type>– Operation types:
• replace : Replace all color with texture with no adjustment
• add : Add color components together. • modulate : Multiply colour components together• alpha_blend : Blend based on texture alpha
– Default: colour_op modulate
Material Script: texture_unit
• Texture Transformation– Scroll
• Sets a fixed scroll offset for the texture.• Format: scroll <x> <y>
– Scrolling animation• Sets up an animated scroll for the texture layer • Format: scroll_anim <xspeed> <yspeed>
– Rotate• Format: rotate <angle>
– Rotating animation• Format: rotate_anim <revs_per_second>
– Scale• Format: scale <x_scale> <y_scale>
Material Script: texture_unit• Advanced Texture Transformation
– Animation using wave function• Format: wave_xform <xform_type> <wave_type> <base> <frequency>
<phase> <amplitude>• Example: wave_xform scale_x sine 1.0 0.2 0.0 5.0• xform_types:
– scroll_x : Animate the x scroll value – scroll_y : Animate the y scroll value – rotate : Animate the rotate value – scale_x : Animate the x scale value – scale_y : Animate the y scale value
• wave_types:– sine
» A typical sine wave which smoothly loops between min and max values – triangle
» An angled wave which increases & decreases at constant speed, changing instantly at the extremes
– square » Max for half the wavelength, min for the rest with instant transition between
– sawtooth » Gradual steady increase from min to max over the period with an instant
return to min at the end. – inverse_sawtooth
» Gradual steady decrease from max to min over the period, with an instant return to max at the end.
• Base: The base value, the minimum if amplitude > 0, the maximum if amplitude < 0
Material Script: other functions• There are other advanced shader-based
functions in Material script– Vertex/geometry/fragment programs– CG programs– HLSL programs– GLSL programs
Reference for the materials
• http://www.ogre3d.org/tikiwiki/Materials
Manual Creation
• Using MaterialManager
Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create
( "Test/ColourTest",
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
material->getTechnique(0)->getPass(0)->setDiffuse(Ogre::ColourValue(1.0,0.0,0.0));
Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create
( "Test/ColourTest",
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
material->getTechnique(0)->getPass(0)->setDiffuse(Ogre::ColourValue(1.0,0.0,0.0));
Material basic attributes• ambient reflectance = ColourValue::White (full) • diffuse reflectance = ColourValue::White (full) • specular reflectance = ColourValue::Black (none) • emmissive = ColourValue::Black (none) • shininess = 0 (not shiny) • No texture layers (& hence no textures) • SourceBlendFactor = SBF_ONE, DestBlendFactor =
SBF_ZERO (opaque) • Depth buffer checking = on • Depth buffer writing = on • Depth buffer comparison function = CMPF_LESS_EQUAL • Culling mode = CULL_CLOCKWISE • Ambient lighting in scene = ColourValue(0.5, 0.5, 0.5) (mid-
grey) • Dynamic lighting = enabled • Gourad shading mode • Solid polygon mode • Bilinear texture filtering
top related