Commit MetaInfo

Revision77ed6a7657b68b74672e219bb008c05813672013 (tree)
Time2019-11-06 10:41:33
Author <jarmonik@c0f5...>

Log Message

- Fixed "negative" shadows caused by graphics thats sunken in terrain.
- Improved shadows received by base objects.

Change Summary

Incremental Difference

diff -r 34ff09c1e781 -r 77ed6a7657b6 Modules/D3D9Client/Common.hlsl
--- a/Modules/D3D9Client/Common.hlsl Tue Nov 05 18:02:28 2019 +0000
+++ b/Modules/D3D9Client/Common.hlsl Wed Nov 06 01:41:33 2019 +0000
@@ -132,7 +132,7 @@
132132 // ==========================================================================================================
133133 // Object Self Shadows
134134 // ==========================================================================================================
135-
135+/*
136136 float ProjectShadows(float2 sp)
137137 {
138138 if (!gShadowsEnabled) return 0.0f;
@@ -159,14 +159,13 @@
159159 if ((tex2D(ShadowS, sp + dx).r) > pd) va++;
160160
161161 return va / 9.0f;
162-}
162+}*/
163163
164164
165165 // ---------------------------------------------------------------------------------------------------
166166 //
167167 float SampleShadows(float2 sp, float pd)
168168 {
169- if (!gShadowsEnabled) return 0.0f;
170169
171170 float2 dx = float2(gSHD[1], 0) * 1.5f;
172171 float2 dy = float2(0, gSHD[1]) * 1.5f;
@@ -193,8 +192,7 @@
193192 //
194193 float SampleShadows2(float2 sp, float pd)
195194 {
196- if (!gShadowsEnabled) return 0.0f;
197-
195+
198196 float val = 0;
199197 float m = KERNEL_RADIUS * gSHD[1];
200198
@@ -210,7 +208,6 @@
210208 //
211209 float SampleShadows3(float2 sp, float pd, float4 frame)
212210 {
213- if (!gShadowsEnabled) return 0.0f;
214211
215212 float val = 0;
216213 frame *= KERNEL_RADIUS * gSHD[1];
@@ -228,6 +225,7 @@
228225 //
229226 float SampleShadowsEx(float2 sp, float pd, float4 sc)
230227 {
228+
231229 #if SHDMAP == 1
232230 return SampleShadows(sp, pd);
233231 #elif SHDMAP == 2 || SHDMAP == 4
@@ -245,12 +243,17 @@
245243 //
246244 float ComputeShadow(float4 shdH, float dLN, float4 sc)
247245 {
246+ if (!gShadowsEnabled) return 1.0f;
247+
248248 shdH.xyz /= shdH.w;
249249 shdH.z = 1 - shdH.z;
250250 float2 sp = shdH.xy * float2(0.5f, -0.5f) + float2(0.5f, 0.5f);
251251
252252 sp += gSHD[1] * 0.5f;
253253
254+ if (sp.x < 0 || sp.y < 0) return 1.0f; // If a sample is outside border -> fully lit
255+ if (sp.x > 1 || sp.y > 1) return 1.0f;
256+
254257 float fShadow;
255258
256259 float kr = gSHD[0] * KERNEL_RADIUS;
@@ -258,17 +261,12 @@
258261 float ofs = kr / (dLN * dx);
259262 float omx = min(0.05 + ofs, 0.5);
260263
261- if (gBaseBuilding) {
264+ float pd = shdH.z + omx * gSHD[3];
262265
263- // It's a surface base building
264- fShadow = ProjectShadows(sp);
265- }
266- else {
266+ if (pd < 0) pd = 0;
267+ if (pd > 1) pd = 1;
267268
268- // It's a vessel
269- float pd = shdH.z + omx * gSHD[3];
270- fShadow = SampleShadowsEx(sp, pd, sc);
271- }
272-
269+ fShadow = SampleShadowsEx(sp, pd, sc);
270+
273271 return 1 - fShadow;
274272 }
\ No newline at end of file
diff -r 34ff09c1e781 -r 77ed6a7657b6 Modules/D3D9Client/Surface.fx
--- a/Modules/D3D9Client/Surface.fx Tue Nov 05 18:02:28 2019 +0000
+++ b/Modules/D3D9Client/Surface.fx Wed Nov 06 01:41:33 2019 +0000
@@ -323,6 +323,7 @@
323323 // -------------------------------------------------------------------------------------------------------------
324324 // Project shadows on surface
325325 //
326+/*
326327 float ProjectShadows(float2 sp)
327328 {
328329 if (sp.x < 0 || sp.y < 0) return 1.0f;
@@ -347,6 +348,38 @@
347348 if ((tex2D(ShadowS, sp + dx).r) < pd) va++;
348349
349350 return va / 9.0f;
351+}*/
352+
353+
354+
355+// ---------------------------------------------------------------------------------------------------
356+//
357+float SampleShadows(float2 sp, float pd)
358+{
359+ if (sp.x < 0 || sp.y < 0) return 0.0f; // If a sample is outside border -> fully lit
360+ if (sp.x > 1 || sp.y > 1) return 0.0f;
361+
362+ if (pd < 0) pd = 0;
363+ if (pd > 2) pd = 2;
364+
365+ float2 dx = float2(vSHD[1], 0) * 1.5f;
366+ float2 dy = float2(0, vSHD[1]) * 1.5f;
367+ float va = 0;
368+
369+ sp -= dy;
370+ if ((tex2D(ShadowS, sp - dx).r) > pd) va++;
371+ if ((tex2D(ShadowS, sp).r) > pd) va++;
372+ if ((tex2D(ShadowS, sp + dx).r) > pd) va++;
373+ sp += dy;
374+ if ((tex2D(ShadowS, sp - dx).r) > pd) va++;
375+ if ((tex2D(ShadowS, sp).r) > pd) va++;
376+ if ((tex2D(ShadowS, sp + dx).r) > pd) va++;
377+ sp += dy;
378+ if ((tex2D(ShadowS, sp - dx).r) > pd) va++;
379+ if ((tex2D(ShadowS, sp).r) > pd) va++;
380+ if ((tex2D(ShadowS, sp + dx).r) > pd) va++;
381+
382+ return va * 0.1111111f;
350383 }
351384
352385 // -------------------------------------------------------------------------------------------------------------
@@ -698,8 +731,10 @@
698731 #if defined(_SHDMAP)
699732 if (bShadows) {
700733 frg.shdH.xyz /= frg.shdH.w;
734+ frg.shdH.z = 1 - frg.shdH.z;
701735 float2 sp = frg.shdH.xy * float2(0.5f, -0.5f) + float2(0.5f, 0.5f);
702- fShadow = ProjectShadows(sp);
736+ float pd = frg.shdH.z + 0.05f * vSHD[3];
737+ fShadow = 1.0f - SampleShadows(sp, pd);
703738 }
704739 #endif
705740
diff -r 34ff09c1e781 -r 77ed6a7657b6 Orbitersdk/D3D9Client/Surfmgr2.cpp
--- a/Orbitersdk/D3D9Client/Surfmgr2.cpp Tue Nov 05 18:02:28 2019 +0000
+++ b/Orbitersdk/D3D9Client/Surfmgr2.cpp Wed Nov 06 01:41:33 2019 +0000
@@ -755,9 +755,9 @@
755755
756756 if (sqrt(D3DXVec3Dot(&bc, &bc) - x*x) < (shd->rad + mesh->bsRad)) {
757757 float s = float(shd->size);
758- float qw = 1.0f / float(Config->ShadowMapSize);
758+ float sr = 2.0f * shd->rad / s;
759759 HR(Shader->SetMatrix(TileManager2Base::smLVP, &shd->mViewProj));
760- HR(Shader->SetVector(TileManager2Base::svSHD, &D3DXVECTOR4(s, 1.0f / s, qw, 0)));
760+ HR(Shader->SetVector(TileManager2Base::svSHD, &D3DXVECTOR4(sr, 1.0f / s, 0, 1.0f / shd->depth)));
761761 HR(Shader->SetTexture(TileManager2Base::stShadowMap, shd->pShadowMap));
762762 HR(Shader->SetBool(TileManager2Base::sbShadows, true));
763763 }
diff -r 34ff09c1e781 -r 77ed6a7657b6 Orbitersdk/D3D9Client/VVessel.cpp
--- a/Orbitersdk/D3D9Client/VVessel.cpp Tue Nov 05 18:02:28 2019 +0000
+++ b/Orbitersdk/D3D9Client/VVessel.cpp Wed Nov 06 01:41:33 2019 +0000
@@ -665,15 +665,13 @@
665665
666666 float s = float(shd->size);
667667 float sr = 2.0f * shd->rad / s;
668- float qw = 1.0f / float(Config->ShadowMapSize);
669668
670669 HR(D3D9Effect::FX->SetBool(D3D9Effect::eEnvMapEnable, false));
671670 HR(D3D9Effect::FX->SetMatrix(D3D9Effect::eLVP, &shd->mViewProj));
672671
673672 if (shd->pShadowMap && (scn->GetRenderPass() == RENDERPASS_MAINSCENE)) {
674673 HR(D3D9Effect::FX->SetTexture(D3D9Effect::eShadowMap, shd->pShadowMap));
675- //HR(D3D9Effect::FX->SetVector(D3D9Effect::eSHD, &D3DXVECTOR4(sr, 1.0f/s, float(oapiRand()), float(CamDist()))));
676- HR(D3D9Effect::FX->SetVector(D3D9Effect::eSHD, &D3DXVECTOR4(sr, 1.0f / s, float(oapiRand()), 1.0f/shd->depth)));
674+ HR(D3D9Effect::FX->SetVector(D3D9Effect::eSHD, &D3DXVECTOR4(sr, 1.0f / s, float(oapiRand()), 1.0f / shd->depth)));
677675 HR(D3D9Effect::FX->SetBool(D3D9Effect::eShadowToggle, true));
678676 }
679677 else {
Show on old repository browser