summaryrefslogtreecommitdiffstats
path: root/pbr.cginc
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2024-05-11 14:35:59 -0700
committeryum <yum.food.vr@gmail.com>2024-05-11 14:35:59 -0700
commit47d32c9b5a4c809b10b3c198089cd4992281fa36 (patch)
tree45dffa4353c2ac95f654b4d325c84f28cc6aa1bf /pbr.cginc
parent6eed98ff4e57326ebf7a41f0c180635a7bcac626 (diff)
Make flat normals adjustable
Diffstat (limited to 'pbr.cginc')
-rw-r--r--pbr.cginc10
1 files changed, 7 insertions, 3 deletions
diff --git a/pbr.cginc b/pbr.cginc
index a699a53..1ceef09 100644
--- a/pbr.cginc
+++ b/pbr.cginc
@@ -127,8 +127,12 @@ float4 getLitColor(
float3 view_dir = normalize(_WorldSpaceCameraPos - worldPos);
bool flat = round(_Flatten_Mesh_Normals) == 1.0;
+ float3 flat_normal = normalize(
+ (1.0 / _Flatten_Mesh_Normals_Str) * normal +
+ _Flatten_Mesh_Normals_Str * view_dir);
+
UnityIndirect indirect_light = CreateIndirectLight(vertexLightColor,
- view_dir, flat ? view_dir : normal, smoothness, worldPos, uv);
+ view_dir, flat ? flat_normal : normal, smoothness, worldPos, uv);
UnityLight direct_light = CreateDirectLight(normal, i);
if (flat) {
@@ -148,7 +152,7 @@ float4 getLitColor(
one_minus_reflectivity,
smoothness,
view_dir,
- flat ? view_dir : normal,
+ flat ? flat_normal : normal,
direct_light,
indirect_light).xyz;
} else {
@@ -157,7 +161,7 @@ float4 getLitColor(
specular_tint,
one_minus_reflectivity,
smoothness,
- flat ? view_dir : normal,
+ flat ? flat_normal : normal,
view_dir,
direct_light,
indirect_light).xyz;