Skip to content

Commit 0958290

Browse files
gabrieldelacruzGitHub Enterprise
authored andcommitted
Add support for Gradient sampling with and without gradient mode #100
1 parent eb830bb commit 0958290

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

com.unity.visualeffectgraph/Shaders/VFXCommon.hlsl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,12 +444,24 @@ float HalfTexelOffset(float f)
444444
return (a * f) + b;
445445
}
446446

447-
float4 SampleGradient(float v, float u)
447+
float SnapToTexel(float f)
448448
{
449-
float2 uv = float2(HalfTexelOffset(saturate(u)), v);
449+
const float kInvTextureWidth = 1.0f / 128.0f;
450+
return f - fmod(f, kInvTextureWidth) + 0.5f * kInvTextureWidth;
451+
}
452+
453+
float4 SampleGradient(float2 gradientData, float u)
454+
{
455+
float2 uv = float2(HalfTexelOffset(saturate(u)), gradientData.x);
456+
if (gradientData.y > 0.5f) uv.x = SnapToTexel(uv.x);
450457
return bakedTexture.SampleLevel(samplerbakedTexture, uv, 0);
451458
}
452459

460+
float4 SampleGradient(float gradientData, float u)
461+
{
462+
return SampleGradient(float2(gradientData, 0.0f), u);
463+
}
464+
453465
float SampleCurve(float4 curveData, float u)
454466
{
455467
float uNorm = (u * curveData.x) + curveData.y;

0 commit comments

Comments
 (0)