Unity Unlit Shader (vertex & fragment shader)
Unity3D/Shader 2020. 12. 22. 21:04SV_Target
These semantics signifiers communicate the “meaning” of these variables to the GPU.
Most often a fragment (pixel) shader outputs a color, and has an SV_Target semantic.
Vertex Shader defines the position where vertices composed of 3D coordinates will be drawn on the 2D screen.
Fragment Shader defines what color each pixel is drawn with. The color buffer is returned as the return value, and all objects not expressed in the color buffer are expressed in black.


// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "Unlit/NewUnlitShader"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
//vertex input
struct appdata
{
float4 vertex : POSITION; //semantics 변수의 용도를 알려줌 https://docs.unity3d.com/Manual/SL-VertexProgramInputs.html
float2 uv : TEXCOORD0;
};
//fragment input
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
//Vertex Shader defines the position where vertices composed of 3D coordinates will be drawn on the 2D screen.
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex); // UnityObjectToClipPos(v.vertex); //Transforms a point from object space to the camera’s clip space in homogeneous coordinates. This is the equivalent of mul(UNITY_MATRIX_MVP, float4(pos, 1.0)), and should be used in its place.
o.uv = TRANSFORM_TEX(v.uv, _MainTex); //The vertex and fragment programs here don’t do anything fancy; vertex program uses the TRANSFORM_TEX macro from UnityCG.cginc to make sure texture scale and offset is applied correctly, and fragment program just samples the texture and multiplies by the color property.
return o;
}
//Fragment Shader defines what color each pixel is drawn with. The color buffer is returned as the return value, and all objects not expressed in the color buffer are expressed in black.
//Most often a fragment (pixel) shader outputs a color, and has an SV_Target semantic.
//https://docs.unity3d.com/Manual/SL-VertexFragmentShaderExamples.html
//https://docs.unity3d.com/Manual/SL-ShaderSemantics.html
fixed4 frag (v2f i) : SV_Target //These semantics signifiers communicate the “meaning” of these variables to the GPU.
{
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv);
return col;
}
ENDCG
}
}
}
참고
hyeonu1258.github.io/2018/06/26/OpenGL%20Shader/#Vertex-Shader
docs.unity3d.com/Manual/SL-VertexFragmentShaderExamples.html
docs.unity3d.com/kr/2019.3/Manual/SL-ShaderSemantics.html
'Unity3D > Shader' 카테고리의 다른 글
Matcap (0) | 2020.12.23 |
---|---|
흔들리는 풀 (0) | 2020.12.23 |
Diffuse Warping (0) | 2020.12.21 |
끊어지는 음영 (0) | 2020.12.21 |
Vertex Shader (0) | 2020.12.21 |