185 lines
5.9 KiB
Plaintext
185 lines
5.9 KiB
Plaintext
Shader "Samples/RebindingUI/SimpleLit"
|
|
{
|
|
Properties
|
|
{
|
|
_Color ("Color", Color) = (1,1,1,1)
|
|
_MainTex ("Albedo (RGB)", 2D) = "white" {}
|
|
_Glossiness ("Smoothness", Range(0,1)) = 0.5
|
|
_Metallic ("Metallic", Range(0,1)) = 0.0
|
|
}
|
|
|
|
SubShader
|
|
{
|
|
Tags { "RenderType"="Opaque" "RenderPipeline"="UniversalPipeline" "Queue"="Geometry" }
|
|
|
|
Pass
|
|
{
|
|
Name "ForwardLit"
|
|
Tags { "LightMode"="UniversalForward" }
|
|
|
|
HLSLPROGRAM
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
|
|
#pragma multi_compile _ _SHADOWS_SOFT
|
|
#pragma multi_compile _ _ADDITIONAL_LIGHTS
|
|
#pragma multi_compile_fog
|
|
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
|
|
|
TEXTURE2D(_MainTex);
|
|
SAMPLER(sampler_MainTex);
|
|
|
|
CBUFFER_START(UnityPerMaterial)
|
|
float4 _MainTex_ST;
|
|
half4 _Color;
|
|
half _Glossiness;
|
|
half _Metallic;
|
|
CBUFFER_END
|
|
|
|
struct Attributes
|
|
{
|
|
float4 positionOS : POSITION;
|
|
float3 normalOS : NORMAL;
|
|
float2 uv : TEXCOORD0;
|
|
};
|
|
|
|
struct Varyings
|
|
{
|
|
float4 positionCS : SV_POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
float3 normalWS : TEXCOORD1;
|
|
float3 positionWS : TEXCOORD2;
|
|
float fogFactor : TEXCOORD3;
|
|
};
|
|
|
|
Varyings vert(Attributes input)
|
|
{
|
|
Varyings output;
|
|
VertexPositionInputs posInputs = GetVertexPositionInputs(input.positionOS.xyz);
|
|
output.positionCS = posInputs.positionCS;
|
|
output.positionWS = posInputs.positionWS;
|
|
output.normalWS = TransformObjectToWorldNormal(input.normalOS);
|
|
output.uv = TRANSFORM_TEX(input.uv, _MainTex);
|
|
output.fogFactor = ComputeFogFactor(posInputs.positionCS.z);
|
|
return output;
|
|
}
|
|
|
|
half4 frag(Varyings input) : SV_Target
|
|
{
|
|
half4 albedo = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, input.uv) * _Color;
|
|
|
|
InputData inputData = (InputData)0;
|
|
inputData.positionWS = input.positionWS;
|
|
inputData.normalWS = normalize(input.normalWS);
|
|
inputData.viewDirectionWS = GetWorldSpaceNormalizeViewDir(input.positionWS);
|
|
inputData.shadowCoord = TransformWorldToShadowCoord(input.positionWS);
|
|
|
|
SurfaceData surfaceData = (SurfaceData)0;
|
|
surfaceData.albedo = albedo.rgb;
|
|
surfaceData.alpha = albedo.a;
|
|
surfaceData.metallic = _Metallic;
|
|
surfaceData.smoothness = _Glossiness;
|
|
surfaceData.occlusion = 1.0;
|
|
|
|
half4 color = UniversalFragmentPBR(inputData, surfaceData);
|
|
color.rgb = MixFog(color.rgb, input.fogFactor);
|
|
return color;
|
|
}
|
|
ENDHLSL
|
|
}
|
|
|
|
Pass
|
|
{
|
|
Name "ShadowCaster"
|
|
Tags { "LightMode"="ShadowCaster" }
|
|
|
|
ZWrite On
|
|
ZTest LEqual
|
|
ColorMask 0
|
|
|
|
HLSLPROGRAM
|
|
#pragma vertex ShadowVert
|
|
#pragma fragment ShadowFrag
|
|
#pragma multi_compile _ _CASTING_PUNCTUAL_LIGHT_SHADOW
|
|
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
|
|
|
float3 _LightDirection;
|
|
float3 _LightPosition;
|
|
|
|
struct Attributes
|
|
{
|
|
float4 positionOS : POSITION;
|
|
float3 normalOS : NORMAL;
|
|
};
|
|
|
|
struct Varyings
|
|
{
|
|
float4 positionCS : SV_POSITION;
|
|
};
|
|
|
|
Varyings ShadowVert(Attributes input)
|
|
{
|
|
Varyings output;
|
|
float3 posWS = TransformObjectToWorld(input.positionOS.xyz);
|
|
float3 normalWS = TransformObjectToWorldNormal(input.normalOS);
|
|
|
|
#if _CASTING_PUNCTUAL_LIGHT_SHADOW
|
|
float3 lightDir = normalize(_LightPosition - posWS);
|
|
#else
|
|
float3 lightDir = _LightDirection;
|
|
#endif
|
|
|
|
output.positionCS = TransformWorldToHClip(ApplyShadowBias(posWS, normalWS, lightDir));
|
|
#if UNITY_REVERSED_Z
|
|
output.positionCS.z = min(output.positionCS.z, UNITY_NEAR_CLIP_VALUE);
|
|
#else
|
|
output.positionCS.z = max(output.positionCS.z, UNITY_NEAR_CLIP_VALUE);
|
|
#endif
|
|
return output;
|
|
}
|
|
|
|
half4 ShadowFrag(Varyings input) : SV_Target
|
|
{
|
|
return 0;
|
|
}
|
|
ENDHLSL
|
|
}
|
|
}
|
|
|
|
SubShader
|
|
{
|
|
Tags { "RenderType"="Opaque" }
|
|
LOD 200
|
|
|
|
CGPROGRAM
|
|
#pragma surface surf Standard fullforwardshadows
|
|
#pragma target 3.0
|
|
|
|
sampler2D _MainTex;
|
|
half _Glossiness;
|
|
half _Metallic;
|
|
fixed4 _Color;
|
|
|
|
struct Input
|
|
{
|
|
float2 uv_MainTex;
|
|
};
|
|
|
|
void surf(Input IN, inout SurfaceOutputStandard o)
|
|
{
|
|
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
|
|
o.Albedo = c.rgb;
|
|
o.Metallic = _Metallic;
|
|
o.Smoothness = _Glossiness;
|
|
o.Alpha = c.a;
|
|
}
|
|
ENDCG
|
|
}
|
|
|
|
FallBack "Diffuse"
|
|
}
|