텍스쳐 단순 입력 |
Shader "Custom/CGTest_TextureChange"
{
Properties{
_MainTex("Albedo", 2D) = "white" {}
}
SubShader{
Tags {
"RenderType" = "Opaque"
}
Pass{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
CBUFFER_START(UnityPerMaterial)
sampler2D _MainTex;
CBUFFER_END
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
};
v2f vert(appdata v) {
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
half4 frag(v2f i) : SV_Target{
half4 c;
c = tex2D(_MainTex, i.uv);
return c;
}
ENDCG
}
}
FallBack "Diffuse"
}
텍스쳐를 회색으로 만들기 |
다음과 같이 색상값을 낮춰서 흑백으로 만들수도 있다.
half4 frag(v2f i) : SV_Target{
half4 c;
c = tex2D(_MainTex, i.uv);
c = (c.x + c.y + c.z + c.w) / 10;
return c;
}
Lerp 사용해보기 |
Shader "Custom/CGTest_TextureChange"
{
Properties{
_MainTex("Albedo", 2D) = "white" {}
_SubTex("Albedo", 2D) = "white" {}
_LerpValue("LerpValue", Range(0,1)) = 1
}
SubShader{
Tags {
"RenderType" = "Opaque"
}
Pass{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
CBUFFER_START(UnityPerMaterial)
sampler2D _MainTex;
sampler2D _SubTex;
half _LerpValue;
CBUFFER_END
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
};
v2f vert(appdata v) {
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
half4 frag(v2f i) : SV_Target{
half4 c;
half4 a = tex2D(_MainTex, i.uv);
half4 b = tex2D(_SubTex, i.uv);
c = lerp(a.xyzw, b.xyzw, _LerpValue);
return c;
}
ENDCG
}
}
FallBack "Diffuse"
}
이미지 합치기 |
모기는 태워야 꿀맛!
Shader "Custom/CGTest_TextureChange"
{
Properties{
_MainTex("Albedo", 2D) = "white" {}
_SubTex("Albedo", 2D) = "white" {}
_LerpValue("LerpValue", Range(0,1)) = 1
}
SubShader{
Tags {
"RenderType" = "Opaque"
}
Pass{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
CBUFFER_START(UnityPerMaterial)
sampler2D _MainTex;
sampler2D _SubTex;
half _LerpValue;
CBUFFER_END
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
};
v2f vert(appdata v) {
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
half4 frag(v2f i) : SV_Target{
half4 c;
half4 a = tex2D(_MainTex, i.uv);
half4 b = tex2D(_SubTex, i.uv);
c = lerp(a.xyzw, b.xyzw, b.x);
return c;
}
ENDCG
}
}
FallBack "Diffuse"
}
반응형