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/ParallelSplitShadowMaps.cpp

Diff revisions: vs.
  @@ -36,16 +36,19 @@
36 36 createJitterTexture(JITTER_SIZE,8,8);
37 37
38 38 _depthMap = GFX_DEVICE.newFBO(FBO_2D_ARRAY_DEPTH);
39 +
40 + SamplerDescriptor depthMapSampler;
41 + depthMapSampler.setWrapMode(TEXTURE_CLAMP_TO_EDGE);
42 + depthMapSampler.toggleMipMaps(false);
43 + depthMapSampler._useRefCompare = true; //< Use compare function
44 + depthMapSampler._cmpFunc = CMP_FUNC_LEQUAL; //< Use less or equal
45 + depthMapSampler._depthCompareMode = INTENSITY;
39 46
40 47 TextureDescriptor depthMapDescriptor(TEXTURE_2D_ARRAY,
41 48 DEPTH_COMPONENT,
42 49 DEPTH_COMPONENT24,
43 50 UNSIGNED_BYTE); ///Default filters, LINEAR is OK for this
44 - depthMapDescriptor.setWrapMode(TEXTURE_CLAMP_TO_EDGE,TEXTURE_CLAMP_TO_EDGE);
45 - depthMapDescriptor._useRefCompare = true; //< Use compare function
46 - depthMapDescriptor._cmpFunc = CMP_FUNC_LEQUAL; //< Use less or equal
47 - depthMapDescriptor._depthCompareMode = LUMINANCE;
48 - depthMapDescriptor.toggleMipMaps(false);
51 + depthMapDescriptor.setSampler(depthMapSampler);
49 52 _depthMap->AddAttachment(depthMapDescriptor, TextureDescriptor::Depth);
50 53 _depthMap->toggleColorWrites(false); //<do not draw colors
51 54 _depthMap->toggleDepthBuffer(false); //<do not create a depth buffer
  @@ -100,14 +103,14 @@
100 103 SAFE_DELETE(_jitterTexture);
101 104 }
102 105
103 - void PSShadowMaps::resolution(U16 resolution,SceneRenderState* sceneRenderState){
106 + void PSShadowMaps::resolution(U16 resolution, const SceneRenderState& sceneRenderState){
104 107 vec2<F32> zPlanes = Frustum::getInstance().getZPlanes();
105 108 calculateSplitPoints( _light->getShadowMapInfo()->_numSplits, zPlanes.x,zPlanes.y);
106 109 setOptimalAdjustFactor(0, 5);
107 110 setOptimalAdjustFactor(1, 1);
108 111 setOptimalAdjustFactor(2, 0);
109 112
110 - U8 resolutionFactorTemp = sceneRenderState->shadowMapResolutionFactor();
113 + U8 resolutionFactorTemp = sceneRenderState.shadowMapResolutionFactor();
111 114 CLAMP<U8>(resolutionFactorTemp, 1, 4);
112 115 U16 maxResolutionTemp = resolution;
113 116 if(resolutionFactorTemp != _resolutionFactor || _maxResolution != maxResolutionTemp){
  @@ -122,20 +125,19 @@
122 125 ShadowMap::resolution(resolution,sceneRenderState);
123 126 }
124 127
125 - void PSShadowMaps::render(SceneRenderState* sceneRenderState, boost::function0<void> sceneRenderFunction){
126 - ///Only if we have a valid callback;
128 + void PSShadowMaps::render(const SceneRenderState& renderState, boost::function0<void> sceneRenderFunction){
129 + //Only if we have a valid callback;
127 130 if(sceneRenderFunction.empty()) {
128 131 ERROR_FN(Locale::get("ERROR_LIGHT_INVALID_SHADOW_CALLBACK"), _light->getId());
129 132 return;
130 133 }
131 - F32 ortho = GET_ACTIVE_SCENE()->getSceneGraph()->getRoot()->getBoundingBox().getWidth() * 0.5f;
132 -
134 + F32 ortho = GET_ACTIVE_SCENEGRAPH()->getRoot()->getBoundingBox().getWidth() * 0.5f;
135 + CLAMP<F32>(ortho, 1.0f, (F32)Config::DIRECTIONAL_LIGHT_DISTANCE);
133 136 for(U8 i = 0; i < _numSplits; i++){
134 - F32 div = (1.0f + i) * (1.0f + i) + i;
135 - _orthoPerPass[_numSplits - i - 1] = ortho / div;
137 + _orthoPerPass[_numSplits - i - 1] = ortho / ((1.0f + i) * (1.0f + i) + i);
136 138 }
137 139 _callback = sceneRenderFunction;
138 - renderInternal(sceneRenderState);
140 + renderInternal(renderState);
139 141 }
140 142
141 143 void PSShadowMaps::setOptimalAdjustFactor(U8 index, F32 value){
  @@ -163,10 +165,12 @@
163 165 _splitPoints[splitCount] = farDist;
164 166 }
165 167
166 - void PSShadowMaps::renderInternal(SceneRenderState* renderState) const {
168 + void PSShadowMaps::renderInternal(const SceneRenderState& renderState) const {
169 + Scene* activeScene = GET_ACTIVE_SCENE();
170 + boost::function0<void> renderFunction = _callback.empty() ? SCENE_GRAPH_UPDATE(activeScene->getSceneGraph()) : _callback;
167 171 GFXDevice& gfx = GFX_DEVICE;
168 172 //Get our eye view
169 - const vec3<F32>& eyePos = renderState->getCamera()->getEye();
173 + const vec3<F32>& eyePos = renderState.getCameraConst().getEye();
170 174 //For every depth map
171 175 //Lock our projection matrix so no changes will be permanent during the rest of the frame
172 176 //Lock our model view matrix so no camera transforms will be saved beyond this light's scope
  @@ -181,12 +185,7 @@
181 185 _light->renderFromLightView(i, _orthoPerPass[i]);
182 186 _depthMap->DrawToLayer(0,i);
183 187 //draw the scene
184 - Scene* activeScene = GET_ACTIVE_SCENE();
185 - if(_callback.empty()){
186 - GFX_DEVICE.render(SCENE_GRAPH_UPDATE(activeScene->getSceneGraph()), activeScene->renderState());
187 - }else{
188 - GFX_DEVICE.render(_callback, activeScene->renderState());
189 - }
188 + GFX_DEVICE.render(renderFunction, renderState);
190 189 }
191 190 _depthMap->End();
192 191 //get all the required information (light MVP matrix for example)
  @@ -207,17 +206,17 @@
207 206 _depthMap->Bind(0,1);
208 207 GFX_DEVICE.toggle2D(true);
209 208 _previewDepthMapShader->Uniform("layer",0);
210 - GFX_DEVICE.renderInViewport(vec4<I32>(0,0,128,128),
209 + GFX_DEVICE.renderInViewport(vec4<U32>(0,0,128,128),
211 210 DELEGATE_BIND(&GFXDevice::renderInstance,
212 211 DELEGATE_REF(GFX_DEVICE),
213 212 DELEGATE_REF(_renderQuad->renderInstance())));
214 213 _previewDepthMapShader->Uniform("layer",1);
215 - GFX_DEVICE.renderInViewport(vec4<I32>(130,0,128,128),
214 + GFX_DEVICE.renderInViewport(vec4<U32>(130,0,128,128),
216 215 DELEGATE_BIND(&GFXDevice::renderInstance,
217 216 DELEGATE_REF(GFX_DEVICE),
218 217 DELEGATE_REF(_renderQuad->renderInstance())));
219 218 _previewDepthMapShader->Uniform("layer",2);
220 - GFX_DEVICE.renderInViewport(vec4<I32>(260,0,128,128),
219 + GFX_DEVICE.renderInViewport(vec4<U32>(260,0,128,128),
221 220 DELEGATE_BIND(&GFXDevice::renderInstance,
222 221 DELEGATE_REF(GFX_DEVICE),
223 222 DELEGATE_REF(_renderQuad->renderInstance())));