Reiiden制作笔记H(OGRE Materilas/HLSL 的完整例子)

Materilas的总结
Materilas所有属性列表在:OgreReadMe -> The OGRE Manual -> Scripts -> Material Scripts(可翻页)

MyOGREMaterials.cpp

#include "MyOGREMaterials.h" void MyOGREMaterials::createScene(void) { // 自建一个网格 Ogre::ManualObject* manual = mSceneMgr->createManualObject("Quad"); manual->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_LIST); // 前一个值是纹理 manual->position(5.0, 0.0, 0.0); manual->textureCoord(0, 2); manual->position(-5.0, 10.0, 0.0); manual->textureCoord(2, 0); manual->position(-5.0, 0.0, 0.0); manual->textureCoord(2, 2); manual->position(5.0, 10.0, 0.0); manual->textureCoord(0, 0); manual->index(0); manual->index(1); manual->index(2); manual->index(0); manual->index(3); manual->index(1); manual->end(); manual->convertToMesh("Quad"); entity = mSceneMgr->createEntity("Quad"); node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node1"); node->attachObject(entity); } void MyOGREMaterials::destroyScene() { } bool MyOGREMaterials::keyPressed(const OIS::KeyEvent &arg) { switch(arg.key) { case OIS::KC_1: entity->setMaterialName("Mine/materilas_1"); break; case OIS::KC_2: entity->setMaterialName("Mine/materilas_2"); break; case OIS::KC_3: entity->setMaterialName("Mine/materilas_3"); break; case OIS::KC_4: entity->setMaterialName("Mine/materilas_4"); break; case OIS::KC_5: { static int b5 = 0; if(b5 == 0 ) { entity->setMaterialName("Mine/materilas_5"); b5 = 1; } else { entity->setMaterialName("Mine/materilas_5_1"); b5 = 0; } } break; case OIS::KC_6: entity->setMaterialName("Mine/materilas_6"); break; default: break; } return BaseApplication::keyPressed(arg); }

Mine.material

// 单纯纹理 material Mine/materilas_1 { technique { pass { texture_unit { texture leaf.png } } } } // 纹理 + 寻址(mirror,clamp,border) material Mine/materilas_2 { technique { pass { texture_unit { texture leaf.png tex_address_mode mirror } } } } // 纹理 + 寻址 + 边框色 material Mine/materilas_3 { technique { pass { texture_unit { texture leaf.png tex_border_colour 1.0 0.0 0.0 tex_address_mode border } } } } // 纹理 + 寻址 + 边框色 + 偏移 material Mine/materilas_4 { technique { pass { texture_unit { texture leaf.png tex_border_colour 1.0 0.0 0.0 tex_address_mode border scroll 0.8 0.8 } } } } // 动画 material Mine/materilas_5 { technique { pass { texture_unit t1 { texture leaf.png rotate_anim 0.1 } } } } // 继承 material Mine/materilas_5_1 : Mine/materilas_5 { set_texture_alias t1 Water02.jpg } // HLSL vertex_program Deferred_vs hlsl { source Deferred_vs.hlsl target vs_2_0 entry_point main default_params { param_named_auto worldViewProj worldviewproj_matrix } } fragment_program Deferred_ps hlsl { source Deferred_ps.hlsl target ps_2_0 entry_point main } material Mine/materilas_6 { technique { pass { vertex_program_ref Deferred_vs { } fragment_program_ref Deferred_ps { } texture_unit { // sampler s0 texture leaf.png } texture_unit { // sampler s1 texture Water02.jpg } } } }  

Deferred_vs.hlsl

struct VS_OUTPUT { float4 pos: POSITION; float2 texCoord0: TEXCOORD0; }; float4x4 worldViewProj; VS_OUTPUT main(float4 Pos: POSITION, float3 normal: NORMAL, float2 texCoord0: TEXCOORD0) { VS_OUTPUT Out; Out.pos = mul(worldViewProj, Pos); Out.texCoord0 = texCoord0; return Out; } 

Deferred_ps.hlsl

sampler Tex0: register(s0); float4 main(float4 texCoord0: TEXCOORD0): COLOR0 { return tex2D(Tex0, texCoord0); }  

你可能感兴趣的:(Reiiden制作笔记H(OGRE Materilas/HLSL 的完整例子))