void App::drawFrame() { mat4 projection = perspectiveMatrixX(1.5f, width, height, 0.001f, 1.0f); mat4 mvRotate = rotateXY(-wx, -wy); mat4 modelview = mvRotate * translate(-camPos); glMatrixMode(GL_PROJECTION); glLoadTransposeMatrixf(projection); glMatrixMode(GL_MODELVIEW); glLoadTransposeMatrixf(modelview); // Determine the shader selections radialSelect = 0; if(doRadialEnvMap->isChecked()) { radialSelect = 1; } constMipSelect = 0; if(constantMipLevel->isChecked()) { constMipSelect = 1; } // Clear only depth renderer->clear(false, true, false); // Draw the background environment drawEnvironment(projection * mvRotate); // Draw the object drawObject(); }
void App::drawFrame() { const float fov = 1.0f; float4x4 projection = toD3DProjection(perspectiveMatrixY(fov, width, height, 0.1f, 50000)); float4x4 view = rotateXY(-wx, -wy); float4x4 inv_vp_env = !(projection * view); view.translate(-camPos); float4x4 view_proj = projection * view; float clearColor[4] = {0.5f, 0.1f, 0.2f}; renderer->clear(true, true, true, clearColor); renderer->reset(); renderer->setGlobalConstant4x4f("WorldViewProj", view_proj); renderer->apply(); GDModel::Update(&m_GDModel, animLoaded ? &m_restAnim : nullptr, time*30); GDModel::Draw(renderer, &m_GDModel); }
void App::drawFrame(){ const float near_plane = 20.0f; const float far_plane = 4000.0f; // Reversed depth float4x4 projection = toD3DProjection(perspectiveMatrixY(1.2f, width, height, far_plane, near_plane)); float4x4 view = rotateXY(-wx, -wy); view.translate(-camPos); float4x4 viewProj = projection * view; // Pre-scale-bias the matrix so I can use the screen position directly float4x4 viewProjInv = (!viewProj) * (translate(-1.0f, 1.0f, 0.0f) * scale(2.0f / width, -2.0f / height, 1.0f)); TextureID bufferRTs[] = { baseRT, normalRT }; renderer->changeRenderTargets(bufferRTs, elementsOf(bufferRTs), depthRT); renderer->clear(false, true, false, NULL, 0.0f); /* Main scene pass. This is where the buffers are filled for the later deferred passes. */ renderer->reset(); renderer->setRasterizerState(cullBack); renderer->setShader(fillBuffers); renderer->setShaderConstant4x4f("viewProj", viewProj); renderer->setShaderConstant3f("camPos", camPos); renderer->setSamplerState("baseFilter", trilinearAniso); renderer->setDepthState(depthTest); renderer->apply(); for (uint i = 0; i < map->getBatchCount(); i++){ renderer->setTexture("Base", base[i]); renderer->setTexture("Bump", bump[i]); renderer->applyTextures(); map->drawBatch(renderer, i); } renderer->changeToMainFramebuffer(); int mode = renderMode->getSelectedItem(); /* Deferred ambient pass */ renderer->reset(); renderer->setRasterizerState(cullNone); renderer->setShader(ambient); renderer->setShaderConstant2f("factors", float2((mode == 3)? 0.0f : 0.1f, (mode == 3)? 1.0f : 0.0f)); renderer->setTexture("Base", baseRT); if (antiAliasSamples == 1) renderer->setSamplerState("filter", pointClamp); renderer->setDepthState(noDepthTest); renderer->apply(); context->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST); context->Draw(3, 0); if (mode == 3) return; renderer->changeRenderTargets(NULL, 0, stencilMask); renderer->clear(false, true, true, NULL, 0.0f, 0); /* Create the stencil mask */ renderer->reset(); renderer->setRasterizerState(cullNone); renderer->setShader(createMask); renderer->setTexture("BackBuffer", backBufferTexture); renderer->setSamplerState("filter", pointClamp); renderer->setDepthState(stencilSet, 0x1); renderer->apply(); context->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST); context->Draw(3, 0); renderer->changeRenderTarget(FB_COLOR, stencilMask); /* Deferred lighting pass. Draw twice, using stencil to separate pixels for single or multiple sample evaluation. */ float2 zw = projection.rows[2].zw(); int passCount = (mode == 0 && antiAliasSamples > 1)? 2 : 1; for (int p = 0; p < passCount; p++){ renderer->reset(); if (mode == 0 && antiAliasSamples > 1){ renderer->setDepthState(stencilTest, (p == 0)? 0x1 : 0x0); renderer->setShader(lighting[p]); } else { renderer->setDepthState(noDepthTest); if (mode == 1){ renderer->setShader(lighting[0]); } else { renderer->setShader(lighting[1]); } } renderer->setRasterizerState(cullFront); renderer->setBlendState(blendAdd); renderer->setShaderConstant4x4f("viewProj", viewProj); renderer->setShaderConstant4x4f("viewProjInv", viewProjInv); renderer->setShaderConstant3f("camPos", camPos); renderer->setTexture("Base", baseRT); renderer->setTexture("Normal", normalRT); renderer->setTexture("Depth", depthRT); renderer->apply(); for (uint i = 0; i < LIGHT_COUNT; i++){ float3 lightPos = lights[i].position; float radius = lights[i].radius; float invRadius = 1.0f / radius; // Compute z-bounds float4 lPos = view * float4(lightPos, 1.0f); float z1 = lPos.z + radius; if (z1 > near_plane){ float z0 = max(lPos.z - radius, near_plane); float2 zBounds; zBounds.y = saturate(zw.x + zw.y / z0); zBounds.x = saturate(zw.x + zw.y / z1); renderer->setShaderConstant3f("lightPos", lightPos); renderer->setShaderConstant1f("radius", radius); renderer->setShaderConstant1f("invRadius", invRadius); renderer->setShaderConstant2f("zBounds", zBounds); renderer->applyConstants(); sphere->draw(renderer); } } } // Display help text static float displayTime = 5.0f; if (displayTime > 0 && antiAliasSamples <= 1){ if (configDialog->isVisible()){ displayTime = 0; } else { displayTime -= min(frameTime, 0.1f); renderer->drawText("Press F1 to select\na multisampled mode", width * 0.5f - 140, height * 0.5f - 38, 30, 38, defaultFont, linearClamp, blendSrcAlpha, noDepthTest); } } }
void Vector::rotate(float x, float y, float z){ rotateYZ(x); rotateXZ(y); rotateXY(z); }