Синтаксис:
Используется glsl
Shader "Unlit/BillboardSnow"
{
Properties
{
_Size("Size", Vector) = (5,5,5,0)
_MainTex ("Texture", 2D) = "white" {}
_Scaling("Scaling", Float) = 1.0
_FallSpeed("FallSpeed", Float) = 1.0
}
SubShader
{
Tags { "Queue"="Overlay-1" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" }
Blend SrcAlpha OneMinusSrcAlpha
ColorMask RGB
Cull Off Lighting Off
// ZWrite Off
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
// #pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
// UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float _Scaling;
float _FallSpeed;
float3 _Size;
v2f vert (appdata v)
{
v2f o;
v.vertex.y=frac(v.vertex.y-_WorldSpaceCameraPos.y/_Size.y-_Time.x*_FallSpeed)*_Size.y-_Size.y/2;
v.vertex.xz=frac(v.vertex.xz-_WorldSpaceCameraPos.xz/_Size.xz)*_Size.xz-_Size.xz/2;
float4 viewSpaceOrigin = mul( UNITY_MATRIX_MV, v.vertex);
float2 disp = v.uv-0.5;
float4 scaledVertexLocalPos = float4( disp.x, disp.y, 0.0, 0.0) * _Scaling;
o.vertex = mul( UNITY_MATRIX_P, viewSpaceOrigin + scaledVertexLocalPos);
o.uv = v.uv;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv);
// apply fog
// UNITY_APPLY_FOG(i.fogCoord, col);
clip(col.a-0.1);
return col;
}
ENDCG
}
}
}
{
Properties
{
_Size("Size", Vector) = (5,5,5,0)
_MainTex ("Texture", 2D) = "white" {}
_Scaling("Scaling", Float) = 1.0
_FallSpeed("FallSpeed", Float) = 1.0
}
SubShader
{
Tags { "Queue"="Overlay-1" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" }
Blend SrcAlpha OneMinusSrcAlpha
ColorMask RGB
Cull Off Lighting Off
// ZWrite Off
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
// #pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
// UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float _Scaling;
float _FallSpeed;
float3 _Size;
v2f vert (appdata v)
{
v2f o;
v.vertex.y=frac(v.vertex.y-_WorldSpaceCameraPos.y/_Size.y-_Time.x*_FallSpeed)*_Size.y-_Size.y/2;
v.vertex.xz=frac(v.vertex.xz-_WorldSpaceCameraPos.xz/_Size.xz)*_Size.xz-_Size.xz/2;
float4 viewSpaceOrigin = mul( UNITY_MATRIX_MV, v.vertex);
float2 disp = v.uv-0.5;
float4 scaledVertexLocalPos = float4( disp.x, disp.y, 0.0, 0.0) * _Scaling;
o.vertex = mul( UNITY_MATRIX_P, viewSpaceOrigin + scaledVertexLocalPos);
o.uv = v.uv;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv);
// apply fog
// UNITY_APPLY_FOG(i.fogCoord, col);
clip(col.a-0.1);
return col;
}
ENDCG
}
}
}
Синтаксис:
Используется csharp
using UnityEngine;
//Костыль обновляющий положение объекта
[ExecuteInEditMode]
public class SnowToCameraPin : MonoBehaviour
{
private void OnWillRenderObject()
{
transform.position = Camera.current.transform.position;
}
void Reset()
{
GetComponent<MeshFilter>().sharedMesh.bounds = new Bounds(Vector3.zero, Vector3.one*1000000);
}
void Awake()
{
Reset();
}
}
//Костыль обновляющий положение объекта
[ExecuteInEditMode]
public class SnowToCameraPin : MonoBehaviour
{
private void OnWillRenderObject()
{
transform.position = Camera.current.transform.position;
}
void Reset()
{
GetComponent<MeshFilter>().sharedMesh.bounds = new Bounds(Vector3.zero, Vector3.one*1000000);
}
void Awake()
{
Reset();
}
}
Пак: https://yadi.sk/d/AmJDRxHipR_-JQ
Для правильной работы, вершины отдельных "частиц" должны быль скукожены в одну точку, также они должны находиться в диапазоне (-1; 1) по всем осям.