Unity Shader Study01
Shader lab script
light and has high compatibility, but not good for high level effects.
Can't interconvert with other languages
not recommended
Surface shader script
Shader Lab + CG code
half
little automatic
Vertex & Fragment Shader
mannaul way have to handle all the settings.
Surface shader is recommended
아직 UV와 계산되지 않은 텍스쳐는 색상(float4)으로 나타낼 수 없다. 이를 sampler이라고 한다. text2D 는 2D텍스쳐를 받는 인터페이스를 만든다.
_____________________________________________________________________________
Shader "Unique/SurfaceShader01" { //name of the shader
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 { "RenderType"="Opaque" }
LOD 200
//snippet : calculate the light and the details
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
//input : input's needed to get from the engine
struct Input {
float2 uv_MainTex;
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
// #pragma instancing_options assumeuniformscaling
UNITY_INSTANCING_CBUFFER_START(Props)
// put more per-instance properties here
UNITY_INSTANCING_CBUFFER_END
// surf : function which can make color or image output , "name"
//void : no return function (will not be output)
//Input IN ,inout SurfaceOutputStandard o : 구조체를 각 IN과 o로 받음
//SurfaceOutputStandard 안에는 7개의 변수가 있고 이 변수를 불러서 간단히 값을 넣는것 만으로도 출력값을 만들 수 있다.
이중 특히 Albedo와 Emission을 신경써야 한다
float 의 1/2half 이며 fixed 는 더 작은 값
color나 vector길이는 fixed로 충분하며 범위나 정밀도가 필요하면 half 이외는 float
성능과 관련된 문제
fixed3 = float3 단 좀더 작은 범위 값
//abledo : 조명 연산을 추가로 받는다
//Emission : 순수한 색을 출력한다.
float(0,0,0) -1 = float(0,0,0) - float(-1,-1,-1);
float4 n = float (r,b,g,a) 이런식으로 구성
//#pragma surface surf Standard fullforwardshadows //noambient : can turn off ambient color
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 "Diffuse"
}
light and has high compatibility, but not good for high level effects.
Can't interconvert with other languages
not recommended
Surface shader script
Shader Lab + CG code
half
little automatic
Vertex & Fragment Shader
mannaul way have to handle all the settings.
Surface shader is recommended
아직 UV와 계산되지 않은 텍스쳐는 색상(float4)으로 나타낼 수 없다. 이를 sampler이라고 한다. text2D 는 2D텍스쳐를 받는 인터페이스를 만든다.
_____________________________________________________________________________
Shader "Unique/SurfaceShader01" { //name of the shader
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 { "RenderType"="Opaque" }
LOD 200
//snippet : calculate the light and the details
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
//input : input's needed to get from the engine
struct Input {
float2 uv_MainTex;
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
// #pragma instancing_options assumeuniformscaling
UNITY_INSTANCING_CBUFFER_START(Props)
// put more per-instance properties here
UNITY_INSTANCING_CBUFFER_END
// surf : function which can make color or image output , "name"
//void : no return function (will not be output)
//Input IN ,inout SurfaceOutputStandard o : 구조체를 각 IN과 o로 받음
//SurfaceOutputStandard 안에는 7개의 변수가 있고 이 변수를 불러서 간단히 값을 넣는것 만으로도 출력값을 만들 수 있다.
이중 특히 Albedo와 Emission을 신경써야 한다
float 의 1/2half 이며 fixed 는 더 작은 값
color나 vector길이는 fixed로 충분하며 범위나 정밀도가 필요하면 half 이외는 float
성능과 관련된 문제
fixed3 = float3 단 좀더 작은 범위 값
//abledo : 조명 연산을 추가로 받는다
//Emission : 순수한 색을 출력한다.
float(0,0,0) -1 = float(0,0,0) - float(-1,-1,-1);
float4 n = float (r,b,g,a) 이런식으로 구성
//#pragma surface surf Standard fullforwardshadows //noambient : can turn off ambient color
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 "Diffuse"
}
댓글
댓글 쓰기