Skip to content

Commit

Permalink
Merge pull request #29 from Delt06/specular-fix
Browse files Browse the repository at this point in the history
Specular fix
  • Loading branch information
Delt06 authored Jan 11, 2022
2 parents 8cb6ed7 + 69d629d commit 7a6048d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ half4 frag(const v2f input) : SV_Target
half3 normal_ws = input.normalWS;
#endif

normal_ws = NormalizeNormalPerPixel(normal_ws);
normal_ws = normalize(normal_ws);

const half3 light_direction_ws = normalize(main_light.direction);
const float3 position_ws = input.positionWSAndFogFactor.xyz;
const half3 view_direction_ws = SafeNormalize(GetCameraPositionWS() - position_ws);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ inline half3 get_specular_color(half3 light_color, half3 view_direction_ws, half
half specular = get_specular(view_direction_ws, normal_ws, light_direction_ws);
#endif

const half specular_exponent = UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, _SpecularExponent);
const half specular_exponent = _SpecularExponent;
specular = pow(specular, specular_exponent);
const half4 specular_color = UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, _SpecularColor);
const half specular_threshold = UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, _SpecularThreshold);
const half specular_smoothness = UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, _SpecularSmoothness);
const half4 specular_color = _SpecularColor;
const half specular_threshold = _SpecularThreshold;
const half specular_smoothness = _SpecularSmoothness;
const half3 ramp = get_simple_ramp(light_color, specular_color.a, specular_threshold, specular_smoothness,
specular);
return specular_color.xyz * ramp;
Expand All @@ -121,9 +121,9 @@ inline half3 get_fresnel_color(half3 light_color, half3 view_direction_ws, half3
return 0;
#else
const half fresnel = get_fresnel(view_direction_ws, normal_ws);
const half4 fresnel_color = UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, _FresnelColor);
const half fresnel_thickness = UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, _FresnelThickness);
const half fresnel_smothness = UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, _FresnelSmoothness);
const half4 fresnel_color = _FresnelColor;
const half fresnel_thickness = _FresnelThickness;
const half fresnel_smothness = _FresnelSmoothness;
return fresnel_color.xyz * get_simple_ramp(light_color, fresnel_color.a, fresnel_thickness, fresnel_smothness, brightness * fresnel);
#endif
}
Expand Down

0 comments on commit 7a6048d

Please sign in to comment.