From: HelixPilot@pm.me   
      
   On 15/10/2025 00:00, atray wrote:   
   >> and finally fix my awful shadows   
   > Tell me about your shadows! I've been swinging at enginedev for a decade and   
   I can never bother past cascade shadows. It sounds to me like you've gotten   
   pretty fantastically into it so far. Oh! Do you fall into the same problem I   
   always have of memory-   
   golf?   
   > All the time in engine dev I end up using the bare minimum which makes the   
   whole thing so awful to look at. I'll use 256px maps for lights lol.   
   > Don't mean to be too chatty, just excited to make conversation. Tell me   
   about your shadows.   
      
   Ha, well thats kinda why they are awful at the moment, not even really   
   as far as CSM. Literally just very simple occlusion shadows that are   
   then passed to the PBRLightingShader as a stencil and then run through a   
   function that looks like this:   
      
   fn ShadowFactor(worldPosition: vec3, lightData: LightData,   
   shadowIndex: u32) -> f32 {   
    // Shadows   
    var shadow: f32 = 1.0;   
    var visibility: f32 = 0.0;   
    let shadowCoord: vec4 = lightData.lightVPMatrix *   
   vec4(worldPosition, 1.0);   
    var shadowCoordW: vec3 = shadowCoord.xyz / shadowCoord.www;   
    let shadowDepthTextureSize: vec2 =   
   textureDimensions(uTextureShadowBuffer, shadowIndex);   
    let oneOverShadowDepthTextureSize: f32 = 1.0 /   
   f32(shadowDepthTextureSize.x);   
    for (var y=-1; y<=1; y++) {   
    for (var x=-1; x<=1; x++) {   
    let offset = vec2(f32(x), f32(y)) * oneOverShadowDepthTextureSize;   
    visibility += textureSampleCompare(   
    uTextureShadowBuffer,   
    uSamplerShadow,   
    ((vec2(shadowCoordW.x, 0 - shadowCoordW.y) + 1.0) * 0.5) + offset,   
    shadowIndex,   
    shadowCoordW.z - ShadowBias   
    );   
    }   
    }   
    visibility /= 9.0;   
    shadow *= visibility;   
    return shadow;   
   }   
      
      
   I originally came at this project with absolutely no experience in   
   graphics programming so WGSL is my first shader language. In a lot of   
   cases though I've managed to adopt OpenGL glsl tutorials into WebGPU and   
   WGSL.   
      
   As far as memory golf is concerned, not really because TypeScript (JS)   
   runs in the browser anyway, so its never going to be as efficient as   
   something written in C and when 32Gb of ram is pretty commonplace its   
   not one of my prime concerns. My main design goals for the project is   
   for it to be easily run by anyone with a web browser, meaning you don't   
   have to download a client to access the world.   
      
   That said I try to be as efficient as possible and one of the things I'm   
   paying for currently is that when I first wrote the graphics system I   
   made the stupid decision of each object in a scene having its own shader   
   pipeline. :)   
      
   So recently rewrote a huge chunk of the graphics system to share one   
   shader across all objects in the scene.   
      
   HP   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|