Skip to content

Commit

Permalink
Merge pull request #307 from vsg-dev/VSG_ALPHA_TEST
Browse files Browse the repository at this point in the history
Added VSG_ALPHA_TEST #pragma(tic) shadow composition define to control whether the alpha test discard code path in fragment shaders is run.
  • Loading branch information
robertosfield authored Apr 19, 2024
2 parents e864d55 + b6f94f7 commit f0bfe39
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 21 deletions.
10 changes: 4 additions & 6 deletions data/shaders/standard_flat_shaded.frag
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#version 450
#extension GL_ARB_separate_shader_objects : enable
#pragma import_defines (VSG_POINT_SPRITE, VSG_DIFFUSE_MAP, VSG_GREYSCALE_DIFFUSE_MAP)
#pragma import_defines (VSG_POINT_SPRITE, VSG_DIFFUSE_MAP, VSG_GREYSCALE_DIFFUSE_MAP, VSG_ALPHA_TEST)

#define VIEW_DESCRIPTOR_SET 0
#define MATERIAL_DESCRIPTOR_SET 1
Expand Down Expand Up @@ -44,11 +44,9 @@ void main()
#endif
#endif

if (material.alphaMask == 1.0f)
{
if (diffuseColor.a < material.alphaMaskCutoff)
discard;
}
#ifdef VSG_ALPHA_TEST
if (material.alphaMask == 1.0f && diffuseColor.a < material.alphaMaskCutoff) discard;
#endif

outColor = diffuseColor;
}
10 changes: 4 additions & 6 deletions data/shaders/standard_pbr.frag
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#version 450
#extension GL_ARB_separate_shader_objects : enable
#pragma import_defines (VSG_DIFFUSE_MAP, VSG_GREYSCALE_DIFFUSE_MAP, VSG_EMISSIVE_MAP, VSG_LIGHTMAP_MAP, VSG_NORMAL_MAP, VSG_METALLROUGHNESS_MAP, VSG_SPECULAR_MAP, VSG_TWO_SIDED_LIGHTING, VSG_WORKFLOW_SPECGLOSS, VSG_SHADOWS_PCSS, VSG_SHADOWS_SOFT, VSG_SHADOWS_HARD, SHADOWMAP_DEBUG)
#pragma import_defines (VSG_DIFFUSE_MAP, VSG_GREYSCALE_DIFFUSE_MAP, VSG_EMISSIVE_MAP, VSG_LIGHTMAP_MAP, VSG_NORMAL_MAP, VSG_METALLROUGHNESS_MAP, VSG_SPECULAR_MAP, VSG_TWO_SIDED_LIGHTING, VSG_WORKFLOW_SPECGLOSS, VSG_SHADOWS_PCSS, VSG_SHADOWS_SOFT, VSG_SHADOWS_HARD, SHADOWMAP_DEBUG, VSG_ALPHA_TEST)

// define by default for backwards compatibility
#define VSG_SHADOWS_HARD
Expand Down Expand Up @@ -334,11 +334,9 @@ void main()
baseColor = vertexColor * pbr.baseColorFactor;
#endif

if (pbr.alphaMask == 1.0f)
{
if (baseColor.a < pbr.alphaMaskCutoff)
discard;
}
#ifdef VSG_ALPHA_TEST
if (material.alphaMask == 1.0f && diffuseColor.a < material.alphaMaskCutoff) discard;
#endif

#ifdef VSG_WORKFLOW_SPECGLOSS
#ifdef VSG_DIFFUSE_MAP
Expand Down
10 changes: 4 additions & 6 deletions data/shaders/standard_phong.frag
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#version 450
#extension GL_ARB_separate_shader_objects : enable
#pragma import_defines (VSG_POINT_SPRITE, VSG_DIFFUSE_MAP, VSG_GREYSCALE_DIFFUSE_MAP, VSG_EMISSIVE_MAP, VSG_LIGHTMAP_MAP, VSG_NORMAL_MAP, VSG_SPECULAR_MAP, VSG_TWO_SIDED_LIGHTING, VSG_SHADOWS_PCSS, VSG_SHADOWS_SOFT, VSG_SHADOWS_HARD, SHADOWMAP_DEBUG)
#pragma import_defines (VSG_POINT_SPRITE, VSG_DIFFUSE_MAP, VSG_GREYSCALE_DIFFUSE_MAP, VSG_EMISSIVE_MAP, VSG_LIGHTMAP_MAP, VSG_NORMAL_MAP, VSG_SPECULAR_MAP, VSG_TWO_SIDED_LIGHTING, VSG_SHADOWS_PCSS, VSG_SHADOWS_SOFT, VSG_SHADOWS_HARD, SHADOWMAP_DEBUG, VSG_ALPHA_TEST)

// define by default for backwards compatibility
#define VSG_SHADOWS_HARD
Expand Down Expand Up @@ -136,11 +136,9 @@ void main()
float shininess = material.shininess;
float ambientOcclusion = 1.0;

if (material.alphaMask == 1.0f)
{
if (diffuseColor.a < material.alphaMaskCutoff)
discard;
}
#ifdef VSG_ALPHA_TEST
if (material.alphaMask == 1.0f && diffuseColor.a < material.alphaMaskCutoff) discard;
#endif

#ifdef VSG_EMISSIVE_MAP
emissiveColor *= texture(emissiveMap, texCoord0.st);
Expand Down
5 changes: 5 additions & 0 deletions examples/nodes/vsgshadow/vsgshadow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,11 @@ int main(int argc, char** argv)
shadowSettings = vsg::HardShadows::create(numShadowMapsPerLight);
}

if (arguments.read({"--alpha-test", "--at"}))
{
shaderHints->defines.insert("VSG_ALPHA_TEST");
}

bool overrideShadowSettings = arguments.read("--override");
if (overrideShadowSettings)
{
Expand Down
2 changes: 1 addition & 1 deletion examples/utils/vsgshaderset/flat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ vsg::ref_ptr<vsg::ShaderSet> flat_ShaderSet(vsg::ref_ptr<const vsg::Options> opt

shaderSet->addPushConstantRange("pc", "", VK_SHADER_STAGE_VERTEX_BIT, 0, 128);

shaderSet->optionalDefines = {"VSG_POINT_SPRITE", "VSG_GREYSCALE_DIFFUSE_MAP"};
shaderSet->optionalDefines = {"VSG_POINT_SPRITE", "VSG_GREYSCALE_DIFFUSE_MAP", "VSG_ALPHA_TEST"};

shaderSet->definesArrayStates.push_back(vsg::DefinesArrayState{{"VSG_INSTANCE_POSITIONS", "VSG_DISPLACEMENT_MAP"}, vsg::PositionAndDisplacementMapArrayState::create()});
shaderSet->definesArrayStates.push_back(vsg::DefinesArrayState{{"VSG_INSTANCE_POSITIONS"}, vsg::PositionArrayState::create()});
Expand Down
2 changes: 1 addition & 1 deletion examples/utils/vsgshaderset/pbr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ vsg::ref_ptr<vsg::ShaderSet> pbr_ShaderSet(vsg::ref_ptr<const vsg::Options> opti
shaderSet->addDescriptorBinding("shadowMapShadowSampler", "", VIEW_DESCRIPTOR_SET, 4, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr);

// additional defines
shaderSet->optionalDefines = {"VSG_GREYSCALE_DIFFUSE_MAP", "VSG_TWO_SIDED_LIGHTING", "VSG_WORKFLOW_SPECGLOSS", "VSG_SHADOWS_PCSS", "VSG_SHADOWS_SOFT", "VSG_SHADOWS_HARD", "SHADOWMAP_DEBUG" };
shaderSet->optionalDefines = {"VSG_GREYSCALE_DIFFUSE_MAP", "VSG_TWO_SIDED_LIGHTING", "VSG_WORKFLOW_SPECGLOSS", "VSG_SHADOWS_PCSS", "VSG_SHADOWS_SOFT", "VSG_SHADOWS_HARD", "SHADOWMAP_DEBUG", "VSG_ALPHA_TEST" };

shaderSet->addPushConstantRange("pc", "", VK_SHADER_STAGE_VERTEX_BIT, 0, 128);

Expand Down
2 changes: 1 addition & 1 deletion examples/utils/vsgshaderset/phong.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ vsg::ref_ptr<vsg::ShaderSet> phong_ShaderSet(vsg::ref_ptr<const vsg::Options> op

shaderSet->addPushConstantRange("pc", "", VK_SHADER_STAGE_VERTEX_BIT, 0, 128);

shaderSet->optionalDefines = {"VSG_GREYSCALE_DIFFUSE_MAP", "VSG_TWO_SIDED_LIGHTING", "VSG_POINT_SPRITE", "VSG_SHADOWS_PCSS", "VSG_SHADOWS_SOFT", "VSG_SHADOWS_HARD", "SHADOWMAP_DEBUG" };
shaderSet->optionalDefines = {"VSG_GREYSCALE_DIFFUSE_MAP", "VSG_TWO_SIDED_LIGHTING", "VSG_POINT_SPRITE", "VSG_SHADOWS_PCSS", "VSG_SHADOWS_SOFT", "VSG_SHADOWS_HARD", "SHADOWMAP_DEBUG", "VSG_ALPHA_TEST" };

shaderSet->definesArrayStates.push_back(vsg::DefinesArrayState{{"VSG_INSTANCE_POSITIONS", "VSG_DISPLACEMENT_MAP"}, vsg::PositionAndDisplacementMapArrayState::create()});
shaderSet->definesArrayStates.push_back(vsg::DefinesArrayState{{"VSG_INSTANCE_POSITIONS"}, vsg::PositionArrayState::create()});
Expand Down

0 comments on commit f0bfe39

Please sign in to comment.