mirror of
https://github.com/KhronosGroup/SPIRV-Cross.git
synced 2024-11-09 22:00:05 +00:00
Fix textureProj with shadow on GLSL.
This commit is contained in:
parent
24c35e3fb3
commit
cbcaca5a39
66
reference/shaders-hlsl/frag/texture-proj-shadow.frag
Normal file
66
reference/shaders-hlsl/frag/texture-proj-shadow.frag
Normal file
@ -0,0 +1,66 @@
|
||||
Texture1D<float4> uShadow1D : register(t0);
|
||||
SamplerComparisonState _uShadow1D_sampler : register(s0);
|
||||
Texture2D<float4> uShadow2D : register(t1);
|
||||
SamplerComparisonState _uShadow2D_sampler : register(s1);
|
||||
Texture1D<float4> uSampler1D : register(t2);
|
||||
SamplerState _uSampler1D_sampler : register(s2);
|
||||
Texture2D<float4> uSampler2D : register(t3);
|
||||
SamplerState _uSampler2D_sampler : register(s3);
|
||||
Texture3D<float4> uSampler3D : register(t4);
|
||||
SamplerState _uSampler3D_sampler : register(s4);
|
||||
|
||||
static float FragColor;
|
||||
static float4 vClip4;
|
||||
static float2 vClip2;
|
||||
static float3 vClip3;
|
||||
|
||||
struct SPIRV_Cross_Input
|
||||
{
|
||||
float3 vClip3 : TEXCOORD0;
|
||||
float4 vClip4 : TEXCOORD1;
|
||||
float2 vClip2 : TEXCOORD2;
|
||||
};
|
||||
|
||||
struct SPIRV_Cross_Output
|
||||
{
|
||||
float FragColor : SV_Target0;
|
||||
};
|
||||
|
||||
float SPIRV_Cross_projectTextureCoordinate(float2 coord)
|
||||
{
|
||||
return coord.x / coord.y;
|
||||
}
|
||||
|
||||
float2 SPIRV_Cross_projectTextureCoordinate(float3 coord)
|
||||
{
|
||||
return float2(coord.x, coord.y) / coord.z;
|
||||
}
|
||||
|
||||
float3 SPIRV_Cross_projectTextureCoordinate(float4 coord)
|
||||
{
|
||||
return float3(coord.x, coord.y, coord.z) / coord.w;
|
||||
}
|
||||
|
||||
void frag_main()
|
||||
{
|
||||
float4 _20 = vClip4;
|
||||
_20.y = vClip4.w;
|
||||
FragColor = uShadow1D.SampleCmp(_uShadow1D_sampler, SPIRV_Cross_projectTextureCoordinate(_20.xy), vClip4.z);
|
||||
float4 _30 = vClip4;
|
||||
_30.z = vClip4.w;
|
||||
FragColor = uShadow2D.SampleCmp(_uShadow2D_sampler, SPIRV_Cross_projectTextureCoordinate(_30.xyz), vClip4.z);
|
||||
FragColor = uSampler1D.Sample(_uSampler1D_sampler, SPIRV_Cross_projectTextureCoordinate(vClip2)).x;
|
||||
FragColor = uSampler2D.Sample(_uSampler2D_sampler, SPIRV_Cross_projectTextureCoordinate(vClip3)).x;
|
||||
FragColor = uSampler3D.Sample(_uSampler3D_sampler, SPIRV_Cross_projectTextureCoordinate(vClip4)).x;
|
||||
}
|
||||
|
||||
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
|
||||
{
|
||||
vClip4 = stage_input.vClip4;
|
||||
vClip2 = stage_input.vClip2;
|
||||
vClip3 = stage_input.vClip3;
|
||||
frag_main();
|
||||
SPIRV_Cross_Output stage_output;
|
||||
stage_output.FragColor = FragColor;
|
||||
return stage_output;
|
||||
}
|
32
reference/shaders-msl/frag/texture-proj-shadow.frag
Normal file
32
reference/shaders-msl/frag/texture-proj-shadow.frag
Normal file
@ -0,0 +1,32 @@
|
||||
#include <metal_stdlib>
|
||||
#include <simd/simd.h>
|
||||
|
||||
using namespace metal;
|
||||
|
||||
struct main0_in
|
||||
{
|
||||
float4 vClip4 [[user(locn1)]];
|
||||
float3 vClip3 [[user(locn0)]];
|
||||
float2 vClip2 [[user(locn2)]];
|
||||
};
|
||||
|
||||
struct main0_out
|
||||
{
|
||||
float FragColor [[color(0)]];
|
||||
};
|
||||
|
||||
fragment main0_out main0(main0_in in [[stage_in]], unknown_depth_texture_type<float> uShadow1D [[texture(0)]], sampler uShadow1DSmplr [[sampler(0)]], depth2d<float> uShadow2D [[texture(1)]], sampler uShadow2DSmplr [[sampler(1)]], texture1d<float> uSampler1D [[texture(2)]], sampler uSampler1DSmplr [[sampler(2)]], texture2d<float> uSampler2D [[texture(3)]], sampler uSampler2DSmplr [[sampler(3)]], texture3d<float> uSampler3D [[texture(4)]], sampler uSampler3DSmplr [[sampler(4)]])
|
||||
{
|
||||
main0_out out = {};
|
||||
float4 _20 = in.vClip4;
|
||||
_20.y = in.vClip4.w;
|
||||
out.FragColor = uShadow1D.sample_compare(uShadow1DSmplr, _20.x / _20.y, in.vClip4.z);
|
||||
float4 _30 = in.vClip4;
|
||||
_30.z = in.vClip4.w;
|
||||
out.FragColor = uShadow2D.sample_compare(uShadow2DSmplr, _30.xy / _30.z, in.vClip4.z);
|
||||
out.FragColor = uSampler1D.sample(uSampler1DSmplr, in.vClip2.x / in.vClip2.y).x;
|
||||
out.FragColor = uSampler2D.sample(uSampler2DSmplr, in.vClip3.xy / in.vClip3.z).x;
|
||||
out.FragColor = uSampler3D.sample(uSampler3DSmplr, in.vClip4.xyz / in.vClip4.w).x;
|
||||
return out;
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
#version 450
|
||||
|
||||
layout(binding = 0) uniform sampler1DShadow uShadow1D;
|
||||
layout(binding = 1) uniform sampler2DShadow uShadow2D;
|
||||
layout(binding = 2) uniform sampler1D uSampler1D;
|
||||
layout(binding = 3) uniform sampler2D uSampler2D;
|
||||
layout(binding = 4) uniform sampler3D uSampler3D;
|
||||
|
||||
layout(location = 0) out float FragColor;
|
||||
layout(location = 1) in vec4 vClip4;
|
||||
layout(location = 2) in vec2 vClip2;
|
||||
layout(location = 0) in vec3 vClip3;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 _20 = vClip4;
|
||||
_20.y = vClip4.w;
|
||||
FragColor = textureProj(uShadow1D, vec4(_20.x, 0.0, vClip4.z, _20.y));
|
||||
vec4 _30 = vClip4;
|
||||
_30.z = vClip4.w;
|
||||
FragColor = textureProj(uShadow2D, vec4(_30.xy, vClip4.z, _30.z));
|
||||
FragColor = textureProj(uSampler1D, vClip2).x;
|
||||
FragColor = textureProj(uSampler2D, vClip3).x;
|
||||
FragColor = textureProj(uSampler3D, vClip4).x;
|
||||
}
|
||||
|
21
shaders-hlsl/frag/texture-proj-shadow.frag
Normal file
21
shaders-hlsl/frag/texture-proj-shadow.frag
Normal file
@ -0,0 +1,21 @@
|
||||
#version 450
|
||||
|
||||
layout(binding = 0) uniform sampler1DShadow uShadow1D;
|
||||
layout(binding = 1) uniform sampler2DShadow uShadow2D;
|
||||
layout(binding = 2) uniform sampler1D uSampler1D;
|
||||
layout(binding = 3) uniform sampler2D uSampler2D;
|
||||
layout(binding = 4) uniform sampler3D uSampler3D;
|
||||
|
||||
layout(location = 0) out float FragColor;
|
||||
layout(location = 0) in vec3 vClip3;
|
||||
layout(location = 1) in vec4 vClip4;
|
||||
layout(location = 2) in vec2 vClip2;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = textureProj(uShadow1D, vClip4);
|
||||
FragColor = textureProj(uShadow2D, vClip4);
|
||||
FragColor = textureProj(uSampler1D, vClip2).x;
|
||||
FragColor = textureProj(uSampler2D, vClip3).x;
|
||||
FragColor = textureProj(uSampler3D, vClip4).x;
|
||||
}
|
21
shaders-msl/frag/texture-proj-shadow.frag
Normal file
21
shaders-msl/frag/texture-proj-shadow.frag
Normal file
@ -0,0 +1,21 @@
|
||||
#version 450
|
||||
|
||||
layout(binding = 0) uniform sampler1DShadow uShadow1D;
|
||||
layout(binding = 1) uniform sampler2DShadow uShadow2D;
|
||||
layout(binding = 2) uniform sampler1D uSampler1D;
|
||||
layout(binding = 3) uniform sampler2D uSampler2D;
|
||||
layout(binding = 4) uniform sampler3D uSampler3D;
|
||||
|
||||
layout(location = 0) out float FragColor;
|
||||
layout(location = 0) in vec3 vClip3;
|
||||
layout(location = 1) in vec4 vClip4;
|
||||
layout(location = 2) in vec2 vClip2;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = textureProj(uShadow1D, vClip4);
|
||||
FragColor = textureProj(uShadow2D, vClip4);
|
||||
FragColor = textureProj(uSampler1D, vClip2).x;
|
||||
FragColor = textureProj(uSampler2D, vClip3).x;
|
||||
FragColor = textureProj(uSampler3D, vClip4).x;
|
||||
}
|
21
shaders/desktop-only/frag/texture-proj-shadow.desktop.frag
Normal file
21
shaders/desktop-only/frag/texture-proj-shadow.desktop.frag
Normal file
@ -0,0 +1,21 @@
|
||||
#version 450
|
||||
|
||||
layout(binding = 0) uniform sampler1DShadow uShadow1D;
|
||||
layout(binding = 1) uniform sampler2DShadow uShadow2D;
|
||||
layout(binding = 2) uniform sampler1D uSampler1D;
|
||||
layout(binding = 3) uniform sampler2D uSampler2D;
|
||||
layout(binding = 4) uniform sampler3D uSampler3D;
|
||||
|
||||
layout(location = 0) out float FragColor;
|
||||
layout(location = 0) in vec3 vClip3;
|
||||
layout(location = 1) in vec4 vClip4;
|
||||
layout(location = 2) in vec2 vClip2;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = textureProj(uShadow1D, vClip4);
|
||||
FragColor = textureProj(uShadow2D, vClip4);
|
||||
FragColor = textureProj(uSampler1D, vClip2).x;
|
||||
FragColor = textureProj(uSampler2D, vClip3).x;
|
||||
FragColor = textureProj(uSampler3D, vClip4).x;
|
||||
}
|
@ -3019,7 +3019,7 @@ string CompilerGLSL::to_function_name(uint32_t, const SPIRType &imgtype, bool is
|
||||
}
|
||||
|
||||
// Returns the function args for a texture sampling function for the specified image and sampling characteristics.
|
||||
string CompilerGLSL::to_function_args(uint32_t img, const SPIRType &imgtype, bool, bool, bool, uint32_t coord,
|
||||
string CompilerGLSL::to_function_args(uint32_t img, const SPIRType &imgtype, bool, bool, bool is_proj, uint32_t coord,
|
||||
uint32_t coord_components, uint32_t dref, uint32_t grad_x, uint32_t grad_y,
|
||||
uint32_t lod, uint32_t coffset, uint32_t offset, uint32_t bias, uint32_t comp,
|
||||
uint32_t sample, bool *p_forward)
|
||||
@ -3071,6 +3071,35 @@ string CompilerGLSL::to_function_args(uint32_t img, const SPIRType &imgtype, boo
|
||||
farg_str += ", ";
|
||||
farg_str += to_expression(dref);
|
||||
}
|
||||
else if (is_proj)
|
||||
{
|
||||
// Have to reshuffle so we get vec4(coord, dref, proj), special case.
|
||||
// Other shading languages splits up the arguments for coord and compare value like SPIR-V.
|
||||
// The coordinate type for textureProj shadow is always vec4 even for sampler1DShadow.
|
||||
farg_str += ", vec4(";
|
||||
|
||||
if (imgtype.image.dim == Dim1D)
|
||||
{
|
||||
// Could reuse coord_expr, but we will mess up the temporary usage checking.
|
||||
farg_str += to_enclosed_expression(coord) + ".x";
|
||||
farg_str += ", ";
|
||||
farg_str += "0.0, ";
|
||||
farg_str += to_expression(dref);
|
||||
farg_str += ", ";
|
||||
farg_str += to_enclosed_expression(coord) + ".y)";
|
||||
}
|
||||
else if (imgtype.image.dim == Dim2D)
|
||||
{
|
||||
// Could reuse coord_expr, but we will mess up the temporary usage checking.
|
||||
farg_str += to_enclosed_expression(coord) + (swizz_func ? ".xy()" : ".xy");
|
||||
farg_str += ", ";
|
||||
farg_str += to_expression(dref);
|
||||
farg_str += ", ";
|
||||
farg_str += to_enclosed_expression(coord) + ".z)";
|
||||
}
|
||||
else
|
||||
SPIRV_CROSS_THROW("Invalid type for textureProj with shadow.");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create a composite which merges coord/dref into a single vector.
|
||||
|
Loading…
Reference in New Issue
Block a user