175 lines
6.4 KiB
Plaintext
175 lines
6.4 KiB
Plaintext
Shader "SepCore/Drop/Instanced Emission"
|
|
{
|
|
Properties
|
|
{
|
|
_BaseColor ("Base Color", Color) = (0.04, 0.85, 0.22, 1)
|
|
[HDR] _EmissionColor ("Emission Color", Color) = (0.12, 1, 0.38, 1)
|
|
_EmissionIntensity ("Emission Intensity", Range(0, 10)) = 1.8
|
|
_OutlineColor ("Outline Color", Color) = (0.005, 0.045, 0.02, 1)
|
|
_OutlineWidth ("Outline Width (Object Space)", Range(0, 0.05)) = 0.006
|
|
}
|
|
|
|
SubShader
|
|
{
|
|
Tags
|
|
{
|
|
"RenderType" = "Opaque"
|
|
"RenderPipeline" = "UniversalPipeline"
|
|
"Queue" = "Geometry"
|
|
}
|
|
|
|
LOD 100
|
|
|
|
Pass
|
|
{
|
|
Name "Outline"
|
|
Tags { "LightMode" = "SRPDefaultUnlit" }
|
|
Cull Front
|
|
ZWrite On
|
|
ZTest LEqual
|
|
|
|
HLSLPROGRAM
|
|
#pragma target 3.0
|
|
#pragma vertex OutlineVert
|
|
#pragma fragment OutlineFrag
|
|
#pragma multi_compile_instancing
|
|
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
|
|
|
UNITY_INSTANCING_BUFFER_START(DropOutlineProperties)
|
|
UNITY_DEFINE_INSTANCED_PROP(float4, _OutlineColor)
|
|
UNITY_DEFINE_INSTANCED_PROP(float, _OutlineWidth)
|
|
UNITY_INSTANCING_BUFFER_END(DropOutlineProperties)
|
|
|
|
struct OutlineAttributes
|
|
{
|
|
float4 positionOS : POSITION;
|
|
float3 normalOS : NORMAL;
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
};
|
|
|
|
struct OutlineVaryings
|
|
{
|
|
float4 positionCS : SV_POSITION;
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
};
|
|
|
|
OutlineVaryings OutlineVert(OutlineAttributes input)
|
|
{
|
|
OutlineVaryings output;
|
|
UNITY_SETUP_INSTANCE_ID(input);
|
|
UNITY_TRANSFER_INSTANCE_ID(input, output);
|
|
|
|
float outlineWidth = UNITY_ACCESS_INSTANCED_PROP(DropOutlineProperties, _OutlineWidth);
|
|
float3 expandedPositionOS = input.positionOS.xyz + normalize(input.normalOS) * outlineWidth;
|
|
output.positionCS = TransformObjectToHClip(expandedPositionOS);
|
|
return output;
|
|
}
|
|
|
|
half4 OutlineFrag(OutlineVaryings input) : SV_Target
|
|
{
|
|
UNITY_SETUP_INSTANCE_ID(input);
|
|
return UNITY_ACCESS_INSTANCED_PROP(DropOutlineProperties, _OutlineColor);
|
|
}
|
|
ENDHLSL
|
|
}
|
|
|
|
Pass
|
|
{
|
|
Name "ForwardLit"
|
|
Tags { "LightMode" = "UniversalForward" }
|
|
|
|
HLSLPROGRAM
|
|
#pragma target 3.0
|
|
#pragma vertex Vert
|
|
#pragma fragment Frag
|
|
#pragma multi_compile_instancing
|
|
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
|
|
#pragma multi_compile_fragment _ _SHADOWS_SOFT
|
|
#pragma multi_compile_fog
|
|
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
|
|
|
UNITY_INSTANCING_BUFFER_START(DropProperties)
|
|
UNITY_DEFINE_INSTANCED_PROP(float4, _BaseColor)
|
|
UNITY_DEFINE_INSTANCED_PROP(float4, _EmissionColor)
|
|
UNITY_DEFINE_INSTANCED_PROP(float, _EmissionIntensity)
|
|
UNITY_INSTANCING_BUFFER_END(DropProperties)
|
|
|
|
struct Attributes
|
|
{
|
|
float4 positionOS : POSITION;
|
|
float3 normalOS : NORMAL;
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
};
|
|
|
|
struct Varyings
|
|
{
|
|
float4 positionCS : SV_POSITION;
|
|
float3 normalWS : TEXCOORD0;
|
|
float4 shadowCoord : TEXCOORD1;
|
|
half fogFactor : TEXCOORD2;
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
};
|
|
|
|
Varyings Vert(Attributes input)
|
|
{
|
|
Varyings output;
|
|
UNITY_SETUP_INSTANCE_ID(input);
|
|
UNITY_TRANSFER_INSTANCE_ID(input, output);
|
|
|
|
VertexPositionInputs positionInputs = GetVertexPositionInputs(input.positionOS.xyz);
|
|
VertexNormalInputs normalInputs = GetVertexNormalInputs(input.normalOS);
|
|
|
|
output.positionCS = positionInputs.positionCS;
|
|
output.normalWS = normalInputs.normalWS;
|
|
output.shadowCoord = GetShadowCoord(positionInputs);
|
|
output.fogFactor = ComputeFogFactor(positionInputs.positionCS.z);
|
|
return output;
|
|
}
|
|
|
|
half4 Frag(Varyings input) : SV_Target
|
|
{
|
|
UNITY_SETUP_INSTANCE_ID(input);
|
|
|
|
half4 baseColor = UNITY_ACCESS_INSTANCED_PROP(DropProperties, _BaseColor);
|
|
half3 emissionColor = UNITY_ACCESS_INSTANCED_PROP(DropProperties, _EmissionColor).rgb;
|
|
half emissionIntensity = UNITY_ACCESS_INSTANCED_PROP(DropProperties, _EmissionIntensity);
|
|
|
|
half3 normalWS = normalize(input.normalWS);
|
|
Light mainLight = GetMainLight(input.shadowCoord);
|
|
half diffuse = saturate(dot(normalWS, mainLight.direction)) * mainLight.shadowAttenuation;
|
|
half3 ambientLighting = SampleSH(normalWS);
|
|
half3 baseLighting = baseColor.rgb * (ambientLighting + mainLight.color * diffuse);
|
|
half3 color = MixFog(baseLighting + emissionColor * emissionIntensity, input.fogFactor);
|
|
|
|
return half4(color, baseColor.a);
|
|
}
|
|
ENDHLSL
|
|
}
|
|
|
|
Pass
|
|
{
|
|
Name "ShadowCaster"
|
|
Tags { "LightMode" = "ShadowCaster" }
|
|
ZWrite On
|
|
ZTest LEqual
|
|
ColorMask 0
|
|
Cull Back
|
|
|
|
HLSLPROGRAM
|
|
#pragma target 3.0
|
|
#pragma vertex ShadowPassVertex
|
|
#pragma fragment ShadowPassFragment
|
|
#pragma multi_compile_instancing
|
|
#pragma multi_compile_vertex _ _CASTING_PUNCTUAL_LIGHT_SHADOW
|
|
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/Shaders/ShadowCasterPass.hlsl"
|
|
ENDHLSL
|
|
}
|
|
}
|
|
}
|