@@ -112,7 +112,7 @@ MaterialInput GetGeometryMaterialInput(GeometryData geometry)
|
|||||||
#if USE_LIGHTMAP
|
#if USE_LIGHTMAP
|
||||||
output.LightmapUV = geometry.LightmapUV;
|
output.LightmapUV = geometry.LightmapUV;
|
||||||
#endif
|
#endif
|
||||||
output.TBN = CalcTangentBasisFromWorldNormal(geometry.WorldNormal);
|
output.TBN = CalcTangentBasis(geometry.WorldNormal, geometry.WorldPosition, geometry.TexCoord);
|
||||||
output.HolesMask = geometry.HolesMask;
|
output.HolesMask = geometry.HolesMask;
|
||||||
#if USE_TERRAIN_LAYERS
|
#if USE_TERRAIN_LAYERS
|
||||||
output.Layers = geometry.Layers;
|
output.Layers = geometry.Layers;
|
||||||
@@ -415,7 +415,7 @@ VertexOutput VS(TerrainVertexInput input)
|
|||||||
#if USE_LIGHTMAP
|
#if USE_LIGHTMAP
|
||||||
materialInput.LightmapUV = output.Geometry.LightmapUV;
|
materialInput.LightmapUV = output.Geometry.LightmapUV;
|
||||||
#endif
|
#endif
|
||||||
materialInput.TBN = CalcTangentBasisFromWorldNormal(output.Geometry.WorldNormal);
|
materialInput.TBN = tangentToWorld;
|
||||||
materialInput.TwoSidedSign = WorldDeterminantSign;
|
materialInput.TwoSidedSign = WorldDeterminantSign;
|
||||||
materialInput.SvPosition = output.Position;
|
materialInput.SvPosition = output.Position;
|
||||||
materialInput.PreSkinnedPosition = position;
|
materialInput.PreSkinnedPosition = position;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Current materials shader version.
|
/// Current materials shader version.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
#define MATERIAL_GRAPH_VERSION 148
|
#define MATERIAL_GRAPH_VERSION 149
|
||||||
|
|
||||||
class Material;
|
class Material;
|
||||||
class GPUShader;
|
class GPUShader;
|
||||||
|
|||||||
@@ -154,6 +154,22 @@ struct GBufferOutput
|
|||||||
float4 RT3 : SV_Target4;
|
float4 RT3 : SV_Target4;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
float3x3 CalcTangentBasis(float3 normal, float3 pos, float2 uv)
|
||||||
|
{
|
||||||
|
// References:
|
||||||
|
// http://www.thetenthplanet.de/archives/1180
|
||||||
|
// https://zhangdoa.com/posts/normal-and-normal-mapping
|
||||||
|
float3 dp1 = ddx(pos);
|
||||||
|
float3 dp2 = ddy(pos);
|
||||||
|
float2 duv1 = ddx(uv);
|
||||||
|
float2 duv2 = ddy(uv);
|
||||||
|
float3 dp2perp = cross(dp2, normal);
|
||||||
|
float3 dp1perp = cross(normal, dp1);
|
||||||
|
float3 tangent = normalize(dp2perp * duv1.x + dp1perp * duv2.x);
|
||||||
|
float3 bitangent = normalize(dp2perp * duv1.y + dp1perp * duv2.y);
|
||||||
|
return float3x3(tangent, bitangent, normal);
|
||||||
|
}
|
||||||
|
|
||||||
float3x3 CalcTangentBasisFromWorldNormal(float3 normal)
|
float3x3 CalcTangentBasisFromWorldNormal(float3 normal)
|
||||||
{
|
{
|
||||||
float3 tangent = cross(normal, float3(1, 0, 0));
|
float3 tangent = cross(normal, float3(1, 0, 0));
|
||||||
|
|||||||
Reference in New Issue
Block a user