generated from raccoon/vrchat-project-template
Fixed normal mapping
This commit is contained in:
@@ -24,8 +24,9 @@ Shader "Custom/StandardSurf"
|
||||
|
||||
CGPROGRAM
|
||||
// Physically based Standard lighting model, and enable shadows on all light types
|
||||
#pragma surface surf Standard fullforwardshadows alpha:fade
|
||||
#pragma target 3.0
|
||||
#pragma surface surf Standard fullforwardshadows alpha:fade addshadow
|
||||
#pragma target 3.5
|
||||
#pragma shader_feature_local _NORMALMAP
|
||||
|
||||
UNITY_DECLARE_TEX2DARRAY(_DiffuseArray);
|
||||
fixed4 _Color;
|
||||
@@ -40,6 +41,7 @@ Shader "Custom/StandardSurf"
|
||||
struct Input
|
||||
{
|
||||
float2 uv_DiffuseArray;
|
||||
INTERNAL_DATA // For proper normal handling
|
||||
};
|
||||
|
||||
// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
|
||||
@@ -49,14 +51,6 @@ Shader "Custom/StandardSurf"
|
||||
// put more per-instance properties here
|
||||
UNITY_INSTANCING_BUFFER_END(Props)
|
||||
|
||||
float3 UnpackAndScaleNormal(float4 c, float scale)
|
||||
{
|
||||
float3 n;
|
||||
n.xy = (c.xy * 2 - 1) * scale;
|
||||
n.z = sqrt(saturate(1.0 - dot(n.xy, n.xy)));
|
||||
return n;
|
||||
}
|
||||
|
||||
void surf(Input IN, inout SurfaceOutputStandard o)
|
||||
{
|
||||
// Common UV for all texture arrays
|
||||
@@ -66,17 +60,18 @@ Shader "Custom/StandardSurf"
|
||||
// Albedo with alpha
|
||||
float4 diff = UNITY_SAMPLE_TEX2DARRAY(_DiffuseArray, uvw) * _Color;
|
||||
o.Albedo = diff.rgb;
|
||||
o.Alpha = diff.a;
|
||||
o.Alpha = _Color.a;
|
||||
|
||||
// Sample Metallic and smoothness (R = Metallic, A = Smoothness) plus slider variable
|
||||
float4 metalGloss = UNITY_SAMPLE_TEX2DARRAY(_MetallicArray, uvw);
|
||||
o.Metallic = metalGloss.r;
|
||||
o.Smoothness = metalGloss.a * _Glossiness;
|
||||
|
||||
// Normal map
|
||||
// Normal map and it's scale
|
||||
float4 normalTex = UNITY_SAMPLE_TEX2DARRAY(_NormalArray, uvw);
|
||||
float3 tangentNormal = UnpackAndScaleNormal(normalTex, _Bumpyness);
|
||||
o.Normal = tangentNormal;
|
||||
float3 normalMap = UnpackNormal(normalTex);
|
||||
normalMap.xy *= _Bumpyness;
|
||||
o.Normal = normalize(normalMap);
|
||||
}
|
||||
|
||||
ENDCG
|
||||
|
||||
Reference in New Issue
Block a user