Need Help with Godot 4.4 Shadow Shaders for VR Therapy Applications
Hello there!
Firstly, i’m a frenchy. In advance, please accept my apologies for bad translating
I’m working on a therapeutic VR project for a friend whose developing an healthcare platform (you can check out their work at https://socialdream.fr), and I’m running into some performance issues with shadow rendering in Godot 4.4.
Background:
The application is designed for anxiety therapy using immersive environments. We need realistic shadows for presence and immersion, but the current implementation is causing frame drops on Quest 2 devices, which is obviously problematic for VR comfort.
Current Setup:
- Godot 4.4.0 stable
- Using Forward+ renderer with clustered lighting
- Custom shader material for ground surfaces
- Directional light with shadow mapping enabled
- Target: 90fps on Quest 2 (currently getting ~60fps with heavy scenes)
Technical Questions:
-
Shadow Map Resolution: I’m currently using 2048x2048 shadow maps. Would reducing to 1024x1024 significantly impact visual quality in VR? The viewing distance is typically 2-10 meters from objects.
-
Shader Optimization: Has anyone experimented with simplified shadow calculations in fragment shaders for VR? I’m thinking about implementing a basic PCF (Percentage Closer Filtering) instead of the default shadow filtering.
-
LOD for Shadows: Is there a way to disable shadow casting for objects beyond a certain distance threshold without affecting the shadow receiving? I couldn’t find a clean solution in the documentation.
Code Snippet (Current Shadow Calculation):
float shadow_calculation(vec4 frag_pos_light_space) {
vec3 proj_coords = frag_pos_light_space.xyz / frag_pos_light_space.w;
proj_coords = proj_coords * 0.5 + 0.5;
float closest_depth = texture(shadow_map, proj_coords.xy).r;
float current_depth = proj_coords.z;
float bias = 0.005;
float shadow = current_depth - bias > closest_depth ? 1.0 : 0.0;
return shadow;
}
The therapeutic context requires stable performance since any stuttering can break immersion and potentially trigger discomfort in patients. I’ve tried adjusting the shadow bias and implementing cascade shadow maps, but I’m wondering if there are VR-specific optimizations I’m missing.
More Context:
The scenes typically include:
- 1-2 directional lights (sun/moon simulation)
- 3-5 spot lights for ambient lighting
- Dynamic objects that need to cast shadows
- Naturalistic environments (forests, beaches, etc.)
Has anyone successfully optimized shadow rendering for therapeutic VR applications? Any suggestions for balancing visual fidelity with performance would be greatly apreciated!
Thanks in advance for any insights!
NB: Forgot to mention we’re also considering switching to mobile renderer, but I’m concerned about loosing some of the visual quality that’s really important for the therapeutic effectiveness.