155 lines
4.5 KiB
Plaintext
155 lines
4.5 KiB
Plaintext
Shader "MR/MRObstacle"
|
|
{
|
|
Properties
|
|
{
|
|
_MainTex ("Texture", 2D) = "white" {}
|
|
[Toggle(_Enable)]_Enable("Enable" , Float) = 1.0
|
|
}
|
|
|
|
SubShader
|
|
{
|
|
LOD 0
|
|
|
|
Tags { "RenderPipeline"="UniversalPipeline" "RenderType"="Geometry" "Queue"="Geometry-50" "UniversalMaterialType"="Lit" }
|
|
|
|
HLSLINCLUDE
|
|
#pragma target 3.5
|
|
#pragma prefer_hlslcc gles
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Filtering.hlsl"
|
|
ENDHLSL
|
|
|
|
// 自阴影留用,勿删
|
|
// Pass
|
|
// {
|
|
// Name "ShadowCaster"
|
|
// Tags{"LightMode" = "ShadowCaster"}
|
|
|
|
// ZWrite On
|
|
// ZTest LEqual
|
|
// ColorMask 0
|
|
// Cull[_Cull]
|
|
|
|
// HLSLPROGRAM
|
|
// #pragma exclude_renderers gles gles3 glcore
|
|
// #pragma target 4.5
|
|
|
|
// // -------------------------------------
|
|
// // Material Keywords
|
|
// #pragma shader_feature_local_fragment _ALPHATEST_ON
|
|
// #pragma shader_feature_local_fragment _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
|
|
|
|
// //--------------------------------------
|
|
// // GPU Instancing
|
|
// #pragma multi_compile_instancing
|
|
// #pragma multi_compile _ DOTS_INSTANCING_ON
|
|
|
|
// #pragma vertex ShadowPassVertex
|
|
// #pragma fragment ShadowPassFragment
|
|
|
|
// #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
|
|
// #include "Packages/com.unity.render-pipelines.universal/Shaders/ShadowCasterPass.hlsl"
|
|
// ENDHLSL
|
|
// }
|
|
|
|
Pass
|
|
{
|
|
Name "Forward"
|
|
|
|
Tags { "LightMode"="UniversalForward" }
|
|
|
|
Cull Back
|
|
AlphaToMask Off
|
|
Blend SrcAlpha OneMinusSrcAlpha
|
|
ZWrite On
|
|
ZTest LEqual
|
|
Offset 0 , 0
|
|
ColorMask RGBA
|
|
|
|
HLSLPROGRAM
|
|
|
|
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
|
|
#pragma multi_compile_fragment _ _REFLECTION_PROBE_BLENDING
|
|
#pragma multi_compile_fragment _ _REFLECTION_PROBE_BOX_PROJECTION
|
|
#pragma multi_compile_fragment _ _DBUFFER_MRT1 _DBUFFER_MRT2 _DBUFFER_MRT3
|
|
|
|
#pragma multi_compile _ SHADOWS_SHADOWMASK
|
|
#pragma multi_compile _ DIRLIGHTMAP_COMBINED
|
|
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
|
|
#define SHADERPASS SHADERPASS_FORWARD
|
|
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
|
|
|
|
struct VertexInput
|
|
{
|
|
float4 vertex : POSITION;
|
|
float3 normal : NORMAL;
|
|
float4 tangent : TANGENT;
|
|
};
|
|
|
|
struct VertexOutput
|
|
{
|
|
float4 clipPos : SV_POSITION;
|
|
float4 clipPosV : TEXCOORD0;
|
|
float4 tSpace0 : TEXCOORD3;
|
|
float4 tSpace1 : TEXCOORD4;
|
|
float4 tSpace2 : TEXCOORD5;
|
|
};
|
|
|
|
sampler2D _ShadowMapTexture;
|
|
half _Enable;
|
|
|
|
VertexOutput vert ( VertexInput v )
|
|
{
|
|
VertexOutput o = (VertexOutput)0;
|
|
float3 positionWS = TransformObjectToWorld( v.vertex.xyz );
|
|
float3 positionVS = TransformWorldToView( positionWS );
|
|
float4 positionCS = TransformWorldToHClip( positionWS );
|
|
VertexNormalInputs normalInput = GetVertexNormalInputs( v.normal, v.tangent );
|
|
o.tSpace0 = float4( normalInput.normalWS, positionWS.x);
|
|
o.tSpace1 = float4( normalInput.tangentWS, positionWS.y);
|
|
o.tSpace2 = float4( normalInput.bitangentWS, positionWS.z);
|
|
half3 vertexLight = VertexLighting( positionWS, normalInput.normalWS );
|
|
o.clipPos = positionCS;
|
|
o.clipPosV = positionCS;
|
|
return o;
|
|
}
|
|
|
|
half4 frag (VertexOutput IN) : SV_Target
|
|
{
|
|
half4 color = 0;
|
|
if(_Enable == 1.0){
|
|
float3 WorldPosition = float3(IN.tSpace0.w, IN.tSpace1.w, IN.tSpace2.w);
|
|
float4 ShadowCoords = TransformWorldToShadowCoord(WorldPosition);
|
|
|
|
int sampleCount = 5;
|
|
float offset = 1.0 / 4096.0;
|
|
|
|
for (int i = 0; i < sampleCount; i++)
|
|
{
|
|
for (int j = 0; j < sampleCount; j++)
|
|
{
|
|
float4 offsetShadowCoords = ShadowCoords;
|
|
offsetShadowCoords.xy += float2((i - sampleCount / 2) * offset, (j - sampleCount / 2) * offset);
|
|
Light light = GetMainLight(offsetShadowCoords);
|
|
half4 sampledColor = float4(0, 0, 0, 1 - light.shadowAttenuation);
|
|
color += sampledColor;
|
|
}
|
|
}
|
|
color /= sampleCount * sampleCount;
|
|
}
|
|
return color;
|
|
}
|
|
ENDHLSL
|
|
}
|
|
}
|
|
|
|
FallBack "Hidden/Shader Graph/FallbackError"
|
|
|
|
Fallback Off
|
|
} |