> 텍스쳐 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"
}

 

 

 

+ Recent posts