Subversion Repository Public Repository

Divide-Framework

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

Diff Revisions 259 vs 260 for /trunk/Source Code/Rendering/Lighting/ShadowMapping/ShadowMap.cpp

Diff revisions: vs.
  @@ -5,13 +5,15 @@
5 5 #include "Scenes/Headers/SceneState.h"
6 6 #include "Headers/CascadedShadowMaps.h"
7 7 #include "Rendering/Lighting/Headers/Light.h"
8 + #include "Rendering/Lighting/Headers/DirectionalLight.h"
9 + #include "Hardware/Video/Headers/GFXDevice.h"
8 10 #include "Hardware/Video/Buffers/FrameBuffer/Headers/FrameBuffer.h"
9 11
10 - ShadowMap::ShadowMap(Light* light, ShadowType type) : _resolutionFactor(1),
11 - _init(false),
12 + ShadowMap::ShadowMap(Light* light, ShadowType type) : _init(false),
12 13 _isBound(false),
13 14 _light(light),
14 15 _shadowMapType(type),
16 + _resolution(0),
15 17 _par(ParamHandler::getInstance())
16 18 {
17 19 _bias.bias();
  @@ -26,7 +28,8 @@
26 28 _shadowMap(nullptr)
27 29 {
28 30 _resolution = 512;
29 - _resolutionFactor = 1.0f;
31 + if (GFX_DEVICE.shadowDetailLevel() == DETAIL_HIGH) _resolution = 1024;
32 + if (GFX_DEVICE.shadowDetailLevel() == DETAIL_ULTRA) _resolution = 2048;
30 33 _numLayers = 1;
31 34 }
32 35
  @@ -38,7 +41,6 @@
38 41 if(_shadowMap) return _shadowMap;
39 42
40 43 if(!_light->castsShadows()) return nullptr;
41 - _resolutionFactor = renderState.shadowMapResolutionFactor();
42 44
43 45 switch(_light->getLightType()){
44 46 case LIGHT_TYPE_POINT:{
  @@ -46,8 +48,9 @@
46 48 _shadowMap = New CubeShadowMap(_light);
47 49 }break;
48 50 case LIGHT_TYPE_DIRECTIONAL:{
49 - _numLayers = renderState.csmSplitCount();
50 - _shadowMap = New CascadedShadowMaps(_light, _numLayers, renderState.csmSplitLogFactor());
51 + DirectionalLight* dirLight = dynamic_cast<DirectionalLight*>(_light);
52 + _numLayers = dirLight->csmSplitCount();
53 + _shadowMap = New CascadedShadowMaps(_light, _numLayers);
51 54 }break;
52 55 case LIGHT_TYPE_SPOT:{
53 56 _shadowMap = New SingleShadowMap(_light);
  @@ -61,30 +64,33 @@
61 64 return _shadowMap;
62 65 }
63 66
67 + void ShadowMapInfo::resolution(U16 resolution) {
68 + _resolution = resolution;
69 + if (_shadowMap)
70 + _shadowMap->resolution(_resolution, _light->shadowMapResolutionFactor());
71 + }
72 +
64 73 bool ShadowMap::Bind(U8 offset){
65 - if(_isBound)
74 + if (_isBound || !_depthMap)
66 75 return false;
67 76
68 77 _isBound = true;
69 78
70 - if(_depthMap){
71 - if(getShadowMapType() == SHADOW_TYPE_CSM){
72 - _depthMap->Bind(offset, TextureDescriptor::Color0);
73 - _depthMap->UpdateMipMaps(TextureDescriptor::Color0);
74 - }else{
75 - _depthMap->Bind(offset, TextureDescriptor::Depth);
76 - }
79 + if (getShadowMapType() == SHADOW_TYPE_CSM){
80 + _depthMap->Bind(offset, TextureDescriptor::Color0 );
81 + _depthMap->UpdateMipMaps(TextureDescriptor::Color0);
82 + } else {
83 + _depthMap->Bind(offset, TextureDescriptor::Depth);
77 84 }
78 85
79 86 return true;
80 87 }
81 88
82 89 bool ShadowMap::Unbind(U8 offset){
83 - if(!_isBound)
90 + if (!_isBound || !_depthMap)
84 91 return false;
85 92
86 - if(_depthMap)
87 - _depthMap->Unbind(offset);
93 + _depthMap->Unbind(offset);
88 94
89 95 _isBound = false;
90 96 return true;