void RenderAmbientLight() { glEnable(GL_BLEND); glBlendEquation(GL_FUNC_ADD); glBlendFunc(GL_ONE, GL_ONE); m_LightingTech.Enable(); m_pointLight.AmbientIntensity = 0.2f; m_pointLight.DiffuseIntensity = 0.0f; m_LightingTech.SetPointLights(1, &m_pointLight); Pipeline p; p.SetPerspectiveProj(m_persProjInfo); p.SetCamera(m_pGameCamera->GetPos(), m_pGameCamera->GetTarget(), m_pGameCamera->GetUp()); m_boxOrientation.m_rotation = Vector3f(0, m_scale, 0); p.Orient(m_boxOrientation); m_LightingTech.SetWVP(p.GetWVPTrans()); m_LightingTech.SetWorldMatrix(p.GetWorldTrans()); m_box.Render(); p.Orient(m_quadOrientation); m_LightingTech.SetWVP(p.GetWVPTrans()); m_LightingTech.SetWorldMatrix(p.GetWorldTrans()); m_pGroundTex->Bind(COLOR_TEXTURE_UNIT); m_quad.Render(); glDisable(GL_BLEND); }
virtual void RenderSceneCB() { m_scale += 0.01f; m_pGameCamera->OnRender(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); Pipeline p; p.WorldPos(0.0f, 0.0f, 10.0f); p.SetCamera(m_pGameCamera->GetPos(), m_pGameCamera->GetTarget(), m_pGameCamera->GetUp()); p.SetPerspectiveProj(m_persProjInfo); m_pEffect->SetWVP(p.GetWVPTrans()); m_pEffect->SetWorldMatrix(p.GetWorldTrans()); m_pEffect->SetDirectionalLight(m_directionalLight); m_pEffect->SetEyeWorldPos(m_pGameCamera->GetPos()); m_pEffect->SetMatSpecularIntensity(0.0f); m_pEffect->SetMatSpecularPower(0); m_pEffect->SetWVP(p.GetWVPTrans()); m_pMesh->Render(); glutSwapBuffers(); }
virtual void RenderSceneCB() { m_scale += 0.01f; m_pGameCamera->OnRender(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); m_pEffect->SetEyeWorldPos(m_pGameCamera->GetPos()); Pipeline p; p.SetCamera(m_pGameCamera->GetPos(), m_pGameCamera->GetTarget(), m_pGameCamera->GetUp()); p.Rotate(0.0f, m_scale, 0.0f); p.SetPerspectiveProj(m_persProjInfo); p.Scale(0.1f, 0.1f, 0.1f); p.WorldPos(-6.0f, -2.0f, 10.0f); m_pEffect->SetWVP(p.GetWVPTrans()); m_pEffect->SetWorldMatrix(p.GetWorldTrans()); m_pMesh1->Render(); p.Scale(0.01f, 0.01f, 0.01f); p.WorldPos(6.0f, -2.0f, 10.0f); m_pEffect->SetWVP(p.GetWVPTrans()); m_pEffect->SetWorldMatrix(p.GetWorldTrans()); m_pMesh2->Render(); p.Scale(0.04f, 0.04f, 0.04f); p.WorldPos(0.0f, 6.0f, 10.0f); m_pEffect->SetWVP(p.GetWVPTrans()); m_pEffect->SetWorldMatrix(p.GetWorldTrans()); m_pMesh3->Render(); glutSwapBuffers(); }
virtual void RenderPass() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); m_pLightingEffect->Enable(); m_shadowMapFBO.BindForReading(GL_TEXTURE1); Pipeline p; p.SetPerspectiveProj(60.0f, WINDOW_WIDTH, WINDOW_HEIGHT, 1.0f, 50.0f); p.Scale(10.0f, 10.0f, 10.0f); p.WorldPos(0.0f, 0.0f, 1.0f); p.Rotate(90.0f, 0.0f, 0.0f); p.SetCamera(m_pGameCamera->GetPos(), m_pGameCamera->GetTarget(), m_pGameCamera->GetUp()); m_pLightingEffect->SetWVP(p.GetWVPTrans()); m_pLightingEffect->SetWorldMatrix(p.GetWorldTrans()); p.SetCamera(m_spotLight.Position, m_spotLight.Direction, Vector3f(0.0f, 1.0f, 0.0f)); m_pLightingEffect->SetLightWVP(p.GetWVPTrans()); m_pLightingEffect->SetEyeWorldPos(m_pGameCamera->GetPos()); m_pGroundTex->Bind(GL_TEXTURE0); m_pQuad->Render(); p.Scale(0.1f, 0.1f, 0.1f); p.Rotate(0.0f, m_scale, 0.0f); p.WorldPos(0.0f, 0.0f, 3.0f); p.SetCamera(m_pGameCamera->GetPos(), m_pGameCamera->GetTarget(), m_pGameCamera->GetUp()); m_pLightingEffect->SetWVP(p.GetWVPTrans()); m_pLightingEffect->SetWorldMatrix(p.GetWorldTrans()); p.SetCamera(m_spotLight.Position, m_spotLight.Direction, Vector3f(0.0f, 1.0f, 0.0f)); m_pLightingEffect->SetLightWVP(p.GetWVPTrans()); m_pMesh->Render(); }
void RenderShadowedScene() { glDrawBuffer(GL_BACK); // Draw only if the corresponding stencil value is zero glStencilFunc(GL_EQUAL, 0x0, 0xFF); // prevent update to the stencil buffer glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); m_LightingTech.Enable(); m_pointLight.AmbientIntensity = 0.0f; m_pointLight.DiffuseIntensity = 0.8f; m_LightingTech.SetPointLights(1, &m_pointLight); Pipeline p; p.SetPerspectiveProj(m_persProjInfo); p.SetCamera(m_pGameCamera->GetPos(), m_pGameCamera->GetTarget(), m_pGameCamera->GetUp()); m_boxOrientation.m_rotation = Vector3f(0, m_scale, 0); p.Orient(m_boxOrientation); m_LightingTech.SetWVP(p.GetWVPTrans()); m_LightingTech.SetWorldMatrix(p.GetWorldTrans()); m_box.Render(); p.Orient(m_quadOrientation); m_LightingTech.SetWVP(p.GetWVPTrans()); m_LightingTech.SetWorldMatrix(p.GetWorldTrans()); m_pGroundTex->Bind(COLOR_TEXTURE_UNIT); m_quad.Render(); }
void RenderPhase() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); Pipeline p; p.Scale(0.1f, 0.1f, 0.1f); p.Rotate(0.0f, 90.0f, 0.0f); p.SetCamera(m_pGameCamera->GetPos(), m_pGameCamera->GetTarget(), m_pGameCamera->GetUp()); p.SetPerspectiveProj(m_persProjInfo); // If the left mouse button is clicked check if it hit a triangle // and color it red if (m_leftMouseButton.IsPressed) { PickingTexture::PixelInfo Pixel = m_pickingTexture.ReadPixel(m_leftMouseButton.x, WINDOW_HEIGHT - m_leftMouseButton.y - 1); if (Pixel.PrimID != 0) { m_simpleColorEffect.Enable(); p.WorldPos(m_worldPos[Pixel.ObjectID]); m_simpleColorEffect.SetWVP(p.GetWVPTrans()); // Must compensate for the decrement in the FS! m_pMesh->Render(Pixel.DrawID, Pixel.PrimID - 1); } } // render the objects as usual m_lightingEffect.Enable(); m_lightingEffect.SetEyeWorldPos(m_pGameCamera->GetPos()); for (unsigned int i = 0 ; i < ARRAY_SIZE_IN_ELEMENTS(m_worldPos) ; i++) { p.WorldPos(m_worldPos[i]); m_lightingEffect.SetWVP(p.GetWVPTrans()); m_lightingEffect.SetWorldMatrix(p.GetWorldTrans()); m_pMesh->Render(NULL); } }
void ShadowMapPass() { glCullFace(GL_FRONT); m_shadowMapEffect.Enable(); PersProjInfo ProjInfo; ProjInfo.FOV = 90.0f; ProjInfo.Height = WINDOW_HEIGHT; ProjInfo.Width = WINDOW_WIDTH; ProjInfo.zNear = 1.0f; ProjInfo.zFar = 100.0f; Pipeline p; p.SetPerspectiveProj(m_persProjInfo); glClearColor(FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX); for (uint i = 0 ; i < NUM_OF_LAYERS ; i++) { m_shadowMapFBO.BindForWriting(gCameraDirections[i].CubemapFace); glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); p.SetCamera(m_pointLight.Position, gCameraDirections[i].Target, gCameraDirections[i].Up); p.Orient(m_mesh1Orientation); m_shadowMapEffect.SetWorld(p.GetWorldTrans()); m_shadowMapEffect.SetWVP(p.GetWVPTrans()); m_mesh.Render(); p.Orient(m_mesh2Orientation); m_shadowMapEffect.SetWorld(p.GetWorldTrans()); m_shadowMapEffect.SetWVP(p.GetWVPTrans()); m_mesh.Render(); } }
void RenderShadowVolIntoStencil() { glDepthMask(GL_FALSE); glEnable(GL_DEPTH_CLAMP); glDisable(GL_CULL_FACE); // We need the stencil test to be enabled but we want it // to succeed always. Only the depth test matters. glStencilFunc(GL_ALWAYS, 0, 0xff); glStencilOpSeparate(GL_BACK, GL_KEEP, GL_INCR_WRAP, GL_KEEP); glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_DECR_WRAP, GL_KEEP); m_ShadowVolTech.Enable(); m_ShadowVolTech.SetLightPos(m_pointLight.Position); // Render the occluder Pipeline p; p.SetCamera(m_pGameCamera->GetPos(), m_pGameCamera->GetTarget(), m_pGameCamera->GetUp()); p.SetPerspectiveProj(m_persProjInfo); m_boxOrientation.m_rotation = Vector3f(0, m_scale, 0); p.Orient(m_boxOrientation); m_ShadowVolTech.SetWVP(p.GetWVPTrans()); m_box.Render(); // Restore local stuff glDisable(GL_DEPTH_CLAMP); glEnable(GL_CULL_FACE); }
static void RenderSceneCB() { pGameCamera->OnRender(); glClear(GL_COLOR_BUFFER_BIT); static GLfloat scale = 0.0f; scale += 0.1f; Pipeline p; p.Rotate(0.0f, scale, 0.0f); p.WorldPos(0.0f, 0.0f, 3.0f); p.SetCamera(*pGameCamera); p.SetPerspectiveProj(gPersProjInfo); glUniformMatrix4fv(gWVPLocation, 1, GL_TRUE, (const GLfloat*)p.GetWVPTrans()); glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, VBO); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO); glDrawElements(GL_TRIANGLES, 12, GL_UNSIGNED_INT, 0); glDisableVertexAttribArray(0); glutSwapBuffers(); }
void Tutorial18::RenderSceneCB() { m_pGameCamera->OnRender(); glClear(GL_COLOR_BUFFER_BIT); m_scale += 0.1f; Pipeline p; p.Rotate(0.0f, m_scale, 0.0f); p.WorldPos(0.0f, 0.0f, 1.0f); p.SetCamera(m_pGameCamera->GetPos(), m_pGameCamera->GetTarget(), m_pGameCamera->GetUp()); p.SetPerspectiveProj(m_persProjInfo); m_pEffect->SetWVP(p.GetWVPTrans()); const Matrix4f& WorldTransformation = p.GetWorldTrans(); m_pEffect->SetWorldMatrix(WorldTransformation); m_pEffect->SetDirectionalLight(m_directionalLight); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glEnableVertexAttribArray(2); glBindBuffer(GL_ARRAY_BUFFER, m_VBO); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid*)12); glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid*)20); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_IBO); m_pTexture->Bind(GL_TEXTURE0); glDrawElements(GL_TRIANGLES, 12, GL_UNSIGNED_INT, 0); glDisableVertexAttribArray(0); glDisableVertexAttribArray(1); glDisableVertexAttribArray(2); glutSwapBuffers(); }
void DSStencilPass(unsigned int PointLightIndex) { m_nullTech.Enable(); // Disable color/depth write and enable stencil m_gbuffer.BindForStencilPass(); glEnable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glClear(GL_STENCIL_BUFFER_BIT); // We need the stencil test to be enabled but we want it // to succeed always. Only the depth test matters. glStencilFunc(GL_ALWAYS, 0, 0); glStencilOpSeparate(GL_BACK, GL_KEEP, GL_INCR_WRAP, GL_KEEP); glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_DECR_WRAP, GL_KEEP); Pipeline p; p.WorldPos(m_pointLight[PointLightIndex].Position); float BBoxScale = CalcPointLightBSphere(m_pointLight[PointLightIndex]); p.Scale(BBoxScale, BBoxScale, BBoxScale); p.SetCamera(m_pGameCamera->GetPos(), m_pGameCamera->GetTarget(), m_pGameCamera->GetUp()); p.SetPerspectiveProj(m_persProjInfo); m_nullTech.SetWVP(p.GetWVPTrans()); m_bsphere.Render(); }
void DSPointLightPass(unsigned int PointLightIndex) { m_gbuffer.BindForLightPass(); m_DSPointLightPassTech.Enable(); m_DSPointLightPassTech.SetEyeWorldPos(m_pGameCamera->GetPos()); glStencilFunc(GL_NOTEQUAL, 0, 0xFF); glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendEquation(GL_FUNC_ADD); glBlendFunc(GL_ONE, GL_ONE); glEnable(GL_CULL_FACE); glCullFace(GL_FRONT); Pipeline p; p.WorldPos(m_pointLight[PointLightIndex].Position); float BBoxScale = CalcPointLightBSphere(m_pointLight[PointLightIndex]); p.Scale(BBoxScale, BBoxScale, BBoxScale); p.SetCamera(m_pGameCamera->GetPos(), m_pGameCamera->GetTarget(), m_pGameCamera->GetUp()); p.SetPerspectiveProj(m_persProjInfo); m_DSPointLightPassTech.SetWVP(p.GetWVPTrans()); m_DSPointLightPassTech.SetPointLight(m_pointLight[PointLightIndex]); m_bsphere.Render(); glCullFace(GL_BACK); glDisable(GL_BLEND); }
bool Skybox::Render() { mSkyboxTech->Enable(); GLint OldCullFaceMode; glGetIntegerv(GL_CULL_FACE_MODE, &OldCullFaceMode); GLint OldDepthFuncMode; glGetIntegerv(GL_DEPTH_FUNC, &OldDepthFuncMode); glCullFace(GL_FRONT); glDepthFunc(GL_LEQUAL); auto camera = mCamera.lock(); Pipeline pipeline; // pipeline.SetPerspective(glm::transpose(camera->GetGLMPerspMatrix())); pipeline.SetPerspective(camera->GetPerspMatrix()); pipeline.SetCamera(camera->GetPos(), camera->Forward(), camera->Up()); const glm::mat4 transform = glm::transpose(GetTransform()); mSkyboxTech->SetTextureUnit(0); mSkyboxTech->SetWVP(pipeline.GetWVPTrans(transform)); mCubemapTexture->Bind(mSkyboxTech->GetProgram()); mSkyboxMesh->Render(mSkyboxTech->GetProgram()); mCubemapTexture->Unbind(); glCullFace(OldCullFaceMode); glDepthFunc(OldDepthFuncMode); return true; }
virtual void RenderSceneCB() { long long TimeNowMillis = GetCurrentTimeMillis(); assert(TimeNowMillis >= m_currentTimeMillis); unsigned int DeltaTimeMillis = (unsigned int)(TimeNowMillis - m_currentTimeMillis); m_currentTimeMillis = TimeNowMillis; m_pGameCamera->OnRender(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); m_pLightingTechnique->Enable(); m_pTexture->Bind(COLOR_TEXTURE_UNIT); m_pNormalMap->Bind(NORMAL_TEXTURE_UNIT); Pipeline p; p.Scale(20.0f, 20.0f, 1.0f); p.Rotate(90.0f, 0.0, 0.0f); p.SetCamera(m_pGameCamera->GetPos(), m_pGameCamera->GetTarget(), m_pGameCamera->GetUp()); p.SetPerspectiveProj(m_persProjInfo); m_pLightingTechnique->SetWVP(p.GetWVPTrans()); m_pLightingTechnique->SetWorldMatrix(p.GetWorldTrans()); m_pGround->Render(); m_particleSystem.Render(DeltaTimeMillis, p.GetVPTrans(), m_pGameCamera->GetPos()); glutSwapBuffers(); }
void SkyBox::Render() { m_pSkyboxTechnique->Enable(); GLint OldCullFaceMode; glGetIntegerv(GL_CULL_FACE_MODE, &OldCullFaceMode); GLint OldDepthFuncMode; glGetIntegerv(GL_DEPTH_FUNC, &OldDepthFuncMode); glCullFace(GL_FRONT); glDepthFunc(GL_LEQUAL); Pipeline p; p.Scale(20.0f, 20.0f, 20.0f); p.Rotate(0.0f, 0.0f, 0.0f); p.WorldPos(m_pCamera->GetPos().x, m_pCamera->GetPos().y, m_pCamera->GetPos().z); p.SetCamera(m_pCamera->GetPos(), m_pCamera->GetTarget(), m_pCamera->GetUp()); p.SetPerspectiveProj(m_persProjInfo); m_pSkyboxTechnique->SetWVP(p.GetWVPTrans()); m_pCubemapTex->Bind(GL_TEXTURE0); m_pMesh->Render(); glCullFace(OldCullFaceMode); glDepthFunc(OldDepthFuncMode); }
virtual void RenderSceneCB() { m_pGameCamera->OnRender(); m_scale += 0.01f; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); m_pLightingTechnique->Enable(); Pipeline p; p.Rotate(0.0f, m_scale, 0.0f); p.WorldPos(0.0f, 0.0f, 3.0f); p.SetCamera(m_pGameCamera->GetPos(), m_pGameCamera->GetTarget(), m_pGameCamera->GetUp()); p.SetPerspectiveProj(m_persProjInfo); m_pTexture->Bind(COLOR_TEXTURE_UNIT); if (m_bumpMapEnabled) { m_pNormalMap->Bind(NORMAL_TEXTURE_UNIT); } else { m_pTrivialNormalMap->Bind(NORMAL_TEXTURE_UNIT); } m_pLightingTechnique->SetWVP(p.GetWVPTrans()); m_pLightingTechnique->SetWorldMatrix(p.GetWorldTrans()); m_pSphereMesh->Render(); glutSwapBuffers(); }
void DSGeometryPass() { m_DSGeomPassTech.Enable(); m_gbuffer.BindForWriting(); // Only the geometry pass updates the depth buffer glDepthMask(GL_TRUE); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glDisable(GL_BLEND); Pipeline p; p.SetCamera(m_pGameCamera->GetPos(), m_pGameCamera->GetTarget(), m_pGameCamera->GetUp()); p.SetPerspectiveProj(m_persProjInfo); p.Rotate(0.0f, m_scale, 0.0f); for (unsigned int i = 0 ; i < ARRAY_SIZE_IN_ELEMENTS(m_boxPositions) ; i++) { p.WorldPos(m_boxPositions[i]); m_DSGeomPassTech.SetWVP(p.GetWVPTrans()); m_DSGeomPassTech.SetWorldMatrix(p.GetWorldTrans()); m_box.Render(); } // When we get here the depth buffer is already populated and the stencil pass // depends on it, but it does not write to it. glDepthMask(GL_FALSE); glDisable(GL_DEPTH_TEST); }
virtual void RenderSceneCB() { m_pGameCamera->OnRender(); glClear(GL_COLOR_BUFFER_BIT); m_scale += 0.01f; SpotLight sl[2]; sl[0].DiffuseIntensity = 15.0f; sl[0].Color = Vector3f(1.0f, 1.0f, 0.7f); sl[0].Position = Vector3f(-0.0f, -1.9f, -0.0f); sl[0].Direction = Vector3f(sinf(m_scale), 0.0f, cosf(m_scale)); sl[0].Attenuation.Linear = 0.1f; sl[0].Cutoff = 20.0f; sl[1].DiffuseIntensity = 5.0f; sl[1].Color = Vector3f(0.0f, 1.0f, 1.0f); sl[1].Position = m_pGameCamera->GetPos(); sl[1].Direction = m_pGameCamera->GetTarget(); sl[1].Attenuation.Linear = 0.1f; sl[1].Cutoff = 10.0f; m_pEffect->SetSpotLights(2, sl); Pipeline p; p.Rotate(0.0f, 0.0f, 0.0f); p.WorldPos(0.0f, 0.0f, 1.0f); p.SetCamera(m_pGameCamera->GetPos(), m_pGameCamera->GetTarget(), m_pGameCamera->GetUp()); p.SetPerspectiveProj(60.0f, WINDOW_WIDTH, WINDOW_HEIGHT, 0.1f, 100.0f); m_pEffect->SetWVP(p.GetWVPTrans()); const Matrix4f& WorldTransformation = p.GetWorldTrans(); m_pEffect->SetWorldMatrix(WorldTransformation); m_pEffect->SetDirectionalLight(m_directionalLight); m_pEffect->SetEyeWorldPos(m_pGameCamera->GetPos()); m_pEffect->SetMatSpecularIntensity(1.0f); m_pEffect->SetMatSpecularPower(32); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glEnableVertexAttribArray(2); glBindBuffer(GL_ARRAY_BUFFER, m_VBO); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid*)12); glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid*)20); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_IBO); m_pTexture->Bind(GL_TEXTURE0); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); glDisableVertexAttribArray(0); glDisableVertexAttribArray(1); glDisableVertexAttribArray(2); glutSwapBuffers(); }
void RenderSceneIntoDepth() { glDrawBuffer(GL_NONE); m_nullTech.Enable(); Pipeline p; p.SetCamera(m_pGameCamera->GetPos(), m_pGameCamera->GetTarget(), m_pGameCamera->GetUp()); p.SetPerspectiveProj(m_persProjInfo); m_boxOrientation.m_rotation = Vector3f(0, m_scale, 0); p.Orient(m_boxOrientation); m_nullTech.SetWVP(p.GetWVPTrans()); m_box.Render(); p.Orient(m_quadOrientation); m_nullTech.SetWVP(p.GetWVPTrans()); m_quad.Render(); }
void Chunks::Render(Pipeline p, StaticNullShader* nullShader) { nullShader->Enable(); nullShader->SetWVP(p.GetWVPTrans()); for (int i = 0; i < VIEW_DISTANCE / CHUNK_SIZE_X * 2; i++) { for (int j = 0; j < VIEW_DISTANCE / CHUNK_SIZE_Z * 2; ++j) { Get(i,j)->Render(); } } }
void RenderPass() { glCullFace(GL_BACK); glBindFramebuffer(GL_FRAMEBUFFER, 0); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); m_lightingEffect.Enable(); m_shadowMapFBO.BindForReading(SHADOW_TEXTURE_UNIT); m_lightingEffect.SetEyeWorldPos(m_pGameCamera->GetPos()); Pipeline p; p.SetPerspectiveProj(m_persProjInfo); p.SetCamera(*m_pGameCamera); // Render the quads m_pGroundTex->Bind(COLOR_TEXTURE_UNIT); p.Orient(m_quad1Orientation); m_lightingEffect.SetWorldMatrix(p.GetWorldTrans()); m_lightingEffect.SetWVP(p.GetWVPTrans()); m_quad.Render(); p.Orient(m_quad2Orientation); m_lightingEffect.SetWorldMatrix(p.GetWorldTrans()); m_lightingEffect.SetWVP(p.GetWVPTrans()); m_quad.Render(); // Render the meshes p.Orient(m_mesh1Orientation); m_lightingEffect.SetWorldMatrix(p.GetWorldTrans()); m_lightingEffect.SetWVP(p.GetWVPTrans()); m_mesh.Render(); p.Orient(m_mesh2Orientation); m_lightingEffect.SetWorldMatrix(p.GetWorldTrans()); m_lightingEffect.SetWVP(p.GetWVPTrans()); m_mesh.Render(); }
void Chunks::Render(Pipeline p) { m_shader->Enable(); m_shader->SetTextureUnitType(1); m_shader->SetWVP(p.GetWVPTrans()); m_shader->SetWorld(p.GetWorldTrans()); for (int i = 0; i < VIEW_DISTANCE / CHUNK_SIZE_X * 2; i++) { for (int j = 0; j < VIEW_DISTANCE / CHUNK_SIZE_Z * 2; ++j) { Get(i,j)->Render(); } } }
virtual void RenderSceneCB() { m_scale += 0.01f; m_pGameCamera->OnRender(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); PointLight pl[2]; pl[0].DiffuseIntensity = 0.25f; pl[0].Color = Vector3f(1.0f, 0.5f, 0.0f); pl[0].Position = Vector3f(3.0f, 1.0f, FieldDepth * (cosf(m_scale) + 1.0f) / 2.0f); pl[0].Attenuation.Linear = 0.1f; pl[1].DiffuseIntensity = 0.25f; pl[1].Color = Vector3f(0.0f, 0.5f, 1.0f); pl[1].Position = Vector3f(7.0f, 1.0f, FieldDepth * (sinf(m_scale) + 1.0f) / 2.0f); pl[1].Attenuation.Linear = 0.1f; m_pEffect->SetPointLights(2, pl); SpotLight sl[2]; sl[0].DiffuseIntensity = 0.9f; sl[0].Color = Vector3f(0.0f, 1.0f, 1.0f); sl[0].Position = m_pGameCamera->GetPos(); sl[0].Direction = m_pGameCamera->GetTarget(); sl[0].Attenuation.Linear = 0.1f; sl[0].Cutoff = 10.0f; sl[1].DiffuseIntensity = 0.75f; sl[1].Color = Vector3f(0.0f, 0.5f, 1.0f); sl[1].Position = Vector3f(7.0f, 1.0f, FieldDepth * (sinf(m_scale) + 1.0f) / 2.0f); sl[1].Attenuation.Linear = 0.1f; m_pEffect->SetSpotLights(1, sl); Pipeline p; p.Scale(0.1f, 0.1f, 0.1f); p.Rotate(0.0f, m_scale, 0.0f); p.WorldPos(0.0f, 0.0f, 10.0f); p.SetCamera(m_pGameCamera->GetPos(), m_pGameCamera->GetTarget(), m_pGameCamera->GetUp()); p.SetPerspectiveProj(60.0f, WINDOW_WIDTH, WINDOW_HEIGHT, 1.0f, 100.0f); m_pEffect->SetWVP(p.GetWVPTrans()); m_pEffect->SetWorldMatrix(p.GetWorldTrans()); m_pEffect->SetDirectionalLight(m_directionalLight); m_pEffect->SetEyeWorldPos(m_pGameCamera->GetPos()); m_pEffect->SetMatSpecularIntensity(0.0f); m_pEffect->SetMatSpecularPower(0); m_pMesh->Render(); glutSwapBuffers(); }
void RenderPass() { glCullFace(GL_BACK); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); m_pLightingEffect->Enable(); m_shadowMapFBO.BindForReading(GL_TEXTURE1); Pipeline p; p.SetPerspectiveProj(m_persProjInfo); p.Scale(10.0f, 10.0f, 10.0f); p.WorldPos(0.0f, 0.0f, 1.0f); p.Rotate(90.0f, 0.0f, 0.0f); p.SetCamera(m_pGameCamera->GetPos(), m_pGameCamera->GetTarget(), m_pGameCamera->GetUp()); m_pLightingEffect->SetWVP(p.GetWVPTrans()); m_pLightingEffect->SetWorldMatrix(p.GetWorldTrans()); p.SetCamera(m_spotLight.Position, m_spotLight.Direction, Vector3f(0.0f, 1.0f, 0.0f)); m_pLightingEffect->SetLightWVP(p.GetWVPTrans()); m_pLightingEffect->SetEyeWorldPos(m_pGameCamera->GetPos()); m_pGroundTex->Bind(GL_TEXTURE0); m_quad.Render(); p.Scale(0.1f, 0.1f, 0.1f); p.Rotate(0.0f, m_scale, 0.0f); p.WorldPos(0.0f, 0.0f, 3.0f); p.SetCamera(m_pGameCamera->GetPos(), m_pGameCamera->GetTarget(), m_pGameCamera->GetUp()); m_pLightingEffect->SetWVP(p.GetWVPTrans()); m_pLightingEffect->SetWorldMatrix(p.GetWorldTrans()); p.SetCamera(m_spotLight.Position, m_spotLight.Direction, Vector3f(0.0f, 1.0f, 0.0f)); m_pLightingEffect->SetLightWVP(p.GetWVPTrans()); m_mesh.Render(); }
virtual void RenderPass() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); m_pShadowMapTech->SetTextureUnit(0); m_shadowMapFBO.BindForReading(GL_TEXTURE0); Pipeline p; p.Scale(5.0f, 5.0f, 5.0f); p.WorldPos(0.0f, 0.0f, 10.0f); p.SetCamera(m_pGameCamera->GetPos(), m_pGameCamera->GetTarget(), m_pGameCamera->GetUp()); p.SetPerspectiveProj(60.0f, WINDOW_WIDTH, WINDOW_HEIGHT, 1.0f, 50.0f); m_pShadowMapTech->SetWVP(p.GetWVPTrans()); m_pQuad->Render(); }
void RenderScene() { // Render the object as-is m_LightingTech.Enable(); Pipeline p; p.SetPerspectiveProj(m_persProjInfo); p.SetCamera(m_pGameCamera->GetPos(), m_pGameCamera->GetTarget(), m_pGameCamera->GetUp()); p.WorldPos(m_boxPos); m_LightingTech.SetWorldMatrix(p.GetWorldTrans()); m_LightingTech.SetWVP(p.GetWVPTrans()); m_mesh.Render(); // Render the object's silhouette m_silhouetteTech.Enable(); m_silhouetteTech.SetWorldMatrix(p.GetWorldTrans()); m_silhouetteTech.SetWVP(p.GetWVPTrans()); m_silhouetteTech.SetLightPos(Vector3f(0.0f, 10.0f, 0.0f)); glLineWidth(5.0f); m_mesh.Render(); }
virtual void RenderPass()//render to screen { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); m_pShadowMapTech->SetTextureUnit(0);//set the value to shaders m_shadowMapFBO.BindForReading(GL_TEXTURE0);//the i in GL_TEXTUREi must be same with m_pShadowMapTech->SetTextureUnit(i); Pipeline p; p.Scale(5.0f, 5.0f, 5.0f); p.WorldPos(0.0f, 0.0f, 10.0f); p.SetCamera(m_pGameCamera->GetPos(), m_pGameCamera->GetTarget(), m_pGameCamera->GetUp()); p.SetPerspectiveProj(m_persProjInfo); m_pShadowMapTech->SetWVP(p.GetWVPTrans()); m_pQuad->Render(); }
virtual void RenderSceneCB() { m_scale += 0.0057f; m_pGameCamera->OnRender(); glClear(GL_COLOR_BUFFER_BIT); PointLight pl[2]; pl[0].DiffuseIntensity = 0.5f; pl[0].Color = Vector3f(1.0f, 0.5f, 0.0f); pl[0].Position = Vector3f(3.0f, 1.0f, FieldDepth * (cosf(m_scale) + 1.0f) / 2.0f); pl[0].Attenuation.Linear = 0.1f; pl[1].DiffuseIntensity = 0.5f; pl[1].Color = Vector3f(0.0f, 0.5f, 1.0f); pl[1].Position = Vector3f(7.0f, 1.0f, FieldDepth * (sinf(m_scale) + 1.0f) / 2.0f); pl[1].Attenuation.Linear = 0.1f; m_pEffect->SetPointLights(2, pl); Pipeline p; p.WorldPos(0.0f, 0.0f, 1.0f); p.SetCamera(m_pGameCamera->GetPos(), m_pGameCamera->GetTarget(), m_pGameCamera->GetUp()); p.SetPerspectiveProj(60.0f, WINDOW_WIDTH, WINDOW_HEIGHT, 1.0f, 100.0f); m_pEffect->SetWVP(p.GetWVPTrans()); const Matrix4f& WorldTransformation = p.GetWorldTrans(); m_pEffect->SetWorldMatrix(WorldTransformation); m_pEffect->SetDirectionalLight(m_directionalLight); m_pEffect->SetEyeWorldPos(m_pGameCamera->GetPos()); m_pEffect->SetMatSpecularIntensity(0.0f); m_pEffect->SetMatSpecularPower(0); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glEnableVertexAttribArray(2); glBindBuffer(GL_ARRAY_BUFFER, m_VBO); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid*)12); glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid*)20); m_pTexture->Bind(GL_TEXTURE0); glDrawArrays(GL_TRIANGLES, 0, 6); glDisableVertexAttribArray(0); glDisableVertexAttribArray(1); glDisableVertexAttribArray(2); glutSwapBuffers(); }
virtual void ShadowMapPass()//draw to the m_shadowMapFBO { m_shadowMapFBO.BindForWriting(); glClear(GL_DEPTH_BUFFER_BIT); Pipeline p; p.Scale(0.1f, 0.1f, 0.1f);//notify that it is very small p.Rotate(0.0f, m_scale, 0.0f); p.WorldPos(0.0f, 0.0f, 5.0f); p.SetCamera(m_spotLight.Position, m_spotLight.Direction, Vector3f(0.0f, 1.0f, 0.0f)); p.SetPerspectiveProj(m_persProjInfo); m_pShadowMapTech->SetWVP(p.GetWVPTrans()); m_pMesh->Render(); glBindFramebuffer(GL_FRAMEBUFFER, 0);//reset to use the default framebuffer }
virtual void ShadowMapPass() { m_shadowMapFBO.BindForWriting(); glClear(GL_DEPTH_BUFFER_BIT); Pipeline p; p.Scale(0.2f, 0.2f, 0.2f); p.Rotate(0.0f, m_scale, 0.0f); p.WorldPos(0.0f, 0.0f, 5.0f); p.SetCamera(m_spotLight.Position, m_spotLight.Direction, Vector3f(0.0f, 1.0f, 0.0f)); p.SetPerspectiveProj(60.0f, WINDOW_WIDTH, WINDOW_HEIGHT, 1.0f, 50.0f); m_pShadowMapTech->SetWVP(p.GetWVPTrans()); m_pMesh->Render(); glBindFramebuffer(GL_FRAMEBUFFER, 0); }