void renderSpotBuffers(Storm3D_Scene &scene, bool renderShadows) { GFX_TRACE_SCOPE("renderSpotBuffers"); device.SetRenderState(D3DRS_COLORWRITEENABLE, 0); Storm3D_ShaderManager::GetSingleton()->setNormalShaders(); Storm3D_Camera &camera = *static_cast<Storm3D_Camera *> (scene.GetCamera()); Storm3D_Spotlight::clearCache(); if(renderShadows) { SpotList::iterator it = spots.begin(); for(; it != spots.end(); ++it) { Storm3D_Spotlight *spot = it->get(); if(!spot || !spot->enabled() || !spot->featureEnabled(IStorm3D_Spotlight::Shadows)) continue; // Test spot visibility with foo scissor rect -- not really an optimal way of doing this if(!spot->setScissorRect(camera, VC2I(100, 100), scene)) continue; device.SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE); const float *cameraView = camera.GetView4x4Matrix(); if(!spot->setAsRenderTarget(cameraView)) continue; /* debug static unsigned int count = 0; count++; device.Clear(0, NULL, D3DCLEAR_ZBUFFER, 0, float(count % 21) / 20.0f, 0); */ //glClearDepth(float(count % 11) / 10.0f); //glClear(GL_DEPTH_BUFFER_BIT); renderer.render(IStorm3D_TerrainRendererBase::SpotBuffer, scene, spot); } } device.SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP); device.SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP); Storm3D_ShaderManager::GetSingleton()->setNormalShaders(); device.SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_ALPHA | D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE); device.SetPixelShader(0); camera.Apply(); }
void renderSpotLights(Storm3D_Scene &scene, bool renderShadows, LightType type) { GFX_TRACE_SCOPE("renderSpotLights"); // this renders spotlight light & shadows //setTracing(true); Storm3D_ShaderManager::GetSingleton()->setProjectedShaders(); device.SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE); device.SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE); device.SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); device.SetRenderState(D3DRS_ALPHATESTENABLE, FALSE); device.SetRenderState(D3DRS_ALPHAREF, 0x1); device.SetRenderState(D3DRS_ZWRITEENABLE, FALSE); for(int i = 0; i < 4; ++i) { if(i != 2) { device.SetSamplerState(i, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); device.SetSamplerState(i, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); } } Storm3D_Camera &camera = *static_cast<Storm3D_Camera *> (scene.GetCamera()); SpotList::iterator it = spots.begin(); for(; it != spots.end(); ++it) { Storm3D_Spotlight *spot = it->get(); if(!spot || !spot->enabled()) continue; // Test spot visibility with foo scissor rect -- not really an optimal way of doing this if(!spot->setScissorRect(camera, VC2I(100, 100), scene)) continue; device.SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE); if(!false) { device.SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_PROJECTED); device.SetTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_PROJECTED); device.SetTextureStageState(2, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE); device.SetTextureStageState(3, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE); } const float *cameraView = camera.GetView4x4Matrix(); const float *cameraViewProjection = camera.GetViewProjection4x4Matrix(); spot->applyTextures(cameraView, cameraViewProjection, storm, renderShadows); if(type == RealSolid) renderer.render(IStorm3D_TerrainRendererBase::SpotProjectionSolid, scene, spot); else { renderer.render(IStorm3D_TerrainRendererBase::SpotProjectionDecal, scene, spot); renderer.render(IStorm3D_TerrainRendererBase::SpotProjectionAlpha, scene, spot); } } Storm3D_ShaderManager::GetSingleton()->setNormalShaders(); for(int i = 0; i < 4; ++i) { device.SetSamplerState(i, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP); device.SetSamplerState(i, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP); } //setTracing(false); device.SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE); device.SetTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE); device.SetTextureStageState(2, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE); device.SetTextureStageState(3, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE); device.SetTexture(1, 0); device.SetTexture(2, 0); device.SetTexture(3, 0); device.SetTexture(4, 0); device.SetPixelShader(0); device.SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); device.SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE); device.SetRenderState(D3DRS_CLIPPLANEENABLE, FALSE); }
void Storm3D_Spotlight::querySizes(Storm3D &storm, bool ps14, int shadowQuality) { if(shadowQuality >= 100) { SHADOW_WIDTH = 1024; SHADOW_HEIGHT = 1024; //SHADOW_WIDTH = 2048; //SHADOW_HEIGHT = 2048; } else if(shadowQuality >= 75) { SHADOW_WIDTH = 1024; SHADOW_HEIGHT = 512; } else if(shadowQuality >= 50) { SHADOW_WIDTH = 512; SHADOW_HEIGHT = 512; } else if(shadowQuality >= 25) { SHADOW_WIDTH = 512; SHADOW_HEIGHT = 256; } else { SHADOW_WIDTH = 256; SHADOW_HEIGHT = 256; } /* if(shadowQuality >= 100) { SHADOW_WIDTH = 768; SHADOW_HEIGHT = 768; } else if(shadowQuality >= 66) { SHADOW_WIDTH = 512; SHADOW_HEIGHT = 512; } else if(shadowQuality >= 33) { SHADOW_WIDTH = 384; SHADOW_HEIGHT = 384; } else { SHADOW_WIDTH = 256; SHADOW_HEIGHT = 256; } */ if(type == Legacy) { bool enableFloats = true; if(shadowQuality <= 33) enableFloats = false; findDepthType(*storm.D3D, ps14, enableFloats); } if(type != DepthBuffer) storm.setNeededDepthTarget(VC2I(SHADOW_WIDTH * 2, SHADOW_HEIGHT * 2)); //else //storm.setNeededColorTarget(VC2I(SHADOW_WIDTH * 2, SHADOW_HEIGHT * 2)); }