diff options
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; } |
