2020-12-22 03:13:43 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
|
|
Shader "Aetheria/Dithered Particles"
|
2020-11-27 22:47:33 +00:00
|
|
|
{
|
|
|
|
|
Properties
|
|
|
|
|
{
|
|
|
|
|
[HDR]_Color ("Color", Color) = (1,1,1,1)
|
|
|
|
|
_MainTex ("Albedo (RGB)", 2D) = "white" {}
|
|
|
|
|
}
|
2022-07-13 06:10:54 +01:00
|
|
|
|
|
|
|
|
CGINCLUDE
|
2020-11-27 22:47:33 +00:00
|
|
|
|
2022-07-13 06:10:54 +01:00
|
|
|
#include "UnityCG.cginc"
|
|
|
|
|
#include "Dither Functions.cginc"
|
|
|
|
|
|
|
|
|
|
struct appdata_particles {
|
|
|
|
|
float4 vertex : POSITION;
|
|
|
|
|
float4 color : COLOR;
|
|
|
|
|
float4 texcoord : TEXCOORD0;
|
|
|
|
|
};
|
2020-11-27 22:47:33 +00:00
|
|
|
|
2022-07-13 06:10:54 +01:00
|
|
|
struct v2f
|
|
|
|
|
{
|
|
|
|
|
float4 position : SV_POSITION;
|
|
|
|
|
float4 color : COLOR;
|
|
|
|
|
float2 texcoord : TEXCOORD0;
|
|
|
|
|
float2 ditherOffset : TEXCOORD1;
|
|
|
|
|
float4 screenPos : TEXCOORD2;
|
|
|
|
|
};
|
2020-11-27 22:47:33 +00:00
|
|
|
|
2022-07-13 06:10:54 +01:00
|
|
|
sampler2D _MainTex;
|
|
|
|
|
float4 _MainTex_ST;
|
|
|
|
|
float4 _Color;
|
|
|
|
|
float _Cutoff;
|
2020-11-27 22:47:33 +00:00
|
|
|
|
2022-07-13 06:10:54 +01:00
|
|
|
v2f vert(appdata_particles v)
|
|
|
|
|
{
|
|
|
|
|
v2f o;
|
|
|
|
|
o.position = UnityObjectToClipPos(v.vertex);
|
|
|
|
|
o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
|
|
|
|
|
o.ditherOffset = v.texcoord.zw;
|
|
|
|
|
o.color = v.color;
|
|
|
|
|
o.screenPos = ComputeScreenPos(o.position);
|
|
|
|
|
return o;
|
|
|
|
|
}
|
2020-11-27 22:47:33 +00:00
|
|
|
|
2022-07-13 06:10:54 +01:00
|
|
|
float4 frag(v2f i) : COLOR
|
|
|
|
|
{
|
|
|
|
|
float4 c = tex2D(_MainTex, i.texcoord) * _Color * i.color;
|
|
|
|
|
// Apply screen space dithering
|
|
|
|
|
float2 screenUV = i.screenPos.xy / i.screenPos.w;
|
|
|
|
|
ditherClip(screenUV + i.ditherOffset, c.a);
|
|
|
|
|
return c;
|
|
|
|
|
}
|
2026-10-29 11:18:37 +01:00
|
|
|
|
|
|
|
|
// The particle in the G-buffer: black, unreflective, emissive, so deferred lighting adds nothing and its depth is in the
|
|
|
|
|
// depth texture the nebula march fogs by. A forward pass draws after that texture is taken, so the fog paints over it.
|
|
|
|
|
struct GBufferOut
|
|
|
|
|
{
|
|
|
|
|
half4 albedo : SV_Target0;
|
|
|
|
|
half4 specular : SV_Target1;
|
|
|
|
|
half4 normal : SV_Target2;
|
|
|
|
|
half4 emission : SV_Target3;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
GBufferOut frag_deferred(v2f i)
|
|
|
|
|
{
|
|
|
|
|
float4 c = tex2D(_MainTex, i.texcoord) * _Color * i.color;
|
|
|
|
|
float2 screenUV = i.screenPos.xy / i.screenPos.w;
|
|
|
|
|
ditherClip(screenUV + i.ditherOffset, c.a);
|
|
|
|
|
GBufferOut o;
|
|
|
|
|
o.albedo = 0;
|
|
|
|
|
o.specular = 0;
|
|
|
|
|
o.normal = half4(.5, 1, .5, 1);
|
|
|
|
|
float3 light = c.rgb;
|
|
|
|
|
#ifndef UNITY_HDR_ON
|
|
|
|
|
light = exp2(-light);
|
|
|
|
|
#endif
|
|
|
|
|
o.emission = half4(light, 1);
|
|
|
|
|
return o;
|
|
|
|
|
}
|
2022-07-13 06:10:54 +01:00
|
|
|
|
|
|
|
|
float4 frag_shadow(v2f i) : COLOR
|
|
|
|
|
{
|
|
|
|
|
float4 c = tex2D(_MainTex, i.texcoord) * _Color.a * i.color.a;
|
|
|
|
|
// Apply screen space dithering
|
|
|
|
|
float2 screenUV = i.screenPos.xy / i.screenPos.w;
|
|
|
|
|
ditherClip(screenUV + i.ditherOffset, c.a);
|
|
|
|
|
SHADOW_CASTER_FRAGMENT(i)
|
|
|
|
|
}
|
2020-11-27 22:47:33 +00:00
|
|
|
|
2022-07-13 06:10:54 +01:00
|
|
|
ENDCG
|
2020-11-27 22:47:33 +00:00
|
|
|
|
2022-07-13 06:10:54 +01:00
|
|
|
SubShader
|
|
|
|
|
{
|
|
|
|
|
Tags { "Queue"="AlphaTest" "RenderType"="TransparentCutout" "IgnoreProjector"="True" }
|
|
|
|
|
Pass
|
2020-11-27 22:47:33 +00:00
|
|
|
{
|
2026-10-29 11:18:37 +01:00
|
|
|
Tags { "LightMode" = "ForwardBase" }
|
2022-07-13 06:10:54 +01:00
|
|
|
CGPROGRAM
|
|
|
|
|
#pragma vertex vert
|
|
|
|
|
#pragma fragment frag
|
|
|
|
|
ENDCG
|
2020-11-27 22:47:33 +00:00
|
|
|
}
|
2022-07-13 06:10:54 +01:00
|
|
|
Pass
|
2026-10-29 11:18:37 +01:00
|
|
|
{
|
|
|
|
|
Name "DEFERRED"
|
|
|
|
|
Tags { "LightMode" = "Deferred" }
|
|
|
|
|
CGPROGRAM
|
|
|
|
|
#pragma vertex vert
|
|
|
|
|
#pragma fragment frag_deferred
|
|
|
|
|
#pragma multi_compile ___ UNITY_HDR_ON
|
|
|
|
|
ENDCG
|
|
|
|
|
}
|
|
|
|
|
Pass
|
2022-07-13 06:10:54 +01:00
|
|
|
{
|
|
|
|
|
Name "ShadowCaster"
|
|
|
|
|
Tags { "LightMode" = "ShadowCaster" }
|
|
|
|
|
CGPROGRAM
|
|
|
|
|
#pragma vertex vert
|
|
|
|
|
#pragma fragment frag_shadow
|
|
|
|
|
ENDCG
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-27 22:47:33 +00:00
|
|
|
FallBack "Diffuse"
|
|
|
|
|
}
|