//******************************************************************************* void CWaterEnvMap::renderTestMesh(IDriver &driver) { doInit(); CMaterial testMat; testMat.setLighting(false); testMat.texEnvOpRGB(0, CMaterial::Modulate); testMat.texEnvArg0RGB(0, CMaterial::Texture, CMaterial::SrcColor); testMat.texEnvArg0RGB(1, CMaterial::Diffuse, CMaterial::SrcColor); testMat.texEnvOpAlpha(0, CMaterial::Replace); testMat.texEnvArg0Alpha(0, CMaterial::Constant, CMaterial::SrcAlpha); testMat.texConstantColor(0, CRGBA(255, 255, 255, 255)); testMat.setDoubleSided(true); testMat.setZWrite(false); testMat.setZFunc(CMaterial::always); // tmp : test cubemap driver.activeVertexProgram(&testMeshVP); driver.activeVertexBuffer(_TestVB); driver.activeIndexBuffer(_TestIB); driver.setConstantMatrix(0, IDriver::ModelViewProjection, IDriver::Identity); // tmp _MaterialPassThruZTest.setTexture(0, _EnvCubic); driver.setConstantMatrix(0, IDriver::ModelViewProjection, IDriver::Identity); driver.setConstant(4, 2.f, 1.f, 0.f, 0.f); //driver.renderTriangles(testMat, 0, TEST_VB_NUM_TRIS); driver.renderTriangles(_MaterialPassThruZTest, 0, TEST_VB_NUM_TRIS); driver.activeVertexProgram(NULL); }
//******************************************************************************* void CWaterEnvMap::update(TGlobalAnimationTime time, IDriver &driver) { if (_LastRenderTime == time) return; _LastRenderTime = time; // First five updates are used to render the cubemap faces (bottom face is not rendered) // Sixth update project the cubemap into a 2D texture uint numTexToRender; if (_UpdateTime > 0) { uint64 currRenderTick = (uint64) (time / (_UpdateTime / (NUM_FACES_TO_RENDER + 1))); numTexToRender = (uint) (currRenderTick - _LastRenderTick); _LastRenderTick = currRenderTick; } else { numTexToRender = NUM_FACES_TO_RENDER + 1; } if (!numTexToRender) return; if (_NumRenderedFaces == 0) { _StartRenderTime = time; } uint lastCubeFacesToRender = std::min((uint) NUM_FACES_TO_RENDER, _NumRenderedFaces + numTexToRender); // we don't render negative Z (only top hemisphere is used) for(uint k = _NumRenderedFaces; k < lastCubeFacesToRender; ++k) { driver.setRenderTarget(_EnvCubic, 0, 0, _EnvCubicSize, _EnvCubicSize, 0, (uint32) k); render((CTextureCube::TFace) k, _StartRenderTime); } _NumRenderedFaces = lastCubeFacesToRender; if (_NumRenderedFaces == NUM_FACES_TO_RENDER && (_NumRenderedFaces + numTexToRender) > NUM_FACES_TO_RENDER) { // render to 2D map driver.setRenderTarget(_Env2D, 0, 0, _Env2DSize, _Env2DSize); doInit(); // driver.activeVertexProgram(NULL); driver.activeVertexBuffer(_FlattenVB); driver.activeIndexBuffer(_FlattenIB); driver.setFrustum(-1.f, 1.f, -1.f, 1.f, 0.f, 1.f, false); driver.setupViewMatrix(CMatrix::Identity); CMatrix mat; //mat.scale(0.8f); driver.setupModelMatrix(mat); _MaterialPassThru.setTexture(0, _EnvCubic); _MaterialPassThru.texConstantColor(0, CRGBA(255, 255, 255, _Alpha)); driver.renderTriangles(_MaterialPassThru, 0, FVB_NUM_TRIS); _NumRenderedFaces = 0; // start to render again } driver.setRenderTarget(NULL); }