Presentation is loading. Please wait.

Presentation is loading. Please wait.

Ogre3D Alapok Model betöltés AnyagjellemzőkFényforrásokShaderek.

Similar presentations


Presentation on theme: "Ogre3D Alapok Model betöltés AnyagjellemzőkFényforrásokShaderek."— Presentation transcript:

1 Ogre3D Alapok Model betöltés AnyagjellemzőkFényforrásokShaderek

2 Új C++ project Win32 Console Application

3 Minden konfigurációra érvényes beállítások

4 …/OgreSDK/include/OGRE …/OgreSDK/boost_1_44

5 …/OgreSDK/include/$(ConfigurationName) …/OgreSDK/boost_1_44/lib

6 copy ”$(TargetPath)” ”$(SolutionDir)\bin” $(SolutionDir)\bin

7 Debug és Release konfigurációk OgreMain_d.lib (Debug konfigurációnál) OgreMain.lib (Release konfigurációnál)

8 Debug konfigurációban opcionális (én szoktam….) $(ProjectName)_d.lib

9 Szükséges dll-ek (_d végű dll-ek a debug könyvtárból, a többi a release-ből) másolás bin és media könyvtárak létrehozása Egy fordítást most már meg is próbálhatunk…

10 OgreLab1.cpp #include "stdafx.h" #include "Ogre.h" using namespace Ogre; Root* ogreRoot; SceneManager* sceneManager; Camera* camera; RenderWindow* renderWindow; Light* light; void setupScene() {} void setupListeners() {} int _tmain(int argc, _TCHAR* argv[]) { ogreRoot = new Root("",""); #ifdef _DEBUG ogreRoot->loadPlugin("RenderSystem_Direct3D9_d");#elseogreRoot->loadPlugin("RenderSystem_Direct3D9");#endif return 0; }

11 Próba: fordítás, futtatás

12 Log file ogreRoot = new Root("", "", "Ogre.log");

13 int _tmain(int argc, _TCHAR* argv[]) { ogreRoot = new Root("",""); ogreRoot->loadPlugin("RenderSystem_Direct3D9_d"); RenderSystemList list = ogreRoot->getAvailableRenderers(); ogreRoot->setRenderSystem(list.at(0)); ogreRoot->initialise(false); renderWindow = ogreRoot->createRenderWindow("GameDev Lab First Ogre3D Application", 800, 600, false); sceneManager = ogreRoot->createSceneManager(0, "Default"); ResourceGroupManager::getSingleton().addResourceLocation("media", "FileSystem", "General", false); ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); setupScene(); setupListeners(); ogreRoot->startRendering(); return 0; }

14 void setupScene() { camera = sceneManager->createCamera("Main Camera"); camera->setPosition(0, 20, 100); camera->lookAt(0, 20, 0); camera->setFarClipDistance(1000); camera->setNearClipDistance(0.1); Viewport* viewport = renderWindow->addViewport(camera); renderWindow->setActive(true); } Camera / viewport

15 Próba

16 Exportálás után másolás Új file-ok A szükséges fájlok megtalálhatók a labor honlapján: Kiindulási alap (ogrebasicsbase.zip), exportedmesh.zip

17 void setupScene() { camera = sceneManager->createCamera("Main Camera"); camera->setPosition(0, 20, 100); camera->lookAt(0, 20, 0); camera->setFarClipDistance(1000); camera->setNearClipDistance(0.1); Viewport* viewport = renderWindow->addViewport(camera); renderWindow->setActive(true); SceneNode* rootNode = sceneManager->getRootSceneNode(); SceneNode* archwayNode = rootNode->createChildSceneNode(); Entity* archway = sceneManager->createEntity("archway", "Archway.mesh"); archwayNode->attachObject(archway); }

18 Próba

19 void setupScene() { camera = sceneManager->createCamera("Main Camera"); camera->setPosition(0, 20, 100); camera->lookAt(0,20,0); camera->setFarClipDistance(1000); camera->setNearClipDistance(0.1); Viewport* viewport = renderWindow->addViewport(camera); renderWindow->setActive(true); for(int i = 0; i < 5; i++) { SceneNode* rootNode = sceneManager->getRootSceneNode(); SceneNode* archwayNode = rootNode->createChildSceneNode(); Entity* archway = sceneManager->createEntity("archway_" + StringConverter::toString(i), "Archway.mesh"); archway->setCastShadows(true); archwayNode->setPosition(0,0,-100 + i * 30); archwayNode->attachObject(archway); } Sok boltív!

20 Próba

21 void setupScene() { … light = sceneManager->createLight("pointlight1"); light->setType(Light::LT_POINT); light->setAttenuation(1000,1,0,0); light->setPowerScale(1000); light->setCastShadows(true); light->setPosition(0, 20, -50); sceneManager->setAmbientLight( ColourValue(0.1f,0.1f,0.1f,1.0f)); } Fényforrás! material Archway { receive_shadows on technique { pass { ambient 0.5 0.5 0.5 1 diffuse 0.64 0.64 0.64 1 specular 0.5 0.5 0.500000 1 12.5 emissive 0 0 0 1 texture_unit { texture archwayColorFinal.bmp tex_address_mode wrap filtering trilinear colour_op modulate } Scene.material

22 Próba

23 Animált fényforrás class animationFrameListener : public FrameListener { private: float timeSinceStart; public: animationFrameListener(){timeSinceStart = 0;} bool frameStarted(const FrameEvent& evt) { timeSinceStart += evt.timeSinceLastFrame; float a = Math::Sin(timeSinceStart) * 0.5f + 0.5; light->setPosition(0, 20, -100.0f + 120.0f * a); return true; } }; void setupListeners() { ogreRoot->addFrameListener(new animationFrameListener()); }

24 Próba http://cg.iit.bme.hu/portal/oktatott-targyak/jatekfejlesztes/ogre3d-alapokhttp://cg.iit.bme.hu/portal/oktatott-targyak/jatekfejlesztes/ogre3d-alapok: 1. fázis (GameDevLab1_phase1.zip)

25 Talaj void createGround() { MovablePlane* plane = new MovablePlane("GroundPlane"); plane->d = 0; plane->normal = Vector3::UNIT_Y; MeshManager::getSingleton().createPlane( "GroundPlane", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, *plane, 500,// x-size 500,// y-size 1,// x-segments 1, // y-segments true, 1, 10, // u-tile 10, // v-tile Vector3::UNIT_Z); Entity* planeEnt = sceneManager->createEntity( "GroundPlane", "GroundPlane" ); planeEnt->setMaterialName("Ground"); planeEnt->setCastShadows(false); sceneManager->getRootSceneNode()->createChildSceneNode()->attachObject(planeEnt); } void setupScene() { … renderWindow->setActive(true); createGround(); for(int i = 0; i < 5; i++) //boltívek létrehozása …

26 material Archway { receive_shadows off … } material Ground { receive_shadows on technique { pass { ambient 0.5 0.5 0.5 1 diffuse 1 1 1 1 specular 1 1 1 1 emissive 0 0 0 1 texture_unit { texture ground.jpg } Másolás a media könyvtárba Scene.material

27 Próba

28 Talaj void createGround() { MovablePlane* plane = new MovablePlane("GroundPlane"); plane->d = 0; plane->normal = Vector3::UNIT_Y; MeshManager::getSingleton().createPlane( "GroundPlane", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, *plane, 500,// x-size 500,// y-size 100, // x-segments 100, // y-segments true, 1, 10, // u-tile 10, // v-tile Vector3::UNIT_Z); Entity* planeEnt = sceneManager->createEntity( "GroundPlane", "GroundPlane" ); planeEnt->setMaterialName("Ground"); planeEnt- >setCastShadows(false); sceneManager->getRootSceneNode()->createChildSceneNode()->attachObject(planeEnt); } void setupScene() { … renderWindow->setActive(true); createGround(); for(int i = 0; i < 5; i++) //boltívek létrehozása …

29 Próba Állítsuk majd vissza segment értékeket 1-re!!

30 Árnyékok / égbolt void setupScene() { … sceneManager->setShadowTechnique(SHADOWTYPE_STENCIL_MODULATIVE); sceneManager->setShadowColour(ColourValue(0.5,0.5,0.5)); sceneManager->setSkyBox(true, "Sky", 10, true); } material Sky { technique { pass { lighting off depth_write off cull_hardware none depth_check off texture_unit { cubic_texture stormy.jpg separateUV tex_address_mode clamp } Scene.material Másolás a media könyvtárba (6 db kép)

31 Próba

32 Shaderek / Phong shading vertex_program PhongShadingVS hlsl { source Phong.hlsl entry_point vs target vs_2_0 } fragment_program PhongShadingPS hlsl { source Phong.hlsl entry_point ps target ps_2_0 } Scene.program

33 Shaderek / Phong shading struct VERTEX_IN { float4 position : POSITION; float4 normal: NORMAL; float2 texCoord : TEXCOORD0; }; struct VERTEX_OUT { float4 hPos: POSITION; float3 N : TEXCOORD0; float3 L : TEXCOORD1; float3 V : TEXCOORD2; float2 texCoord : TEXCOORD3; }; VERTEX_OUT vs(VERTEX_IN In) { VERTEX_OUT Out = (VERTEX_OUT) 0; return Out; } float4 ps(VERTEX_OUT In):COLOR0 { return 1; } Phong.hlsl

34 material Phong { technique main { pass main { vertex_program_ref PhongShadingVS { } fragment_program_ref PhongShadingPS { } material Archway : Phong { technique main { pass main { … } material Ground : Phong { technique main { pass main { … }

35 Próba

36 VERTEX_OUT vs(VERTEX_IN In, uniform float4x4 worldViewProj, uniform float4x4 worldView, uniform float4x4 worldViewIT, uniform float4 lightPos) { VERTEX_OUT Out = (VERTEX_OUT) 0; Out.hPos = mul(worldViewProj, In.position); Out.texCoord = In.texCoord; return Out; } float4 ps(VERTEX_OUT In, uniform sampler2D colorTex : register(s0)):COLOR0 { return tex2D(colorTex, In.texCoord); } vertex_program_ref PhongShadingVS { param_named_auto worldViewProj worldviewproj_matrix param_named_auto worldView worldview_matrix param_named_auto worldViewIT inverse_transpose_worldview_matrix param_named_auto lightPos light_position_view_space 0 }

37 Próba

38 VERTEX_OUT vs(VERTEX_IN In, uniform float4x4 worldViewProj, uniform float4x4 worldView, uniform float4x4 worldViewIT, uniform float4 lightPos) { VERTEX_OUT Out = (VERTEX_OUT) 0; Out.hPos = mul(worldViewProj, In.position); Out.texCoord = In.texCoord; Out.V = -mul(worldView, In.position).xyz; Out.L = lightPos.xyz + lightPos.w * Out.V; Out.N = mul(worldViewIT, In.normal).xyz; return Out; } float4 ps(VERTEX_OUT In, uniform sampler2D colorTex : register(s0)):COLOR0 { float3 N = normalize(In.N); float3 L = normalize(In.L); float3 V = normalize(In.V); return max(0,dot(N,L)); return tex2D(colorTex, In.texCoord); }

39 Próba

40 float4 ps(VERTEX_OUT In, uniform sampler2D colorTex : register(s0), uniform float4 amientLightColor, uniform float4 diffuseLightColor, uniform float4 specularLightColor, uniform float4 lightAttenuation, uniform float4 ambientColor, uniform float4 diffuseColor, uniform float4 specularColor, uniform float4 emissiveColor):COLOR0 { float3 N = normalize(In.N); float d = length(In.L); float3 L = In.L / d; float3 V = normalize(In.V); float4 texColor = tex2D(colorTex, In.texCoord); float attenuation = 1.0 / (lightAttenuation.y + lightAttenuation.z * d + lightAttenuation.w * d * d); diffuseLightColor *= attenuation; specularLightColor *= attenuation; float ambient = amientLightColor * ambientColor; float diffuse = max(0,dot(N,L)) * diffuseColor * diffuseLightColor; float3 H = normalize(L + V); float specular = pow(max(0, dot(N,H)), specularColor.w) * float4(specularColor.xyz, 1) * specularLightColor; return texColor * (ambient + diffuse) + specular + emissiveColor; }

41 material Phong { technique { pass { vertex_program_ref PhongShadingVS { param_named_auto worldViewProj worldviewproj_matrix param_named_auto worldView worldview_matrix param_named_auto worldViewIT inverse_transpose_worldview_matrix param_named_auto lightPos light_position_view_space 0 } fragment_program_ref PhongShadingPS { param_named_auto amientLightColor ambient_light_colour param_named_auto diffuseLightColor light_diffuse_colour_power_scaled 0 param_named_auto specularLightColor light_specular_colour_power_scaled 0 param_named_auto lightAttenuation light_attenuation 0 param_named_auto ambientColor surface_ambient_colour param_named_auto diffuseColor surface_diffuse_colour param_named_auto specularColor surface_specular_colour param_named_auto emissiveColor surface_emissive_colour } light->setAttenuation(1000,0,0,1);

42 Próba

43 Vége


Download ppt "Ogre3D Alapok Model betöltés AnyagjellemzőkFényforrásokShaderek."

Similar presentations


Ads by Google