Ogre Tessellation 使用說明

  • 1123
  • 0
  • 2013-03-08

摘要:Ogre Tessellation 使用說明

這個文章屬於公司內部使用, 所以一般人用處應該不大

相關檔案放在

\\vrfish2\公司-程式\Richard\Tessellation

測試程式碼


	Ogre::MeshPtr pFurcaMesh = Ogre::MeshManager::getSingleton().load("Furcacauda.mesh","Vladivostok");
	pFurcaMesh->buildTangentVectors(Ogre::VES_TANGENT,0,0,true,false,true);
	FurcacaudaEnt = mSceneMgr->createEntity(pFurcaMesh);

	FurcaNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(0,0,-50.0f));
	FurcaNode->attachObject(FurcacaudaEnt);	

	Ogre::AnimationState* pSwim=FurcacaudaEnt->getAnimationState("swim");
	pSwim->setEnabled(true);

	furcaMaterial = FurcacaudaEnt->getSubEntity(0)->getMaterial();

 

結論

 

HLSL shader

 

不要有沒人用到的cbuffer

Tessellation會用到VS, HS, ConstantHS, DS, PS 其中VS和PS的工作和以前的bump Shader很像

HS, constantHS, 大概是制式的寫法, 一般不太會去更動它(除非你要寫將邊緣平滑的程式)

DS裏使用了一張displacement map 


vWorldPos += vNormal * (vNormalHeight.r-0.5);

但是這裏注意一點 Displacement Map是一個灰階圖, 你可以用rgb傳進來(因為r=g=b,所以這裏使用.r) 或是放在某個圖的alpha(w)裏

0.5要看美術製作這個圖以什麼為基準, 也可能是減1或是減0

應該還可以再乘上一個高度值 vWorldPos += vNormal * (vNormalHeight.r-0.5) * scale;
 

Vertex Shader的光源這裏是用方向光寫死, 而且注意方向和打光方向剛好相反


param_named g_LightDirection 		float4 0 1 0 0

OgreTesselation/TesselationHullProgramHLSL有個參數叫做


param_named g_vTessellationFactor   float4 10 10 10 10

這個參數可以控制Tessellation的精細程度, 這邊是用default param 寫死, 但是如果要用程式動態更改, OGRE好像還沒有支援

因為只有看到

tessMaterial->getBestTechnique()->getPass(0)->getVertexProgramParameters();

tessMaterial->getBestTechnique()->getPass(0)->getFragmentProgramParameters();

沒有

tessMaterial->getBestTechnique()->getPass(0)->getHullProgramParameters();

tessMaterial->getBestTechnique()->getPass(0)->getDomainProgramParameters();

所以要動態更改hull shader或 domain shader參數, 可能要使用GpuProgramManager::getSingleton().getSharedParameters("mySharedParams");

 

整合注解

 

Mesh讀入後記得要

pFurcaMesh->buildTangentVectors(Ogre::VES_TANGENT,0,0,true,false,true);

最後一個參數會在Tangent結構中float4最後一個值w放入+1 或-1 可以幫Vertex Shader算出不同方向的光

 

DX11使用注意事項

 

如果你是第一次在Config Dialog中選擇Direct3D 11 Rendering Subsystem

有一個選項要注意 Information Queue Exceptions Bottom Level 記得改成 No information queue excepstions不然Device create 應該會失敗

要使用Displacement Map

OgreD3D11RenderSystem.cpp 記得加入DSSetSampler及DSSetShaderResources (參考實戰Ogre Tessellation)

也許更新版的Ogre會修正這一部份也不一定

 

 

Rz

 

 

 

  Rz     should work (hard)