HLSL: Fix texProj in legacy HLSL.
This commit is contained in:
parent
9e3df69d4e
commit
d13dc0ce47
@ -0,0 +1,32 @@
|
||||
uniform sampler2D uSampler;
|
||||
|
||||
static float4 FragColor;
|
||||
static float2 vUV;
|
||||
|
||||
struct SPIRV_Cross_Input
|
||||
{
|
||||
float2 vUV : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct SPIRV_Cross_Output
|
||||
{
|
||||
float4 FragColor : COLOR0;
|
||||
};
|
||||
|
||||
void frag_main()
|
||||
{
|
||||
float3 _23 = float3(vUV, 5.0f);
|
||||
FragColor = tex2Dproj(uSampler, float4(_23.xy, 0.0, _23.z));
|
||||
FragColor += tex2Dbias(uSampler, float4(vUV, 0.0, 3.0f));
|
||||
FragColor += tex2Dlod(uSampler, float4(vUV, 0.0, 2.0f));
|
||||
FragColor += tex2Dgrad(uSampler, vUV, 4.0f.xx, 5.0f.xx);
|
||||
}
|
||||
|
||||
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
|
||||
{
|
||||
vUV = stage_input.vUV;
|
||||
frag_main();
|
||||
SPIRV_Cross_Output stage_output;
|
||||
stage_output.FragColor = float4(FragColor);
|
||||
return stage_output;
|
||||
}
|
32
reference/shaders-hlsl/frag/legacy-tex-modifiers.sm30.frag
Normal file
32
reference/shaders-hlsl/frag/legacy-tex-modifiers.sm30.frag
Normal file
@ -0,0 +1,32 @@
|
||||
uniform sampler2D uSampler;
|
||||
|
||||
static float4 FragColor;
|
||||
static float2 vUV;
|
||||
|
||||
struct SPIRV_Cross_Input
|
||||
{
|
||||
float2 vUV : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct SPIRV_Cross_Output
|
||||
{
|
||||
float4 FragColor : COLOR0;
|
||||
};
|
||||
|
||||
void frag_main()
|
||||
{
|
||||
float3 _23 = float3(vUV, 5.0f);
|
||||
FragColor = tex2Dproj(uSampler, float4(_23.xy, 0.0, _23.z));
|
||||
FragColor += tex2Dbias(uSampler, float4(vUV, 0.0, 3.0f));
|
||||
FragColor += tex2Dlod(uSampler, float4(vUV, 0.0, 2.0f));
|
||||
FragColor += tex2Dgrad(uSampler, vUV, 4.0f.xx, 5.0f.xx);
|
||||
}
|
||||
|
||||
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
|
||||
{
|
||||
vUV = stage_input.vUV;
|
||||
frag_main();
|
||||
SPIRV_Cross_Output stage_output;
|
||||
stage_output.FragColor = float4(FragColor);
|
||||
return stage_output;
|
||||
}
|
13
shaders-hlsl/frag/legacy-tex-modifiers.sm30.frag
Normal file
13
shaders-hlsl/frag/legacy-tex-modifiers.sm30.frag
Normal file
@ -0,0 +1,13 @@
|
||||
#version 450
|
||||
|
||||
layout(location = 0) in vec2 vUV;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 0) uniform sampler2D uSampler;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = textureProj(uSampler, vec3(vUV, 5.0));
|
||||
FragColor += texture(uSampler, vUV, 3.0);
|
||||
FragColor += textureLod(uSampler, vUV, 2.0);
|
||||
FragColor += textureGrad(uSampler, vUV, vec2(4.0), vec2(5.0));
|
||||
}
|
@ -2946,24 +2946,37 @@ void CompilerHLSL::emit_texture_op(const Instruction &i, bool sparse)
|
||||
if (proj && hlsl_options.shader_model >= 40) // Legacy HLSL has "proj" operations which do this for us.
|
||||
coord_expr = coord_expr + " / " + to_extract_component_expression(coord, coord_components);
|
||||
|
||||
if (hlsl_options.shader_model < 40 && lod)
|
||||
if (hlsl_options.shader_model < 40)
|
||||
{
|
||||
string coord_filler;
|
||||
for (uint32_t size = coord_components; size < 3; ++size)
|
||||
uint32_t modifier_count = 0;
|
||||
|
||||
if (lod)
|
||||
{
|
||||
for (uint32_t size = coord_components; size < 3; ++size)
|
||||
coord_filler += ", 0.0";
|
||||
}
|
||||
coord_expr = "float4(" + coord_expr + coord_filler + ", " + to_expression(lod) + ")";
|
||||
modifier_count++;
|
||||
}
|
||||
|
||||
if (hlsl_options.shader_model < 40 && bias)
|
||||
if (bias)
|
||||
{
|
||||
string coord_filler;
|
||||
for (uint32_t size = coord_components; size < 3; ++size)
|
||||
{
|
||||
coord_filler += ", 0.0";
|
||||
}
|
||||
coord_expr = "float4(" + coord_expr + coord_filler + ", " + to_expression(bias) + ")";
|
||||
modifier_count++;
|
||||
}
|
||||
|
||||
if (proj)
|
||||
{
|
||||
for (uint32_t size = coord_components; size < 3; ++size)
|
||||
coord_filler += ", 0.0";
|
||||
coord_expr = "float4(" + coord_expr + coord_filler + ", " + to_extract_component_expression(coord, coord_components) + ")";
|
||||
modifier_count++;
|
||||
}
|
||||
|
||||
if (modifier_count > 1)
|
||||
SPIRV_CROSS_THROW("Legacy HLSL can only use one of lod/bias/proj modifiers.");
|
||||
}
|
||||
|
||||
if (op == OpImageFetch)
|
||||
|
Loading…
Reference in New Issue
Block a user