Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 167 vs 168 for /trunk/Source Code/Rendering/Lighting/ShadowMapping/CubeShadowMap.cpp

Diff revisions: vs.
  @@ -18,10 +18,14 @@
18 18 DEPTH_COMPONENT,
19 19 DEPTH_COMPONENT,
20 20 UNSIGNED_BYTE); ///Default filters, LINEAR is OK for this
21 - depthMapDescriptor.setWrapMode(TEXTURE_CLAMP_TO_EDGE,TEXTURE_CLAMP_TO_EDGE);
22 - depthMapDescriptor._useRefCompare = true; //< Use compare function
23 - depthMapDescriptor._cmpFunc = CMP_FUNC_LEQUAL; //< Use less or equal
24 - depthMapDescriptor._depthCompareMode = LUMINANCE;
21 +
22 + SamplerDescriptor depthMapSampler;
23 + depthMapSampler.setWrapMode(TEXTURE_CLAMP_TO_EDGE);
24 + depthMapSampler.toggleMipMaps(false);
25 + depthMapSampler._useRefCompare = true; //< Use compare function
26 + depthMapSampler._cmpFunc = CMP_FUNC_LEQUAL; //< Use less or equal
27 + depthMapSampler._depthCompareMode = LUMINANCE;
28 + depthMapDescriptor.setSampler(depthMapSampler);
25 29
26 30 _depthMap = GFX_DEVICE.newFBO(FBO_CUBE_DEPTH);
27 31 _depthMap->AddAttachment(depthMapDescriptor, TextureDescriptor::Depth);
  @@ -32,8 +36,8 @@
32 36 {
33 37 }
34 38
35 - void CubeShadowMap::resolution(U16 resolution,SceneRenderState* sceneRenderState){
36 - U8 resolutionFactorTemp = sceneRenderState->shadowMapResolutionFactor();
39 + void CubeShadowMap::resolution(U16 resolution, const SceneRenderState& renderState){
40 + U8 resolutionFactorTemp = renderState.shadowMapResolutionFactor();
37 41 CLAMP<U8>(resolutionFactorTemp, 1, 4);
38 42 U16 maxResolutionTemp = resolution;
39 43 if(resolutionFactorTemp != _resolutionFactor || _maxResolution != maxResolutionTemp){
  @@ -44,10 +48,10 @@
44 48 U16 shadowMapDimension = _maxResolution/_resolutionFactor;
45 49 _depthMap->Create(shadowMapDimension,shadowMapDimension,RGBA16F);
46 50 }
47 - ShadowMap::resolution(resolution,sceneRenderState);
51 + ShadowMap::resolution(resolution, renderState);
48 52 }
49 53
50 - void CubeShadowMap::render(SceneRenderState* renderState, boost::function0<void> sceneRenderFunction){
54 + void CubeShadowMap::render(const SceneRenderState& renderState, boost::function0<void> sceneRenderFunction){
51 55 ///Only if we have a valid callback;
52 56 if(sceneRenderFunction.empty()) {
53 57 ERROR_FN(Locale::get("ERROR_LIGHT_INVALID_SHADOW_CALLBACK"), _light->getId());
  @@ -58,52 +62,18 @@
58 62 renderInternal(renderState);
59 63 }
60 64
61 - void CubeShadowMap::renderInternal(SceneRenderState* renderState) const {
62 - //Only use cube map depth map
63 - if(_depthMap->getType() != FBO_CUBE_DEPTH){
64 - ERROR_FN(Locale::get("ERROR_GFX_DEVICE_INVALID_FBO_CUBEMAP_SHADOW"));
65 - return;
66 - }
67 - vec3<F32> lightPosition = _light->getPosition();
68 - Camera* activeCamera = GET_ACTIVE_SCENE()->renderState()->getCamera();
65 + void CubeShadowMap::renderInternal(const SceneRenderState& renderState) const {
66 +
69 67 //Get some global vars. We limit ourselves to drawing only the objects in the light's range. If range is infinit (-1) we use the GFX limit
70 68 F32 zNear = Frustum::getInstance().getZPlanes().x;
71 69 F32 zFar = _light->getRange();
70 + F32 oldzFar = Frustum::getInstance().getZPlanes().y;
72 71 if(zFar < zNear){
73 - zFar = Frustum::getInstance().getZPlanes().y;
72 + zFar = oldzFar;
74 73 }
75 - //Save our current camera settings
76 - activeCamera->SaveCamera();
77 - //And save all camera transform matrices
78 - GFX_DEVICE.lockMatrices();
79 - //set a 90 degree vertical FoV perspective projection
80 - GFX_DEVICE.setPerspectiveProjection(90.0,1,vec2<F32>(zNear,zFar));
81 - //Save our old rendering stage
82 - RenderStage prev = GFX_DEVICE.getRenderStage();
83 - //And set the current render stage to
84 - GFX_DEVICE.setRenderStage(SHADOW_STAGE);
85 - //For each of the environment's faces (TOP,DOWN,NORTH,SOUTH,EAST,WEST)
86 - for(U8 i = 0; i < 6; i++){
87 - //Set the correct camera orientation and position for current face
88 - activeCamera->RenderLookAtToCubeMap( lightPosition, i );
89 - //Bind our FBO's current face
90 - _depthMap->Begin(i);
91 - //draw our scene
92 -
93 - //Don't need to override cubemap rendering callback
94 - if(_callback.empty()){
95 - Scene* activeScene = GET_ACTIVE_SCENE();
96 - GFX_DEVICE.render(SCENE_GRAPH_UPDATE(activeScene->getSceneGraph()), activeScene->renderState());
97 - }else{
98 - GFX_DEVICE.render(_callback, GET_ACTIVE_SCENE()->renderState());
99 - }
100 - //Unbind this face
101 - _depthMap->End(i);
102 - }
103 - //Return to our previous rendering stage
104 - GFX_DEVICE.setRenderStage(prev);
105 - //Restore transfom matrices
106 - GFX_DEVICE.releaseMatrices();
107 - //And restore camera
108 - activeCamera->RestoreCamera();
74 + Frustum::getInstance().setZPlanes(vec2<F32>(zNear,zFar));
75 +
76 + GFX_DEVICE.generateCubeMap(*_depthMap, _light->getPosition(), _callback, SHADOW_STAGE);
77 +
78 + Frustum::getInstance().setZPlanes(vec2<F32>(zNear,oldzFar));
109 79 }