void RenderSystem_Deferred::SetMaterialGBuffer(MaterialPtr pMaterial) { MaterialParameterPtr pParam = pMaterial->GetParameterByName("_DR_G_BUFFER_0"); pParam ? pParam->SetParameterTexture(m_pGBuffer->GetTexture(0)) : (void)0; pParam = pMaterial->GetParameterByName("_DR_G_BUFFER_1"); pParam ? pParam->SetParameterTexture(m_pGBuffer->GetTexture(1)) : (void)0; pParam = pMaterial->GetParameterByName("_DR_G_BUFFER_2"); pParam ? pParam->SetParameterTexture(m_pGBuffer->GetTexture(2)) : (void)0; }
void EngineApp::OnUpdate() { math::Matrix44 view; math::Matrix44 proj; math::Matrix44 t; math::Vector3 eye(20, 20, 20); static float radius = 0; radius += 0.001f; t = math::MatrixRotationAxisY(radius); math::TransformCoord(eye, t); view = math::MatrixLookAtLH(eye, math::Vector3(0, 0, 0), math::Vector3(0, 1, 0)); proj = math::MatrixPerspectiveFovLH(0.25f * 3.14f, 4.0f / 3.0f, 0.01f, 10000); MaterialParameterPtr pParam = m_pMaterial->GetParameterByName("v"); pParam->SetParameterMatrix(view); pParam = m_pMaterial->GetParameterByName("p"); pParam->SetParameterMatrix(proj); pParam = m_pMaterial->GetParameterByName("base"); pParam->SetParameterTexture(m_pTex); /* m_pGraphics->SetRenderTarget(m_pRenderTarget); m_pGraphics->ClearRenderTarget(0, math::Color4(0, 0, 0.7, 1)); m_pGraphics->ClearDepthStencil(CLEAR_ALL, 1.0f, 0); m_pGraphics->SetShaderProgram(m_pProgram); m_pGraphics->DrawIndexed(m_pGeometry, 36, 0, 0);*/ //param = m_pProgram->FindParameterByName("base"); //m_pProgram->SetParameterTexture(param, m_pRenderTarget->GetTexture(0)); m_pGraphics->ClearRenderTarget(0, math::Color4(0.3f, 0.5f, 0.7f, 1)); m_pGraphics->ClearDepthStencil(CLEAR_ALL, 1.0f, 0); int n = m_pMaterial->Begin(); for(int i = 0; i < n; ++i) { m_pMaterial->ApplyPass(i); m_pGraphics->DrawIndexed(m_pGeometry, 36, 0, 0); } m_pMaterial->End(); m_pGraphics->Present(); ShowFPS(); }
bool EngineApp::OnInit() { using namespace ld3d; if(false == m_mod.load_sys("./ogl4graphics_x64.dll")) { return false; } m_pGraphics = m_mod.pSys; GraphicsSetting setting; setting.sysMod = "./ogl4graphics_x64.dll"; setting.backBufferCount = 2; setting.depthStencilFormat = G_FORMAT_D24_UNORM_S8_UINT; setting.frameBufferFormat = G_FORMAT_R8G8B8A8_UNORM; setting.frameBufferHeight = GetClientHeight(); setting.frameBufferWidth = GetClientWidth(); setting.multiSampleCount = 1; setting.multiSampleQuality = 0; setting.windowed = true; setting.wnd = GetWnd(); if(false == m_pGraphics->Initialize(setting)) { return false; } m_pGeometry = CreateCube(10); m_pTex = m_pGraphics->CreateTextureFromFile("./assets/standard/texture/array.dds", false); DepthStencilBufferPtr pDS = m_pGraphics->CreateDepthStencilBuffer(G_FORMAT_D32_FLOAT, 800, 600); TexturePtr pTex = m_pGraphics->CreateTexture2D(G_FORMAT_R8G8B8A8_UNORM, 800, 600, 1, false); m_pRenderTarget = m_pGraphics->CreateRenderTexture(); m_pRenderTarget->AttachTexture(pTex); m_pRenderTarget->AttachDepthStencilBuffer(pDS); material_script::Compiler cl; m_pMaterial = cl.CompileFromFile(m_pGraphics, "./assets/standard/material/1.material"); MaterialParameterPtr pParam = m_pMaterial->GetParameterByName("base"); pParam->SetParameterTexture(m_pTex); return true; }
void SkyLight::RenderLight(RenderManagerPtr pRenderer) { if(GetEnabled() == false) { return; } const math::Matrix44& view = pRenderer->GetViewMatrix(); const math::Matrix44& proj = pRenderer->GetProjMatrix(); pRenderer->SetMatrixBlock(m_pMaterial, math::MatrixIdentity()); const math::Matrix44& tm = GetWorldTM(); math::Vector3 d = tm.GetRow3(2); struct DirLightParam { math::Vector3 d; float i; math::Vector3 c; }; DirLightParam l; l.d = d; l.i = GetIntensity(); const math::Color4& diffClr = GetDiffuseColor(); l.c = math::Vector3(diffClr.r, diffClr.g, diffClr.b); MaterialParameterPtr pParam = m_pMaterial->GetParameterByName("light"); pParam->SetParameterBlock(&l, sizeof(DirLightParam)); pRenderer->SetGBuffer(m_pMaterial); if(m_bCastShadow) { pParam = m_pMaterial->GetParameterByName("shadow_map"); pParam->SetParameterTexture(m_pShadowMap->GetTexture(0)); pParam = m_pMaterial->GetParameterByName("light_tm"); pParam->SetParameterMatrix(m_lightTM); } pRenderer->DrawFullScreenQuad(m_pMaterial); }
bool VoxelWorldMaterialManager::Initialize(RenderManagerPtr pRenderManager) { MaterialParameterPtr pParam; TexturePtr pTex; MaterialPtr pMat; // soil pTex = pRenderManager->CreateTextureFromFile("assets/voxel/texture/dirt.dds"); pMat = pRenderManager->CreateMaterialFromFile("assets/voxel/material/voxel_world.material"); pParam = pMat->GetParameterByName("diffuse_map"); pParam->SetParameterTexture(pTex); m_materials[VT_SOIL].pTex = pTex; m_materials[VT_SOIL].pMaterial = pMat; // rock pTex = pRenderManager->CreateTextureFromFile("assets/voxel/texture/rock.dds"); pMat = pRenderManager->CreateMaterialFromFile("assets/voxel/material/voxel_world.material"); pParam = pMat->GetParameterByName("diffuse_map"); pParam->SetParameterTexture(pTex); m_materials[VT_STONE].pTex = pTex; m_materials[VT_STONE].pMaterial = pMat; // iron pTex = pRenderManager->CreateTextureFromFile("assets/voxel/texture/rock.dds"); pMat = pRenderManager->CreateMaterialFromFile("assets/voxel/material/voxel_world.material"); pParam = pMat->GetParameterByName("diffuse_map"); pParam->SetParameterTexture(pTex); m_materials[VT_IRON].pTex = pTex; m_materials[VT_IRON].pMaterial = pMat; // silver pTex = pRenderManager->CreateTextureFromFile("assets/voxel/texture/rock.dds"); pMat = pRenderManager->CreateMaterialFromFile("assets/voxel/material/voxel_world.material"); pParam = pMat->GetParameterByName("diffuse_map"); pParam->SetParameterTexture(pTex); m_materials[VT_SILVER].pTex = pTex; m_materials[VT_SILVER].pMaterial = pMat; // gold pTex = pRenderManager->CreateTextureFromFile("assets/voxel/texture/rock.dds"); pMat = pRenderManager->CreateMaterialFromFile("assets/voxel/material/voxel_world.material"); pParam = pMat->GetParameterByName("diffuse_map"); pParam->SetParameterTexture(pTex); m_materials[VT_GOLD].pTex = pTex; m_materials[VT_GOLD].pMaterial = pMat; // water pTex = pRenderManager->CreateTextureFromFile("assets/voxel/texture/dirt.dds"); pMat = pRenderManager->CreateMaterialFromFile("assets/voxel/material/voxel_world.material"); pParam = pMat->GetParameterByName("diffuse_map"); pParam->SetParameterTexture(pTex); m_materials[VT_WATER].pTex = pTex; m_materials[VT_WATER].pMaterial = pMat; // grass pTex = pRenderManager->CreateTextureFromFile("assets/voxel/texture/dirt.dds"); pMat = pRenderManager->CreateMaterialFromFile("assets/voxel/material/voxel_world.material"); pParam = pMat->GetParameterByName("diffuse_map"); pParam->SetParameterTexture(pTex); m_materials[VT_GRASS].pTex = pTex; m_materials[VT_GRASS].pMaterial = pMat; // sand pTex = pRenderManager->CreateTextureFromFile("assets/voxel/texture/sand.dds"); pMat = pRenderManager->CreateMaterialFromFile("assets/voxel/material/voxel_world.material"); pParam = pMat->GetParameterByName("diffuse_map"); pParam->SetParameterTexture(pTex); m_materials[VT_BEACH].pTex = pTex; m_materials[VT_BEACH].pMaterial = pMat; // tree leaf pTex = pRenderManager->CreateTextureFromFile("assets/voxel/texture/sand.dds"); pMat = pRenderManager->CreateMaterialFromFile("assets/voxel/material/voxel_world.material"); pParam = pMat->GetParameterByName("diffuse_map"); pParam->SetParameterTexture(pTex); m_materials[VT_TREE_LEAF].pTex = pTex; m_materials[VT_TREE_LEAF].pMaterial = pMat; // tree trunk pTex = pRenderManager->CreateTextureFromFile("assets/voxel/texture/sand.dds"); pMat = pRenderManager->CreateMaterialFromFile("assets/voxel/material/voxel_world.material"); pParam = pMat->GetParameterByName("diffuse_map"); pParam->SetParameterTexture(pTex); m_materials[VT_TREE_TRUNK].pTex = pTex; m_materials[VT_TREE_TRUNK].pMaterial = pMat; return true; }
void RenderSystem_Deferred::SetMaterialABuffer(MaterialPtr pMaterial) { MaterialParameterPtr pParam = pMaterial->GetParameterByName("_DR_A_BUFFER"); pParam ? pParam->SetParameterTexture(m_pABuffer->GetTexture(0)) : (void)0 ; }
bool Impl_SkyBox::OnAttach() { m_pRD = m_pManager->alloc_object<RenderData>(); VertexLayout layout; layout.AddAttribute(G_FORMAT_R32G32B32_FLOAT); float size = 1.0f; int nVerts = 36; math::Vector3 verts[] = { math::Vector3(-size, size, -size), math::Vector3(size, -size, -size), math::Vector3(size, size, -size), math::Vector3(-size, size, -size), math::Vector3(-size, -size, -size), math::Vector3(size, -size, -size), math::Vector3(-size, size, size), math::Vector3(size, size, size), math::Vector3(size, -size, size), math::Vector3(-size, size, size), math::Vector3(size, -size, size), math::Vector3(-size, -size, size), math::Vector3(-size, size, size), math::Vector3(size, size, -size), math::Vector3(size, size, size), math::Vector3(-size, size, size), math::Vector3(-size, size, -size), math::Vector3(size, size, -size), math::Vector3(-size, -size, size), math::Vector3(size, -size, size), math::Vector3(size, -size, -size), math::Vector3(-size, -size, size), math::Vector3(size, -size, -size), math::Vector3(-size, -size, -size), math::Vector3(-size, size, size), math::Vector3(-size, -size, -size), math::Vector3(-size, size, -size), math::Vector3(-size, size, size), math::Vector3(-size, -size, size), math::Vector3(-size, -size, -size), math::Vector3(size, size, size), math::Vector3(size, size, -size), math::Vector3(size, -size, -size), math::Vector3(size, size, size), math::Vector3(size, -size, -size), math::Vector3(size, -size, size), }; m_pRD->geometry = m_pManager->GetRenderManager()->CreateGeometryData(); m_pRD->geometry->BeginGeometry(PT_TRIANGLE_LIST); { m_pRD->geometry->AllocVertexBuffer(sizeof(math::Vector3) * 36, verts, false, layout); } m_pRD->geometry->EndGeometry(); m_pRD->base_vertex = 0; m_pRD->index_count = 0; m_pRD->start_index = 0; m_pRD->vertex_count = 36; m_pRD->world_matrix.MakeIdentity(); m_pRD->material = m_pManager->GetRenderManager()->CreateMaterialFromFile("./assets/standard/material/skybox.material"); m_hFrustumCull = m_pManager->AddEventHandler(EV_FRUSTUM_CULL, boost::bind(&Impl_SkyBox::on_event_frustum_cull, this, _1)); m_pTex = m_pManager->GetRenderManager()->CreateTextureFromFile("./assets/standard/texture/001.dds"); MaterialParameterPtr pParam = m_pRD->material->GetParameterByName("sky_map"); pParam->SetParameterTexture(m_pTex); m_pWorldPos = m_pRD->material->GetParameterByName("world_pos"); return true; }