shader-slang / slang

Making it easier to work with shaders
http://shader-slang.com
Other
2.5k stars 198 forks source link

Combined shadow sampler #5577

Open Ollhax opened 6 days ago

Ollhax commented 6 days ago

I'm trying to do shadowmap rendering for OpenGL and so far I've been relying on the combined samplers that were introduced here, but it doesn't seem like there's one for shadow samplers. There's a SampleCmp function to Sampler2D, but it doesn't appear to work. Basically what I'd need is some way to generate a sampler2DShadow instead of sampler2D - perhaps there should be a Sampler2DShadow variant of Sampler2D?

csyonghe commented 4 days ago

You can use this declaration in your shader file before we added it to the builtin library:

__generic<let sampleCount:int=0, let format:int=0>
typealias Sampler2DShadow = _Texture<
    float,
    __Shape2D,
    0, // isArray
    0, // isMS
    sampleCount,
    0, // access
    1, // isShadow
    1, // isCombined
    format
>;

Note that _Texture is an internal type whose declaration can change in the future, so this is only intended as a temporary workaround.

Ollhax commented 1 day ago

You can use this declaration in your shader file before we added it to the builtin library:

__generic<let sampleCount:int=0, let format:int=0>
typealias Sampler2DShadow = _Texture<
    float,
    __Shape2D,
    0, // isArray
    0, // isMS
    sampleCount,
    0, // access
    1, // isShadow
    1, // isCombined
    format
>;

Note that _Texture is an internal type whose declaration can change in the future, so this is only intended as a temporary workaround.

Thank you, that worked splendidly!