Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GLSL: Add option to emulate alpha test #2412

Closed
wants to merge 1 commit into from

Conversation

rdb
Copy link
Contributor

@rdb rdb commented Nov 11, 2024

Adds an option to add an emulated alpha test for back-ends not supporting it, which I imagine is a common enough manipulation that it might be worth putting it in SPIRV-Cross, similar to the coordinate system fix-ups. Always tests against the output with location 0, if present. Adds a uniform float variable called SPIRV_Cross_AlphaTestRef for the reference value. Alpha test is done at every return point from the main entry point.

Example generated shader:

#version 460

uniform float SPIRV_Cross_AlphaTestRef;
layout(location = 4) uniform sampler2D p4;
layout(location = 5) uniform vec4 p5;

layout(location = 0) out vec4 o0;
layout(location = 0) in vec3 i1_0;
layout(location = 1) in vec4 i1_1;

void main()
{
    o0 = textureProj(p4, i1_0);
    o0 += p5;
    o0 *= i1_1;
    if (o0.a <= SPIRV_Cross_AlphaTestRef) discard;
}

I can work on unit tests if you like, but I wanted confirmation first whether you think this is in-scope for SPIRV-Cross.

If not, then maybe we can discuss the best way I can hook into SPIRV-Cross to add the test on the engine side (eg. by allowing a custom name for the main entry point so I can concatenate a wrapper).

@rdb rdb force-pushed the emulate-alpha-test branch from 9e8a3b6 to c4e5e3e Compare November 11, 2024 13:48
@HansKristian-Work
Copy link
Contributor

HansKristian-Work commented Nov 11, 2024

This is too gross to upstream.

emulated alpha test for back-ends not supporting it

Fixed function alpha testing does not exist in any modern API. What is the use case here?

allowing a custom name for the main entry point so I can concatenate a wrapper

That is simple enough. A simple option to replace the GLSL entry point name with something else isn't too invasive. It won't work for HLSL/MSL due to the nature of those languages where they must consume all arguments, but if this is GLSL only, then ... sure.

Something more flexible is probably an option to just use the entry point name assigned to the entry point ID and then the GLSL option is to use entry point name instead of hardcoded "main".

@rdb
Copy link
Contributor Author

rdb commented Nov 11, 2024

Clear.

GL compat profile, even as of 4.6, still has fixed function alpha testing that can be enabled (functioning like this PR), typically the driver injects the extra kill into the shader, the use case for this was emulating that behaviour in core profile / GLES to achieve feature parity between our renderers.

@rdb rdb closed this Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants