2
0
Эх сурвалжийг харах

ShaderGenerator: use shadow map filtering for point light shadows

We were never able to use this because of bugs in the Cg Toolkit, but now that we're no longer using that, we're free to use it.
rdb 5 жил өмнө
parent
commit
511d66d261

+ 7 - 3
panda/src/display/graphicsStateGuardian.cxx

@@ -3494,9 +3494,13 @@ get_dummy_shadow_map(Texture::TextureType texture_type) const {
       dummy_cube = new Texture("dummy-shadow-cube");
       dummy_cube = new Texture("dummy-shadow-cube");
       dummy_cube->setup_cube_map(1, Texture::T_unsigned_byte, Texture::F_depth_component);
       dummy_cube->setup_cube_map(1, Texture::T_unsigned_byte, Texture::F_depth_component);
       dummy_cube->set_clear_color(1);
       dummy_cube->set_clear_color(1);
-      // Note: cube map shadow filtering doesn't seem to work in Cg.
-      dummy_cube->set_minfilter(SamplerState::FT_linear);
-      dummy_cube->set_magfilter(SamplerState::FT_linear);
+      if (get_supports_shadow_filter()) {
+        dummy_cube->set_minfilter(SamplerState::FT_shadow);
+        dummy_cube->set_magfilter(SamplerState::FT_shadow);
+      } else {
+        dummy_cube->set_minfilter(SamplerState::FT_linear);
+        dummy_cube->set_magfilter(SamplerState::FT_linear);
+      }
     }
     }
     return dummy_cube;
     return dummy_cube;
   }
   }

+ 2 - 4
panda/src/pgraphnodes/pointLight.cxx

@@ -208,10 +208,8 @@ setup_shadow_map() {
   _shadow_map->set_clear_color(LColor(1));
   _shadow_map->set_clear_color(LColor(1));
   _shadow_map->set_wrap_u(SamplerState::WM_clamp);
   _shadow_map->set_wrap_u(SamplerState::WM_clamp);
   _shadow_map->set_wrap_v(SamplerState::WM_clamp);
   _shadow_map->set_wrap_v(SamplerState::WM_clamp);
-
-  // Note: cube map shadow filtering doesn't seem to work in Cg.
-  _shadow_map->set_minfilter(SamplerState::FT_linear);
-  _shadow_map->set_magfilter(SamplerState::FT_linear);
+  _shadow_map->set_minfilter(SamplerState::FT_shadow);
+  _shadow_map->set_magfilter(SamplerState::FT_shadow);
 }
 }
 
 
 /**
 /**

+ 15 - 5
panda/src/pgraphnodes/shaderGenerator.cxx

@@ -1051,11 +1051,17 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) {
     const ShaderKey::LightInfo &light = key._lights[i];
     const ShaderKey::LightInfo &light = key._lights[i];
     if (light._flags & ShaderKey::LF_has_shadows) {
     if (light._flags & ShaderKey::LF_has_shadows) {
       if (light._type.is_derived_from(PointLight::get_class_type())) {
       if (light._type.is_derived_from(PointLight::get_class_type())) {
-        text << "\t uniform samplerCUBE shadow_" << i << ",\n";
-      } else if (_use_shadow_filter) {
-        text << "\t uniform sampler2DShadow shadow_" << i << ",\n";
+        if (_use_shadow_filter) {
+          text << "\t uniform samplerCubeShadow shadow_" << i << ",\n";
+        } else {
+          text << "\t uniform samplerCUBE shadow_" << i << ",\n";
+        }
       } else {
       } else {
-        text << "\t uniform sampler2D shadow_" << i << ",\n";
+        if (_use_shadow_filter) {
+          text << "\t uniform sampler2DShadow shadow_" << i << ",\n";
+        } else {
+          text << "\t uniform sampler2D shadow_" << i << ",\n";
+        }
       }
       }
       if (lightcoord_fregs[i] != nullptr) {
       if (lightcoord_fregs[i] != nullptr) {
         text << "\t in float4 l_lightcoord" << i << " : " << lightcoord_fregs[i] << ",\n";
         text << "\t in float4 l_lightcoord" << i << " : " << lightcoord_fregs[i] << ",\n";
@@ -1352,7 +1358,11 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) {
       if (light._flags & ShaderKey::LF_has_shadows) {
       if (light._flags & ShaderKey::LF_has_shadows) {
         text << "\t ldist = max(abs(l_lightcoord" << i << ".x), max(abs(l_lightcoord" << i << ".y), abs(l_lightcoord" << i << ".z)));\n";
         text << "\t ldist = max(abs(l_lightcoord" << i << ".x), max(abs(l_lightcoord" << i << ".y), abs(l_lightcoord" << i << ".z)));\n";
         text << "\t ldist = ((latten.w+lpoint.w)/(latten.w-lpoint.w))+((-2*latten.w*lpoint.w)/(ldist * (latten.w-lpoint.w)));\n";
         text << "\t ldist = ((latten.w+lpoint.w)/(latten.w-lpoint.w))+((-2*latten.w*lpoint.w)/(ldist * (latten.w-lpoint.w)));\n";
-        text << "\t lshad = texCUBE(shadow_" << i << ", l_lightcoord" << i << ".xyz).r >= ldist * 0.5 + 0.5;\n";
+        if (_use_shadow_filter) {
+          text << "\t lshad = shadowCube(shadow_" << i << ", float4(l_lightcoord" << i << ".xyz, ldist * 0.5 + 0.5)).r;\n";
+        } else {
+          text << "\t lshad = texCUBE(shadow_" << i << ", l_lightcoord" << i << ".xyz).r >= ldist * 0.5 + 0.5;\n";
+        }
         text << "\t lcolor *= lshad;\n";
         text << "\t lcolor *= lshad;\n";
         text << "\t lspec *= lshad;\n";
         text << "\t lspec *= lshad;\n";
       }
       }