diff options
| author | yum <yum.food.vr@gmail.com> | 2025-08-07 18:59:23 -0700 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2025-08-07 18:59:23 -0700 |
| commit | 8c6e9be61b2a7b1c5b9e5b61252090a4e2432ce2 (patch) | |
| tree | ad8af761b02f9a37eeafe0ef3ad0324a418447d2 /pbr.cginc | |
| parent | 7fe9d7357ef5788745200012205954b9a484a3ed (diff) | |
add base color, normal, and metallic gloss textures
Diffstat (limited to 'pbr.cginc')
| -rw-r--r-- | pbr.cginc | 21 |
1 files changed, 16 insertions, 5 deletions
@@ -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; } |
