> 텍스쳐 1장 출력 코드
https://developer.download.nvidia.com/cg/tex2D.html
tex2D
Name tex2D - performs a texture lookup in a given 2D sampler and, in some cases, a shadow comparison. May also use pre computed derivatives if those are provided. Synopsis float4 tex2D(sampler2D samp, float2 s) float4 tex2D(sampler2D samp, float2 s, int te
developer.download.nvidia.com
Shader "Custom/tex2"
{
Properties
{
_MainTex("Albedo(RGB)", 2D) = "grey" {}
}
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.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
> Writing Surface Shaders
#pragma surface surf Standard // 뒤에 붙여 그림자 등 제어 가능
https://docs.unity3d.com/Manual/SL-SurfaceShaders.html
Unity - Manual: Writing Surface Shaders
Surface Shaders and rendering paths Writing Surface Shaders In the Built-in Render PipelineA series of operations that take the contents of a Scene, and displays them on a screen. Unity lets you choose from pre-built render pipelines, or write your own. Mo
docs.unity3d.com
> 텍스쳐 흑백 변환
Shader "Custom/tex2"
{
Properties
{
_MainTex("Albedo(RGB)", 2D) = "grey" {}
}
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 ; // c로 대입된 텍스처의 rgb를 더한 후 /3해서 평균을 내 1자리 수로 만듬
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
'게임 그래픽 프로그래밍' 카테고리의 다른 글
셰이더3: 색 반전 및 밝기 조정 (0) | 2024.09.03 |
---|---|
셰이더3:lerp함수로 텍스쳐 섞기 (0) | 2024.09.03 |
셰이더2: 기본 코드로 빨강 셰이더 만들기 (2) | 2024.09.02 |
쉐이더2: 인터페이스 생성해 외부 입력 받기 (1) | 2024.09.02 |
쉐이더1 (2) | 2024.09.02 |