From 8c6e9be61b2a7b1c5b9e5b61252090a4e2432ce2 Mon Sep 17 00:00:00 2001 From: yum Date: Thu, 7 Aug 2025 18:59:23 -0700 Subject: add base color, normal, and metallic gloss textures --- pbr.cginc | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'pbr.cginc') diff --git a/pbr.cginc b/pbr.cginc index 156fba2..1677ccc 100644 --- a/pbr.cginc +++ b/pbr.cginc @@ -8,6 +8,7 @@ struct Pbr { float4 albedo; float3 normal; + float3x3 tbn; float smoothness; float roughness_perceptual; float roughness; @@ -40,13 +41,23 @@ void apply_marble(float3 world_pos, inout float3 albedo) { Pbr getPbr(v2f i) { Pbr pbr = (Pbr) 0; - pbr.normal = normalize(i.normal); - pbr.albedo = _Color; - pbr.smoothness = _Smoothness; - propagateSmoothness(pbr); + + pbr.albedo = _MainTex.Sample(trilinear_repeat_s, i.uv0 * _MainTex_ST.xy); + pbr.albedo *= _Color; apply_marble(i.worldPos, pbr.albedo.xyz); - pbr.metallic = _Metallic; + float3 normal_tangent = UnpackNormal(_BumpMap.Sample(trilinear_repeat_s, i.uv0 * _BumpMap_ST.xy)); + normal_tangent.xy *= _BumpScale; + // Map from tangent space to world space. + float3 bitangent = cross(i.normal, i.tangent.xyz) * i.tangent.w; + pbr.tbn = float3x3(i.tangent.xyz, bitangent, i.normal); + pbr.normal = normalize(mul(normal_tangent, pbr.tbn)); + + float4 metallic_gloss = _MetallicGlossMap.Sample(trilinear_repeat_s, i.uv0 * _MetallicGlossMap_ST.xy); + pbr.smoothness = metallic_gloss.a * _Glossiness; + pbr.metallic = metallic_gloss.r * _Metallic; + + propagateSmoothness(pbr); return pbr; } -- cgit v1.2.3