Shader "Billboard" {
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 { "Queue"="Transparent" "RenderType"="Transparent" "DisableBatching"="True" }
LOD 200
CGPROGRAM
#pragma surface surf Standard fullforwardshadows vertex:vert alpha:fade
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
void vert(inout appdata_full v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input, o);
// apply object scale
v.vertex.xy *= float2(length(unity_ObjectToWorld._m00_m10_m20), length(unity_ObjectToWorld._m01_m11_m21));
// get the camera basis vectors
float3 forward = -normalize(UNITY_MATRIX_V._m20_m21_m22);
float3 up = normalize(UNITY_MATRIX_V._m10_m11_m12);
float3 right = normalize(UNITY_MATRIX_V._m00_m01_m02);
// rotate to face camera
float4x4 rotationMatrix = float4x4(right, 0,
up, 0,
forward, 0,
0, 0, 0, 1);
v.vertex = mul(v.vertex, rotationMatrix);
v.normal = mul(v.normal, rotationMatrix);
// undo object to world transform surface shader will apply
v.vertex.xyz = mul((float3x3)unity_WorldToObject, v.vertex.xyz);
v.normal = mul(v.normal, (float3x3)unity_ObjectToWorld);
}
void surf (Input IN, inout SurfaceOutputStandard o) {
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
// Metallic and smoothness come from slider variables
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Transparent/VertexLit"
}
Fragment code
Shader "billboards" {
Properties {
_MainTex ("Texture Image", 2D) = "white" {}
_ScaleX ("Scale X", Float) = 1.0
_ScaleY ("Scale Y", Float) = 1.0
}
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// User-specified uniforms
uniform sampler2D _MainTex;
uniform float _ScaleX;
uniform float _ScaleY;
struct vertexInput {
float4 vertex : POSITION;
float4 tex : TEXCOORD0;
};
struct vertexOutput {
float4 pos : SV_POSITION;
float4 tex : TEXCOORD0;
};
vertexOutput vert(vertexInput input)
{
vertexOutput output;
output.pos = mul(UNITY_MATRIX_P,
mul(UNITY_MATRIX_MV, float4(0.0, 0.0, 0.0, 1.0)) + float4(input.vertex.x, input.vertex.y, 0.0, 0.0) * float4(_ScaleX, _ScaleY, 1.0, 1.0));
output.tex = input.tex;
return output;
}
float4 frag(vertexOutput input) : COLOR
{
return tex2D(_MainTex, float2(input.tex.xy));
}
ENDCG
}
}
}
'Technical Report > Unity Shader' 카테고리의 다른 글
Fake FixedLight Environment (0) | 2018.08.14 |
---|---|
360 Equirectangular Projection in Unity (0) | 2018.08.07 |
Unity Surface Shader cginc를 활용한 shader 작성 (0) | 2018.04.22 |
Unity Unlit Receive Shadow (0) | 2018.02.05 |
Material properties and the GI system (0) | 2018.02.05 |