[unity] 유니티 쉐이더 공부 2
2021. 9. 5. 00:24
2021.09.04 - [컴퓨터/graphics] - [unity] 유니티 쉐이더 공부 1
[unity] 유니티 쉐이더 공부 1
지난 번에 공부했던 <유니티 쉐이더 스타트업>의 내용을 정리해두지 않으면 올해 안에 완벽하게 까먹을 것 같아서 처음부터 기록+복습해보고자 한다. 학교에서 GLSL은 조금(정말 조금) 배웠으니
kumonoueno.tistory.com
이어서! 피곤하지만 개강 초반이니까 열심히 써놔야지 (조금 있으면 플젝이 몰아쳐서 못쓸테니..ㅠㅠ)

Part 5
Shader "Custom/tex"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma surface surf Standard fullforwardshadows
sampler2D _MainTex;
struct Input
{
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutputStandard o)
{
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
텍스쳐 1장만 albedo로 출력하는 부분만 남긴 것
smoothness가 0이라 둔탁함
float4 결과=tex2D(샘플러,UV)
텍스쳐 출력 확인
Shader "Custom/tex"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma surface surf Standard
sampler2D _MainTex;
struct Input
{
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutputStandard o)
{
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = (c.r+c.g+c.b)/3;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
흑백으로 만들어보기(그레이스케일)
lerp: 선형보간
lerp(X,Y,s)
알파채널이 적용되지 않는 쉐이더
Shader "Custom/tex2"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_MainTex2 ("Albedo (RGB)", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma surface surf Standard
sampler2D _MainTex;
sampler2D _MainTex2;
struct Input
{
float2 uv_MainTex;
float2 uv_MainTex2;
};
void surf (Input IN, inout SurfaceOutputStandard o)
{
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
fixed4 d = tex2D (_MainTex2, IN.uv_MainTex2);
o.Albedo = lerp(c.rgb,d.rgb,0);
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
lerp의 인자를 1로 바꾸면
Shader "Custom/tex2"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_MainTex2 ("Albedo (RGB)", 2D) = "white" {}
_LerpRange("lerp range",Range(0,1))=0.5
}
SubShader
{
Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma surface surf Standard
sampler2D _MainTex;
sampler2D _MainTex2;
struct Input
{
float2 uv_MainTex;
float2 uv_MainTex2;
};
float _LerpRange;
void surf (Input IN, inout SurfaceOutputStandard o)
{
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
fixed4 d = tex2D (_MainTex2, IN.uv_MainTex2);
o.Albedo = lerp(c.rgb,d.rgb,_LerpRange);
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
알파채널 확인하기
o.Albedo = lerp(c.rgb,d.rgb,1-c.a);
Part 6
UV
o.Albedo = IN.uv_MainTex.x;
o.Albedo = IN.uv_MainTex.y;
fixed4 c = tex2D (_MainTex, IN.uv_MainTex+0.5) ;
텍스쳐가 왼-아래로 내려올 것이다
fixed4 c = tex2D (_MainTex, float2(IN.uv_MainTex.x,IN.uv_MainTex.y+_Time.y)) ;
y축으로 흘러가는 텍스쳐
Shader "Custom/fire"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_MainTex2 ("Albedo (RGB)", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Transparent" "Queue"="Transparent"}
CGPROGRAM
#pragma surface surf Standard alpha:fade
sampler2D _MainTex;
sampler2D _MainTex2;
struct Input
{
float2 uv_MainTex;
float2 uv_MainTex2;
};
void surf (Input IN, inout SurfaceOutputStandard o)
{
fixed4 c = tex2D (_MainTex, float2(IN.uv_MainTex.x,IN.uv_MainTex.y)) ;
fixed4 d = tex2D (_MainTex2,float2(IN.uv_MainTex2.x,IN.uv_MainTex2.y-_Time.y)) ;
o.Emission = d.rgb*c.rgb;
o.Alpha = d.a*c.a;
}
ENDCG
}
FallBack "Diffuse"
}
얼레벌레 올라가는 것처럼 보임
'컴퓨터 > graphics' 카테고리의 다른 글
[unity] 유니티 URP 셰이더 1 (0) | 2022.08.06 |
---|---|
[unity] 유니티 쉐이더 공부 4 (0) | 2022.02.22 |
[unity] 유니티 쉐이더 공부 3 (0) | 2021.09.08 |
[unity] 유니티 쉐이더 공부 1 (0) | 2021.09.04 |