Skip to content

Commit 792c8e5

Browse files
Merge pull request #104 from Unity-Technologies/Add-ParallaxOcclusionMapping
Add parallax occlusion mapping (near working version)
2 parents 58838ae + 2084b62 commit 792c8e5

12 files changed

Lines changed: 189 additions & 61 deletions

File tree

Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/BaseLitUI.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ protected static class Styles
8888
public static GUIContent tessellationFactorTriangleSizeText = new GUIContent("Triangle size", "Desired screen space sized of triangle (in pixel). Smaller value mean smaller triangle.");
8989
public static GUIContent tessellationShapeFactorText = new GUIContent("Shape factor", "Strength of Phong tessellation shape (lerp factor)");
9090
public static GUIContent tessellationBackFaceCullEpsilonText = new GUIContent("Triangle culling Epsilon", "If -1.0 back face culling is enabled for tessellation, higher number mean more aggressive culling and better performance");
91-
public static GUIContent tessellationObjectScaleText = new GUIContent("Enable object scale", "Scale displacement taking into account the object scale");
91+
//public static GUIContent tessellationObjectScaleText = new GUIContent("Enable object scale", "Scale displacement taking into account the object scale");
9292
}
9393

9494
public enum SurfaceType
@@ -241,7 +241,7 @@ protected void FindCommonOptionProperties(MaterialProperty[] props)
241241
tessellationFactorTriangleSize = FindProperty(kTessellationFactorTriangleSize, props, false);
242242
tessellationShapeFactor = FindProperty(kTessellationShapeFactor, props, false);
243243
tessellationBackFaceCullEpsilon = FindProperty(kTessellationBackFaceCullEpsilon, props, false);
244-
tessellationObjectScale = FindProperty(kTessellationObjectScale, props, false);
244+
//tessellationObjectScale = FindProperty(kTessellationObjectScale, props, false);
245245
}
246246

247247
protected void SetupCommonOptionsKeywords(Material material)
@@ -513,8 +513,8 @@ protected virtual void SetupEmissionGIFlags(Material material)
513513
const string kTessellationShapeFactor = "_TessellationShapeFactor";
514514
MaterialProperty tessellationBackFaceCullEpsilon = null;
515515
const string kTessellationBackFaceCullEpsilon = "_TessellationBackFaceCullEpsilon";
516-
MaterialProperty tessellationObjectScale = null;
517-
const string kTessellationObjectScale = "_TessellationObjectScale";
516+
//MaterialProperty tessellationObjectScale = null;
517+
//const string kTessellationObjectScale = "_TessellationObjectScale";
518518

519519
protected static string[] reservedProperties = new string[] { kSurfaceType, kBlendMode, kAlphaCutoff, kAlphaCutoffEnabled, kDoubleSidedMode };
520520

Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitData.hlsl

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ float4 SampleLayerLod(TEXTURE2D_ARGS(layerTex, layerSampler), LayerUV layerUV, f
121121

122122
// TODO: Handle BC5 format, currently this code is for DXT5nm
123123
// THis function below must call UnpackNormalmapRGorAG
124-
float3 SampleNormalLayer(TEXTURE2D_ARGS(layerTex, layerSampler), LayerUV layerUV, float3 weights, float scale)
124+
float3 SampleLayerNormal(TEXTURE2D_ARGS(layerTex, layerSampler), LayerUV layerUV, float3 weights, float scale)
125125
{
126126
if (layerUV.isTriplanar)
127127
{
@@ -143,7 +143,7 @@ float3 SampleNormalLayer(TEXTURE2D_ARGS(layerTex, layerSampler), LayerUV layerUV
143143
}
144144

145145
// This version is for normalmap with AG encoding only (use with details map)
146-
float3 SampleNormalLayerAG(TEXTURE2D_ARGS(layerTex, layerSampler), LayerUV layerUV, float3 weights, float scale)
146+
float3 SampleLayerNormalAG(TEXTURE2D_ARGS(layerTex, layerSampler), LayerUV layerUV, float3 weights, float scale)
147147
{
148148
if (layerUV.isTriplanar)
149149
{
@@ -166,7 +166,7 @@ float3 SampleNormalLayerAG(TEXTURE2D_ARGS(layerTex, layerSampler), LayerUV layer
166166

167167
// This version is for normalmap with RGB encoding only, i.e non encoding. It is necessary to use this abstraction to handle correctly triplanar
168168
// plus consistent with the normal scale parameter
169-
float3 SampleNormalLayerRGB(TEXTURE2D_ARGS(layerTex, layerSampler), LayerUV layerUV, float3 weights, float scale)
169+
float3 SampleLayerNormalRGB(TEXTURE2D_ARGS(layerTex, layerSampler), LayerUV layerUV, float3 weights, float scale)
170170
{
171171
if (layerUV.isTriplanar)
172172
{
@@ -190,12 +190,9 @@ float3 SampleNormalLayerRGB(TEXTURE2D_ARGS(layerTex, layerSampler), LayerUV laye
190190
// Macro to improve readibility of surface data
191191
#define SAMPLE_LAYER_TEXTURE2D(textureName, samplerName, coord) SampleLayer(TEXTURE2D_PARAM(textureName, samplerName), coord, layerTexCoord.weights)
192192
#define SAMPLE_LAYER_TEXTURE2D_LOD(textureName, samplerName, coord, lod) SampleLayerLod(TEXTURE2D_PARAM(textureName, samplerName), coord, layerTexCoord.weights, lod)
193-
#define SAMPLE_LAYER_NORMALMAP(textureName, samplerName, coord, scale) SampleNormalLayer(TEXTURE2D_PARAM(textureName, samplerName), coord, layerTexCoord.weights, scale)
194-
#define SAMPLE_LAYER_NORMALMAP_AG(textureName, samplerName, coord, scale) SampleNormalLayerAG(TEXTURE2D_PARAM(textureName, samplerName), coord, layerTexCoord.weights, scale)
195-
#define SAMPLE_LAYER_NORMALMAP_RGB(textureName, samplerName, coord, scale) SampleNormalLayerRGB(TEXTURE2D_PARAM(textureName, samplerName), coord, layerTexCoord.weights, scale)
196-
197-
// Transforms 2D UV by scale/bias property
198-
#define TRANSFORM_TEX(tex,name) ((tex.xy) * name##_ST.xy + name##_ST.zw)
193+
#define SAMPLE_LAYER_NORMALMAP(textureName, samplerName, coord, scale) SampleLayerNormal(TEXTURE2D_PARAM(textureName, samplerName), coord, layerTexCoord.weights, scale)
194+
#define SAMPLE_LAYER_NORMALMAP_AG(textureName, samplerName, coord, scale) SampleLayerNormalAG(TEXTURE2D_PARAM(textureName, samplerName), coord, layerTexCoord.weights, scale)
195+
#define SAMPLE_LAYER_NORMALMAP_RGB(textureName, samplerName, coord, scale) SampleLayerNormalRGB(TEXTURE2D_PARAM(textureName, samplerName), coord, layerTexCoord.weights, scale)
199196

200197
#ifndef LAYERED_LIT_SHADER
201198

@@ -225,15 +222,32 @@ void GetLayerTexCoord(float2 texCoord0, float2 texCoord1, float2 texCoord2, floa
225222
positionWS, normalWS, isTriplanar, layerTexCoord);
226223
}
227224

225+
void ApplyPerPixelDisplacement(FragInputs input, float3 V, inout LayerTexCoord layerTexCoord)
226+
{
227+
#if defined(_HEIGHTMAP) && defined(_PER_PIXEL_DISPLACEMENT)
228+
229+
// ref: https://www.gamedev.net/resources/_/technical/graphics-programming-and-theory/a-closer-look-at-parallax-occlusion-mapping-r3262
230+
float3 viewDirTS = TransformWorldToTangent(V, input.tangentToWorld);
231+
// Change the number of samples per ray depending on the viewing angle for the surface.
232+
// Oblique angles require smaller step sizes to achieve more accurate precision for computing displacement.
233+
// int numSteps = (int)lerp(_PPPMaxSamples, _PPPMinSamples, viewDirTS.z);
234+
int numSteps = (int)lerp(15, 15, viewDirTS.z); // TEMP
235+
236+
ParallaxOcclusionMappingLayer(layerTexCoord, numSteps, viewDirTS);
237+
238+
// TODO: We are supposed to modify lightmaps coordinate (fetch in GetBuiltin), but this isn't the same uv mapping, so can't apply the offset here...
239+
// Let's assume it will be "fine" as indirect diffuse is often low frequency
240+
#endif
241+
}
242+
228243
void GetSurfaceAndBuiltinData(FragInputs input, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData)
229244
{
230245
LayerTexCoord layerTexCoord;
231246
GetLayerTexCoord(input.texCoord0, input.texCoord1, input.texCoord2, input.texCoord3,
232247
input.positionWS, input.tangentToWorld[2].xyz, layerTexCoord);
233248

234-
// Transform view vector in tangent space
235-
float3 viewDirTS = TransformWorldToTangent(V, input.tangentToWorld);
236-
ApplyDisplacement(input, viewDirTS, layerTexCoord);
249+
250+
ApplyPerPixelDisplacement(input, V, layerTexCoord);
237251
float depthOffset = 0.0;
238252

239253
#ifdef _DEPTHOFFSET_ON
@@ -404,20 +418,33 @@ void GetLayerTexCoord(float2 texCoord0, float2 texCoord1, float2 texCoord2, floa
404418
positionWS, normalWS, isTriplanar, layerTexCoord);
405419
}
406420

421+
void ApplyPerPixelDisplacement(FragInputs input, float3 V, inout LayerTexCoord layerTexCoord)
422+
{
423+
#if defined(_HEIGHTMAP) && defined(_PER_PIXEL_DISPLACEMENT)
424+
float3 viewDirTS = TransformWorldToTangent(V, input.tangentToWorld);
425+
int numSteps = (int)lerp(15, 15, viewDirTS.z);
426+
427+
ParallaxOcclusionMappingLayer0(layerTexCoord, numSteps, viewDirTS);
428+
ParallaxOcclusionMappingLayer1(layerTexCoord, numSteps, viewDirTS);
429+
ParallaxOcclusionMappingLayer2(layerTexCoord, numSteps, viewDirTS);
430+
ParallaxOcclusionMappingLayer3(layerTexCoord, numSteps, viewDirTS);
431+
#endif
432+
}
433+
407434
void GetSurfaceAndBuiltinData(FragInputs input, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData)
408435
{
409436
LayerTexCoord layerTexCoord;
410437
GetLayerTexCoord(input.texCoord0, input.texCoord1, input.texCoord2, input.texCoord3,
411438
input.positionWS, input.tangentToWorld[2].xyz, layerTexCoord);
412439

413-
// Transform view vector in tangent space
414-
float3 viewDirTS = TransformWorldToTangent(V, input.tangentToWorld);
415-
float height0 = ApplyDisplacement0(input, viewDirTS, layerTexCoord);
416-
float height1 = ApplyDisplacement1(input, viewDirTS, layerTexCoord);
417-
float height2 = ApplyDisplacement2(input, viewDirTS, layerTexCoord);
418-
float height3 = ApplyDisplacement3(input, viewDirTS, layerTexCoord);
419-
float depthOffset = 0.0;
440+
ApplyPerPixelDisplacement(input, V, layerTexCoord);
420441

442+
float height0 = SampleHeightmap0(layerTexCoord);
443+
float height1 = SampleHeightmap1(layerTexCoord);
444+
float height2 = SampleHeightmap2(layerTexCoord);
445+
float height3 = SampleHeightmap3(layerTexCoord);
446+
447+
float depthOffset = 0.0;
421448
#ifdef _DEPTHOFFSET_ON
422449
ApplyDepthOffsetPositionInput(V, depthOffset, posInput);
423450
#endif

Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitDataInternal.hlsl

Lines changed: 66 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -53,44 +53,83 @@ void ADD_IDX(ComputeLayerTexCoord)( float2 texCoord0, float2 texCoord1, float2 t
5353
ADD_IDX(layerTexCoord.details).uvXY = TRANSFORM_TEX(uvXY, ADD_IDX(_DetailMap));
5454
}
5555

56-
float ADD_IDX(ApplyDisplacement)(inout FragInputs input, float3 viewDirTS, inout LayerTexCoord layerTexCoord)
56+
float ADD_IDX(SampleHeightmap)(LayerTexCoord layerTexCoord)
5757
{
58-
float height = 0.0f;
59-
6058
#ifdef _HEIGHTMAP
61-
height = (SAMPLE_LAYER_TEXTURE2D(ADD_IDX(_HeightMap), ADD_ZERO_IDX(sampler_HeightMap), ADD_IDX(layerTexCoord.base)).r - ADD_IDX(_HeightCenter)) * ADD_IDX(_HeightAmplitude);
59+
return (SAMPLE_TEXTURE2D(ADD_IDX(_HeightMap), ADD_ZERO_IDX(sampler_HeightMap), ADD_IDX(layerTexCoord.base).uv).r - ADD_IDX(_HeightCenter)) * ADD_IDX(_HeightAmplitude);
60+
#else
61+
return 0.0;
62+
#endif
63+
}
6264

63-
//#ifdef _PER_PIXEL_DISPLACEMENT
64-
// //height = SAMPLE_LAYER_TEXTURE2D(ADD_IDX(_HeightMap), ADD_ZERO_IDX(sampler_HeightMap), ADD_IDX(layerTexCoord.base)).r * ADD_IDX(_HeightScale) + ADD_IDX(_HeightBias);
65-
// float2 offset = ParallaxOffset(viewDirTS, height);
65+
void ADD_IDX(ParallaxOcclusionMappingLayer)(inout LayerTexCoord layerTexCoord, int numSteps, float3 viewDirTS)
66+
{
67+
// Convention: 1.0 is top, 0.0 is bottom - POM is always inward, no extrusion
68+
float stepSize = 1.0 / (float)numSteps;
69+
70+
// View vector is from the point to the camera, but we want to raymarch from camera to point, so reverse the sign
71+
// The length of viewDirTS vector determines the furthest amount of displacement:
72+
// float parallaxLimit = -length(viewDirTS.xy) / viewDirTS.z;
73+
// float2 parallaxDir = normalize(Out.viewDirTS.xy);
74+
// float2 parallaxMaxOffsetTS = parallaxDir * parallaxLimit;
75+
// Above code simplify to
76+
float2 parallaxMaxOffsetTS = (viewDirTS.xy / -viewDirTS.z) * ADD_IDX(_HeightAmplitude);
77+
float2 texOffsetPerStep = stepSize * parallaxMaxOffsetTS;
78+
79+
float2 uv = ADD_IDX(layerTexCoord.base).uv;
80+
81+
// Compute lod as we will sample inside a lop (so can't use regular sampling)
82+
float lod = CALCULATE_TEXTURE2D_LOD(ADD_IDX(_HeightMap), ADD_ZERO_IDX(sampler_HeightMap), uv);
83+
84+
// Do a first step before the loop to init all value correctly
85+
float2 texOffsetCurrent = uv;
86+
float prevHeight = SAMPLE_TEXTURE2D_LOD(ADD_IDX(_HeightMap), ADD_ZERO_IDX(sampler_HeightMap), uv + texOffsetCurrent, lod).r;
87+
texOffsetCurrent += texOffsetPerStep;
88+
float currHeight = SAMPLE_TEXTURE2D_LOD(ADD_IDX(_HeightMap), ADD_ZERO_IDX(sampler_HeightMap), uv + texOffsetCurrent, lod).r;
89+
float rayHeight = 1.0 - stepSize; // Start at top less one sample
90+
91+
// Linear search
92+
for (int stepIndex = 0; stepIndex < numSteps; ++stepIndex)
93+
{
94+
// Have we found a height below our ray height ? then we have an intersection
95+
if (currHeight > rayHeight)
96+
break; // end the loop
97+
98+
prevHeight = currHeight;
99+
rayHeight -= stepSize;
100+
texOffsetCurrent += texOffsetPerStep;
66101

67-
// ADD_IDX(layerTexCoord.base).uv += offset;
68-
// ADD_IDX(layerTexCoord.base).uvYZ += offset;
69-
// ADD_IDX(layerTexCoord.base).uvZX += offset;
70-
// ADD_IDX(layerTexCoord.base).uvXY += offset;
102+
// Sample height map which in this case is stored in the alpha channel of the normal map:
103+
currHeight = SAMPLE_TEXTURE2D_LOD(ADD_IDX(_HeightMap), ADD_ZERO_IDX(sampler_HeightMap), uv + texOffsetCurrent, lod).r;
104+
}
71105

72-
// ADD_IDX(layerTexCoord.details).uv += offset;
73-
// ADD_IDX(layerTexCoord.details).uvYZ += offset;
74-
// ADD_IDX(layerTexCoord.details).uvZX += offset;
75-
// ADD_IDX(layerTexCoord.details).uvXY += offset;
106+
// Found below and above points, now perform line interesection (ray) with piecewise linear heightfield approximation
76107

77-
// // Only modify texcoord for first layer, this will be use by for builtin data (like lightmap)
78-
// if (LAYER_INDEX == 0)
79-
// {
80-
// input.texCoord0 += offset;
81-
// input.texCoord1 += offset;
82-
// input.texCoord2 += offset;
83-
// input.texCoord3 += offset;
84-
// }
85108

86-
// // Need to refetch for the right parallaxed height for layer blending to behave correctly...
87-
// height = SAMPLE_LAYER_TEXTURE2D(ADD_IDX(_HeightMap), ADD_ZERO_IDX(sampler_HeightMap), ADD_IDX(layerTexCoord.base)).r * ADD_IDX(_HeightScale) + ADD_IDX(_HeightBias);
109+
#define POM_REFINE 0
110+
#if POM_REFINE
88111

89-
// #endif
112+
#else
113+
/*
114+
float t0 = rayHeight + stepSize;
115+
float t1 = rayHeight;
116+
float delta0 = t0 - prevHeight;
117+
float delta1 = t1 - currHeight;
118+
float t = (t0 * delta1 - t1 * delta0) / (delta1 - delta0);
119+
float2 offset = uv + (1 - t) * texOffsetPerStep * numSteps;
120+
*/
121+
122+
float delta0 = currHeight - rayHeight;
123+
float delta1 = (rayHeight + stepSize) - prevHeight;
124+
float ratio = delta0 / (delta0 + delta1);
125+
float2 offset = (ratio) * (texOffsetCurrent - texOffsetPerStep) + (1.0 - ratio) * texOffsetCurrent;
90126

91127
#endif
92128

93-
return height;
129+
// Apply offset only on base. Details could use another mapping and will not be consistant...
130+
// Don't know if this will still ok.
131+
// TODO: check with artists
132+
ADD_IDX(layerTexCoord.base).uv += offset;
94133
}
95134

96135
// Return opacity

Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.hlsl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ float4 TessellationEdge(float3 p0, float3 p1, float3 p2, float3 n0, float3 n1, f
4040
// Distance based tessellation
4141
if (_TessellationFactorMaxDistance > 0.0)
4242
{
43-
tessFactor *= GetDistanceBasedTessFactor(p0, p1, p2, _WorldSpaceCameraPos, _TessellationFactorMinDistance, _TessellationFactorMaxDistance);
43+
float3 distFactor = GetDistanceBasedTessFactor(p0, p1, p2, _WorldSpaceCameraPos, _TessellationFactorMinDistance, _TessellationFactorMaxDistance);
44+
// We square the disance factor as it allow a better percptual descrease of vertex density.
45+
tessFactor *= distFactor * distFactor;
4446
}
4547

4648
tessFactor *= _TessellationFactor;

Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/VaryingMesh.hlsl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,6 @@ PackedVaryingsMeshToPS PackVaryingsMeshToPS(VaryingsMeshToPS input)
110110
output.interpolators1.w = input.positionWS.x;
111111
output.interpolators2.w = input.positionWS.y;
112112
output.interpolators3.w = input.positionWS.z;
113-
#else
114-
output.interpolators1.w = 0.0;
115-
output.interpolators2.w = 0.0;
116-
output.interpolators3.w = 0.0;
117113
#endif
118114
#else
119115
#ifdef VARYINGS_NEED_POSITION_WS

Assets/ScriptableRenderLoop/HDRenderPipeline/Utilities.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public enum ClearFlag
1616

1717
public class Utilities
1818
{
19-
public const RendererConfiguration kRendererConfigurationBakedLighting = RendererConfiguration.PerObjectLightProbe | RendererConfiguration.PerObjectReflectionProbes | RendererConfiguration.PerObjectLightmaps | RendererConfiguration.PerObjectLightProbeProxyVolume;
19+
public const RendererConfiguration kRendererConfigurationBakedLighting = RendererConfiguration.PerObjectLightProbe | RendererConfiguration.PerObjectLightmaps | RendererConfiguration.PerObjectLightProbeProxyVolume;
2020

2121

2222
// Render Target Management.

Assets/ScriptableRenderLoop/ShaderLibrary/API/D3D11.hlsl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
// Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0
1717
#define ZERO_INITIALIZE(type, name) name = (type)0;
1818

19+
// Texture util abstraction
20+
21+
#define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2)
22+
1923
// Texture abstraction
2024

2125
#define TEXTURE2D(textureName) Texture2D textureName
@@ -50,6 +54,7 @@
5054

5155
#define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2)
5256
#define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod)
57+
#define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) textureName.SampleGrad(samplerName, coord2, ddx, ddy)
5358
#define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index))
5459
#define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod)
5560
#define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3)

Assets/ScriptableRenderLoop/ShaderLibrary/API/PSSL.hlsl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
// Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0
2626
#define ZERO_INITIALIZE(type, name) name = (type)0;
2727

28+
// Texture util abstraction
29+
30+
#define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.GetLOD(samplerName, coord2)
31+
2832
// Texture abstraction
2933

3034
#define TEXTURE2D(textureName) Texture2D textureName
@@ -59,6 +63,7 @@
5963

6064
#define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2)
6165
#define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod)
66+
#define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) textureName.SampleGrad(samplerName, coord2, ddx, ddy)
6267
#define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index))
6368
#define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod)
6469
#define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3)

Assets/ScriptableRenderLoop/ShaderLibrary/CommonMaterial.hlsl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,8 @@ float3 LerpWhiteTo(float3 b, float t)
128128
return float3(oneMinusT, oneMinusT, oneMinusT) + b * t;
129129
}
130130

131+
// MACRO from Legacy Untiy
132+
// Transforms 2D UV by scale/bias property
133+
#define TRANSFORM_TEX(tex, name) ((tex.xy) * name##_ST.xy + name##_ST.zw)
134+
131135
#endif // UNITY_COMMON_MATERIAL_INCLUDED

0 commit comments

Comments
 (0)