<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Standard Surface Shader Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<atom:link href="https://lycos7560.com/tag/standard-surface-shader/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>생각의 흐름을 타고 다니며 만드는 블로그</description>
	<lastBuildDate>Thu, 01 Dec 2022 06:42:09 +0000</lastBuildDate>
	<language>ko-KR</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://lycos7560.com/wp-content/uploads/2022/11/cropped-cropped-cropped-log-1-150x150-1-80x80.png</url>
	<title>Standard Surface Shader Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>12 &#8211; 03 홀로그램(Hologram) 만들기 (Unity Shader)</title>
		<link>https://lycos7560.com/unity/unity_shader/unity-shader-hologram-rim-light/2936/</link>
					<comments>https://lycos7560.com/unity/unity_shader/unity-shader-hologram-rim-light/2936/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Thu, 01 Dec 2022 06:42:08 +0000</pubDate>
				<category><![CDATA[Unity]]></category>
		<category><![CDATA[UnityShader]]></category>
		<category><![CDATA[2Pass]]></category>
		<category><![CDATA[fresnel]]></category>
		<category><![CDATA[Half-Lambert]]></category>
		<category><![CDATA[Hologram]]></category>
		<category><![CDATA[Holography]]></category>
		<category><![CDATA[Lambert]]></category>
		<category><![CDATA[Shader]]></category>
		<category><![CDATA[Standard Surface Shader]]></category>
		<category><![CDATA[Unity Shader]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[만들기]]></category>
		<category><![CDATA[쉐이더]]></category>
		<category><![CDATA[유니티]]></category>
		<category><![CDATA[홀로그램]]></category>
		<category><![CDATA[홀로그램 만들기]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=2936</guid>

					<description><![CDATA[<p>unity의 shader를 이용하여 홀로그램을 구현하는 방법을 정리하고 기록한 글입니다. + 2pass</p>
<p>The post <a href="https://lycos7560.com/unity/unity_shader/unity-shader-hologram-rim-light/2936/">12 &#8211; 03 홀로그램(Hologram) 만들기 (Unity Shader)</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<div style="height:61px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">12 &#8211; 03 홀로그램(Hologram) 만들기 (Unity Shader)</h2>



<div style="height:22px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">Rim 라이트를 구현할 수 있게 되었으니 알파를 사용하여 홀로그램을 만들 수 있습니다.</p>



<p class="has-medium-font-size">처음은 Lambert 기본형에서 시작합니다.</p>



<div style="height:52px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Shader "Custom/Holo"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        #pragma surface surf Lambert noambient

        #pragma target 3.0
        sampler2D _MainTex;

        struct Input
        {
            float2 uv_MainTex;
        };

        void surf (Input IN, inout SurfaceOutput o)
        {

            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            o.Albedo = c.rgb;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}</pre>



<div style="height:41px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="1547" height="519" src="https://lycos7560.com/wp-content/uploads/image-453.png" alt="" class="wp-image-2937" srcset="https://lycos7560.com/wp-content/uploads/image-453.png 1547w, https://lycos7560.com/wp-content/uploads/image-453-300x101.png 300w, https://lycos7560.com/wp-content/uploads/image-453-768x258.png 768w, https://lycos7560.com/wp-content/uploads/image-453-1536x515.png 1536w" sizes="(max-width: 1547px) 100vw, 1547px" /></figure>



<div style="height:67px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">다음은 Fresnel 기본 연산을 구현합니다.</p>



<p class="has-medium-font-size">잠시 Albedo 는 끄고 Emission 으로 결과를 확인하겠습니다.&nbsp;</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1310" height="1022" src="https://lycos7560.com/wp-content/uploads/image-454.png" alt="" class="wp-image-2938" srcset="https://lycos7560.com/wp-content/uploads/image-454.png 1310w, https://lycos7560.com/wp-content/uploads/image-454-300x234.png 300w, https://lycos7560.com/wp-content/uploads/image-454-768x599.png 768w" sizes="(max-width: 1310px) 100vw, 1310px" /></figure>



<div style="height:115px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">이제 반투명으로 구현하겠습니다.</p>



<p class="has-medium-font-size">홀로그램의 핵심원리는&nbsp;<strong>&#8221; Rim 라이트 연산을 알파 채널에 넣는다 &#8220;</strong>&nbsp;입니다.</p>



<p class="has-medium-font-size">반투명 구현은 앞 부분의 불을 만들 때 사용한 방식입니다.</p>



<div style="height:51px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1295" height="764" src="https://lycos7560.com/wp-content/uploads/image-455.png" alt="" class="wp-image-2939" srcset="https://lycos7560.com/wp-content/uploads/image-455.png 1295w, https://lycos7560.com/wp-content/uploads/image-455-300x177.png 300w, https://lycos7560.com/wp-content/uploads/image-455-768x453.png 768w" sizes="(max-width: 1295px) 100vw, 1295px" /></figure>



<div style="height:76px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">마지막으로 Emission에 원하는 색상을 넣어주면 됩니다.</p>



<div style="height:35px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="738" height="930" src="https://lycos7560.com/wp-content/uploads/image-456.png" alt="" class="wp-image-2940" srcset="https://lycos7560.com/wp-content/uploads/image-456.png 738w, https://lycos7560.com/wp-content/uploads/image-456-238x300.png 238w" sizes="(max-width: 738px) 100vw, 738px" /></figure>



<div style="height:59px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="700" style="aspect-ratio: 1232 / 700;" width="1232" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_15_11_19_52.mp4"></video></figure>



<div style="height:102px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">다음은 두께를 조절하게 해줍니다.</p>



<div style="height:46px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="812" height="1002" src="https://lycos7560.com/wp-content/uploads/image-457.png" alt="" class="wp-image-2942" srcset="https://lycos7560.com/wp-content/uploads/image-457.png 812w, https://lycos7560.com/wp-content/uploads/image-457-243x300.png 243w, https://lycos7560.com/wp-content/uploads/image-457-768x948.png 768w" sizes="(max-width: 812px) 100vw, 812px" /></figure>



<div style="height:39px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="836" style="aspect-ratio: 1480 / 836;" width="1480" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_15_12_29_337.mp4"></video></figure>



<div style="height:72px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">입안이 이상하게 구현된 것은 캐릭터가 입안까지 모델링이 되었기 때문입니다.</p>



<p class="has-medium-font-size">반투명이 되면서 반대편의 오브젝트나 안쪽의 오브젝트가 비쳐 보이는 것은 나중에 Z버퍼를 이용한 2pass 쉐이더를 사용하여 해결합니다.</p>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="has-medium-font-size wp-block-heading">전체 코드</h2>



<div style="height:23px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Shader "Custom/Holo"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _RimColor("RimColor", Color) = (1,1,1,1)
        _RimPower("RimPower", Range(1,10)) = 3
    }
    SubShader
    {
        Tags { "RenderType"="Transparent" "Queue"="Transparent" }
        LOD 200

        CGPROGRAM
        #pragma surface surf Lambert noambient alpha:fade

        #pragma target 3.0
        sampler2D _MainTex;
        float4 _RimColor;
        float _RimPower;

        struct Input
        {
            float2 uv_MainTex;
            float3 viewDir;
        };

        void surf (Input IN, inout SurfaceOutput o)
        {
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            float rim = saturate(dot(o.Normal, IN.viewDir));
            rim = pow(1 - rim, _RimPower);
            o.Emission = _RimColor.rgb;
            o.Alpha = rim;
        }
        ENDCG
    }
    FallBack "Diffuse"
}</pre>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<p class="has-medium-font-size">기본형은 만들었지만 이것만으로는 부족합니다.</p>



<p class="has-medium-font-size">다양한 효과를 넣어 봅시다.</p>



<div style="height:37px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">첫번째로 이 홀로그램을 깜빡이게 표현합니다.</p>



<p class="has-medium-font-size">Sin(_Time.y) 를 이용합니다.</p>



<div style="height:23px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="804" height="319" src="https://lycos7560.com/wp-content/uploads/image-458.png" alt="" class="wp-image-2944" srcset="https://lycos7560.com/wp-content/uploads/image-458.png 804w, https://lycos7560.com/wp-content/uploads/image-458-300x119.png 300w, https://lycos7560.com/wp-content/uploads/image-458-768x305.png 768w" sizes="(max-width: 804px) 100vw, 804px" /></figure>



<div style="height:87px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">깜빡임 속도 증가</p>



<div style="height:35px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="770" height="1037" src="https://lycos7560.com/wp-content/uploads/image-459.png" alt="" class="wp-image-2945" srcset="https://lycos7560.com/wp-content/uploads/image-459.png 770w, https://lycos7560.com/wp-content/uploads/image-459-223x300.png 223w, https://lycos7560.com/wp-content/uploads/image-459-768x1034.png 768w" sizes="(max-width: 770px) 100vw, 770px" /></figure>



<div style="height:36px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="828" style="aspect-ratio: 1448 / 828;" width="1448" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_15_16_27_300.mp4"></video></figure>



<div style="height:51px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">그런데, 이러면 깜빡일 떄 안보이는 시간이 너무 길게 나타납니다.</p>



<p class="has-medium-font-size">이것은 sin 또는 cos 곡선에서 일어나는 당연한 결과 입니다.</p>



<p class="has-medium-font-size">이 곡선들이 -1 ~ 1을 반복하다 보니 그림처럼 0 이하로 내려가는 부분이 절반이기 때문입니다.</p>



<div style="height:34px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="748" height="443" src="https://lycos7560.com/wp-content/uploads/image-460.png" alt="" class="wp-image-2947" srcset="https://lycos7560.com/wp-content/uploads/image-460.png 748w, https://lycos7560.com/wp-content/uploads/image-460-300x178.png 300w" sizes="(max-width: 748px) 100vw, 748px" /></figure>



<div style="height:88px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">saturate 해주는 것은 0 이나 &#8211; 1 이나 우리눈에 안보이는 것은 같기 때문에 의미가 없습니다.</p>



<div style="height:66px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">첫번째로&nbsp; * 0.5 + 0.5 를 사용하는 방법이 있습니다.</p>



<p class="has-medium-font-size">하프 램버트에서 사용했던 공식을 이용하면 -1 ~ 1을 0 ~ 1로 변화시켜주므로 부드럽게 지속적으로 반짝이는 곡선을 구할 수 있게 됩니다.</p>



<p class="has-medium-font-size">sin(_Time.y) * 0.5 + 0.5;</p>



<div style="height:24px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="789" height="488" src="https://lycos7560.com/wp-content/uploads/image-461.png" alt="" class="wp-image-2948" srcset="https://lycos7560.com/wp-content/uploads/image-461.png 789w, https://lycos7560.com/wp-content/uploads/image-461-300x186.png 300w, https://lycos7560.com/wp-content/uploads/image-461-768x475.png 768w" sizes="(max-width: 789px) 100vw, 789px" /></figure>



<div style="height:81px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">또 다른 방법으로는 abs () 함수를 사용하여 모든 음수를 양수로 변화시킬 수 있습니다.</p>



<p class="has-medium-font-size">abs(sin(_Time.y));</p>



<div style="height:32px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="790" height="503" src="https://lycos7560.com/wp-content/uploads/image-462.png" alt="" class="wp-image-2949" srcset="https://lycos7560.com/wp-content/uploads/image-462.png 790w, https://lycos7560.com/wp-content/uploads/image-462-300x191.png 300w, https://lycos7560.com/wp-content/uploads/image-462-768x489.png 768w" sizes="(max-width: 790px) 100vw, 790px" /></figure>



<div style="height:38px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="919" height="411" src="https://lycos7560.com/wp-content/uploads/image-463.png" alt="" class="wp-image-2950" srcset="https://lycos7560.com/wp-content/uploads/image-463.png 919w, https://lycos7560.com/wp-content/uploads/image-463-300x134.png 300w, https://lycos7560.com/wp-content/uploads/image-463-768x343.png 768w" sizes="(max-width: 919px) 100vw, 919px" /></figure>



<div style="height:42px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Shader "Custom/Holo"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _RimColor("RimColor", Color) = (1,1,1,1)
        _RimPower("RimPower", Range(1,10)) = 3
        _HoloTwinkling("HoloTwinkling",Range(1,5)) = 1
    }
    SubShader
    {
        Tags { "RenderType"="Transparent" "Queue"="Transparent" }
        LOD 200

        CGPROGRAM
        #pragma surface surf Lambert noambient alpha:fade

        #pragma target 3.0
        sampler2D _MainTex;
        float4 _RimColor;
        float _RimPower;
        float _HoloTwinkling;

        struct Input
        {
            float2 uv_MainTex;
            float3 viewDir;
        };

        void surf (Input IN, inout SurfaceOutput o)
        {

            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            float rim = saturate(dot(o.Normal, IN.viewDir));
            rim = pow(1 - rim, _RimPower);
            o.Emission = _RimColor.rgb;

            //o.Alpha = rim * sin(_Time.y * _HoloTwinkling);
            //o.Alpha = rim * sin(_Time.y * _HoloTwinkling) *0.5 + 0.5;
            o.Alpha = rim * abs(sin(_Time.y * _HoloTwinkling));
        }
        ENDCG
    }
    FallBack "Diffuse"
}</pre>



<div style="height:71px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="828" style="aspect-ratio: 1448 / 828;" width="1448" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_15_20_37_32.mp4"></video></figure>



<div style="height:43px" aria-hidden="true" class="wp-block-spacer"></div>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<p class="has-medium-font-size">다음은 홀로그램의 줄무늬가 올라가는 효과를 만들겠습니다.</p>



<p class="has-medium-font-size">버텍스 컬러를 이용하여 아래에서 위로 밝아지게 칠할 수도 있고, 두번째 UV를 펴는 방법도 있습니다.</p>



<p class="has-medium-font-size">여기서는 Input 구조체에서 다른 값을 이용하겠습니다.</p>



<div style="height:43px" aria-hidden="true" class="wp-block-spacer"></div>



<p><a href="https://docs.unity3d.com/Manual/SL-SurfaceShaders.html" target="_blank" rel="noreferrer noopener">https://docs.unity3d.com/Manual/SL-SurfaceShaders.html</a> &lt;- 영문</p>



<figure class="wp-block-image size-full"><a href="https://docs.unity3d.com/Manual/SL-SurfaceShaders.html" target="_blank" rel="noreferrer noopener"><img decoding="async" width="1302" height="319" src="https://lycos7560.com/wp-content/uploads/image-464.png" alt="" class="wp-image-2952" srcset="https://lycos7560.com/wp-content/uploads/image-464.png 1302w, https://lycos7560.com/wp-content/uploads/image-464-300x74.png 300w, https://lycos7560.com/wp-content/uploads/image-464-768x188.png 768w" sizes="(max-width: 1302px) 100vw, 1302px" /></a></figure>



<div style="height:42px" aria-hidden="true" class="wp-block-spacer"></div>



<p><a href="https://docs.unity3d.com/kr/2021.3/Manual/SL-SurfaceShaders.html" target="_blank" rel="noreferrer noopener">https://docs.unity3d.com/kr/2021.3/Manual/SL-SurfaceShaders.html</a> &lt;-한글</p>



<figure class="wp-block-image size-full"><a href="https://docs.unity3d.com/kr/2021.3/Manual/SL-SurfaceShaders.html" target="_blank" rel="noreferrer noopener"><img decoding="async" width="1306" height="318" src="https://lycos7560.com/wp-content/uploads/image-465.png" alt="" class="wp-image-2953" srcset="https://lycos7560.com/wp-content/uploads/image-465.png 1306w, https://lycos7560.com/wp-content/uploads/image-465-300x73.png 300w, https://lycos7560.com/wp-content/uploads/image-465-768x187.png 768w" sizes="(max-width: 1306px) 100vw, 1306px" /></a></figure>



<div style="height:118px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">표면 셰이더 입력 구조</h2>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">입력 구조&nbsp;Input에는 일반적으로 셰이더가 필요로 하는 텍스처 좌표가 있습니다. 텍스처 좌표의 이름은 텍스처 이름 앞에 “uv”가 붙는 형식으로 지어야 합니다(또는 두 번째 텍스처 좌표 세트를 사용하려면 “uv2”로 시작해야 합니다).</p>



<p class="has-medium-font-size">다음 값을 입력 구조에 추가할 수 있습니다.</p>



<div style="height:38px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">float3 viewDir &#8211; 뷰 방향을 포함합니다. 패럴랙스 이펙트, 림 조명 등의 컴퓨팅에 사용합니다.</p>



<p class="has-medium-font-size">float4와 COLOR 시맨틱 &#8211; 보간된 버텍스당 컬러를 포함합니다.</p>



<p class="has-medium-font-size">float4 screenPos &#8211; 반사 또는 스크린 공간 효과를 위한 스크린 공간 포지션을 포함합니다. GrabPass에는 적합하지 않습니다. ComputeGrabScreenPos 함수를 사용하여 커스텀 UV를 직접 계산해야 합니다.</p>



<p class="has-medium-font-size">float3 worldPos &#8211; 월드 공간 포지션을 포함합니다.</p>



<p class="has-medium-font-size">float3 worldRefl &#8211; 표면 셰이더가 o.Normal에 기록하지 않는 경우 월드 반사 벡터를 포함합니다. 예를 들어 리플렉트-디퓨즈(Reflect-Diffuse) 셰이더가 있습니다.</p>



<p class="has-medium-font-size">float3 worldNormal &#8211; 표면 셰이더가 o.Normal에 기록하지 않는 경우 월드 노멀 벡터를 포함합니다.</p>



<p class="has-medium-font-size">float3 worldRefl; INTERNAL_DATA &#8211; 표면 셰이더가 o.Normal에 기록하는 경우 월드 반사 벡터를 포함합니다. 픽셀당 노멀 맵을 기반으로 반사 벡터를 얻으려면 WorldReflectionVector (IN, o.Normal)를 사용해야 합니다. 예를 들어 리플렉트-범프드(Reflect-Bumped) 셰이더가 있습니다.</p>



<p class="has-medium-font-size">float3 worldNormal; INTERNAL_DATA &#8211; 표면 셰이더가 o.Normal에 기록하는 경우 월드 노멀 벡터를 포함합니다. 픽셀당 노멀 맵에 기반한 노멀 벡터를 얻으려면 WorldNormalVector (IN, o.Normal)를 사용해야 합니다.</p>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">이번에는 float3 worldPos를 사용합니다.</p>



<p class="has-medium-font-size">해당 변수의 기능을 확인하기 위해서 코드를 변경합니다.</p>



<div style="height:29px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="891" height="1003" src="https://lycos7560.com/wp-content/uploads/image-466.png" alt="" class="wp-image-2955" srcset="https://lycos7560.com/wp-content/uploads/image-466.png 891w, https://lycos7560.com/wp-content/uploads/image-466-267x300.png 267w, https://lycos7560.com/wp-content/uploads/image-466-768x865.png 768w" sizes="(max-width: 891px) 100vw, 891px" /></figure>



<div style="height:32px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="608" style="aspect-ratio: 840 / 608;" width="840" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_15_25_54_541.mp4"></video></figure>



<div style="height:56px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">해당 x, y, z 가 각각 r, g, b 에 대입하여 나타납니다.</p>



<p class="has-medium-font-size">우리는 상/하의 값인 Y만 필요하기 때문에 g (y)만 출력합니다.</p>



<div style="height:61px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="667" height="283" src="https://lycos7560.com/wp-content/uploads/image-467.png" alt="" class="wp-image-2957" srcset="https://lycos7560.com/wp-content/uploads/image-467.png 667w, https://lycos7560.com/wp-content/uploads/image-467-300x127.png 300w" sizes="(max-width: 667px) 100vw, 667px" /></figure>



<div style="height:28px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="608" style="aspect-ratio: 840 / 608;" width="840" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_15_28_17_74.mp4"></video></figure>



<div style="height:71px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">위의 코드로는&nbsp; 위로 올라가면 1이 넘는 값이 될 것이고 아래로 내려가면 -1의 아래 값으로 변하게 됩니다.</p>



<p class="has-medium-font-size">이러한 상황에서 유용한 내장 함수는 frac ( ) 입니다.</p>



<p class="has-medium-font-size">frac ( ) 은 안에 들어온 숫자의 &#8220;소수점 부분&#8221; 만 리턴해 줍니다.</p>



<p class="has-medium-font-size">즉, 1.1 은 0.1을 리턴하고 1.9는 0.9를 리턴합니다.</p>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="716" height="299" src="https://lycos7560.com/wp-content/uploads/image-468.png" alt="" class="wp-image-2959" srcset="https://lycos7560.com/wp-content/uploads/image-468.png 716w, https://lycos7560.com/wp-content/uploads/image-468-300x125.png 300w" sizes="(max-width: 716px) 100vw, 716px" /></figure>



<figure class="wp-block-video"><video height="608" style="aspect-ratio: 1088 / 608;" width="1088" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_15_29_32_254.mp4"></video></figure>



<div style="height:55px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">이제 흰 부분을 줄여 주겠습니다.</p>



<p class="has-medium-font-size">그라디에이션에서 검정 부분을 확장시키고 흰 부분을 줄이는 것은 이전에&nbsp; fresnel 을 배울 때 pow ( ) 함수를 이용하여 해결했습니다.</p>



<p class="has-medium-font-size">추가로 시간에 따라 위로 흘러가게 해줍니다.</p>



<div style="height:35px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="642" height="211" src="https://lycos7560.com/wp-content/uploads/image-469.png" alt="" class="wp-image-2961" srcset="https://lycos7560.com/wp-content/uploads/image-469.png 642w, https://lycos7560.com/wp-content/uploads/image-469-300x99.png 300w" sizes="(max-width: 642px) 100vw, 642px" /></figure>



<div style="height:57px" aria-hidden="true" class="wp-block-spacer"></div>



<div style="height:39px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">NormalMap 적용 후 변경이 가능하게 프로퍼티로 설정</p>



<div style="height:37px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Shader "Custom/Holo"
{
    Properties
    {
        _BumpMap("Normal Map", 2D) = "white" {}
        _RimColor ("RimColor", Color) = (1,1,1,1)
        _RimPower ("RimPower", Range(1,10)) = 3
        _HoloTwinkling ("HoloTwinkling",Range(1,5)) = 1
        _HoloSpeed ("HoloSpeed",Range(1,5)) = 1
        _HoloInterval ("HoloInterval",Range(1,5)) = 5
        
    }
    SubShader
    {
        Tags { "RenderType"="Transparent" "Queue"="Transparent" }
        LOD 200

        CGPROGRAM
        #pragma surface surf Lambert noambient alpha:fade

        #pragma target 3.0
        sampler2D _BumpMap;
        float4 _RimColor;
        float _RimPower;
        float _HoloTwinkling;
        float _HoloSpeed;
        float _HoloInterval;

        struct Input
        {
            float2 uv_BumpMap;
            float3 viewDir;
            float3 worldPos;
        };

        void surf (Input IN, inout SurfaceOutput o)
        {

            float3 d = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
            o.Normal = d;
            float rim = saturate(dot(o.Normal, IN.viewDir));
            rim = pow(1 - rim, _RimPower);
            o.Emission = pow (frac(IN.worldPos.g * _HoloInterval - _Time.y * _HoloSpeed), 5) + _RimColor.rgb;
            o.Alpha = rim * abs(sin(_Time.y * _HoloTwinkling));
        }
        ENDCG
    }
    FallBack "Transparent/Diffuse"
}</pre>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="584" style="aspect-ratio: 1080 / 584;" width="1080" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_15_32_17_586.mp4"></video></figure>



<div style="height:45px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="525" height="158" src="https://lycos7560.com/wp-content/uploads/image-470.png" alt="" class="wp-image-2963" srcset="https://lycos7560.com/wp-content/uploads/image-470.png 525w, https://lycos7560.com/wp-content/uploads/image-470-300x90.png 300w" sizes="(max-width: 525px) 100vw, 525px" /></figure>



<div style="height:35px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">Transparent/Diffuse 는 그림자를 생성하지 않게 하도록 넣는 코드입니다.</p>



<p class="has-medium-font-size">원래 FallBack은 그래픽 카드에서 이 쉐이더 연산을 실패 했을 때의 대체 쉐이더를 적는 란이지만</p>



<p class="has-medium-font-size">이 책의 저자분은 그림자 연산할 때 이 FallBack에 씌여진 쉐이더가 영향을 끼치게 된다는 것을 발견했다고 합니다.</p>



<p class="has-medium-font-size">이 쉐이더는 마치 이펙트와 같은 쉐이더이기 때문에 그림자가 필요없으므로 해당 코드를 넣습니다.</p>



<div style="height:48px" aria-hidden="true" class="wp-block-spacer"></div>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<h2 class="wp-block-heading">홀로그램 2Pass</h2>



<div style="height:37px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Shader "Custom/Holo"
{
    Properties
    {
        _BumpMap("Normal Map", 2D) = "white" {}
        _RimColor ("RimColor", Color) = (1,1,1,1)
        _RimPower ("RimPower", Range(1,10)) = 3
        _HoloTwinkling ("HoloTwinkling",Range(1,5)) = 1
        _HoloSpeed ("HoloSpeed",Range(1,5)) = 1
        _HoloInterval ("HoloInterval",Range(1,5)) = 5
        
    }
    SubShader
    {
        Tags { "RenderType"="Transparent" "Queue"="Transparent" }

        ZWrite On
        ColorMask 0

        LOD 200

        CGPROGRAM
        #pragma surface surf _NoLight
        #pragma target 3.0

        struct Input
        {
            float4 color:COLOR;
        };

        void surf (Input IN, inout SurfaceOutput o)
        {
        }

        float4 Lighting_NoLight(SurfaceOutput s, float3 lightDir, float atten) {
            return 0;
        }
        ENDCG

        ZWrite Off

        CGPROGRAM
        #pragma surface surf Lambert noambient alpha:fade

        #pragma target 3.0
        sampler2D _BumpMap;
        float4 _RimColor;
        float _RimPower;
        float _HoloTwinkling;
        float _HoloSpeed;
        float _HoloInterval;

        struct Input
        {
            float2 uv_BumpMap;
            float3 viewDir;
            float3 worldPos;
        };

        void surf (Input IN, inout SurfaceOutput o)
        {
            float3 d = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
            o.Normal = d;
            float rim = saturate(dot(o.Normal, IN.viewDir));
            rim = pow(1 - rim, _RimPower);
            o.Emission = pow (frac(IN.worldPos.g * _HoloInterval - _Time.y * _HoloSpeed), 30) + _RimColor.rgb;
            o.Alpha = rim * abs(sin(_Time.y * _HoloTwinkling));
        }
        ENDCG
    }
    FallBack "Transparent/Diffuse"
}</pre>



<div style="height:37px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="248" style="aspect-ratio: 696 / 248;" width="696" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_15_34_44_771.mp4"></video></figure>



<div style="height:127px" aria-hidden="true" class="wp-block-spacer"></div>
<p>The post <a href="https://lycos7560.com/unity/unity_shader/unity-shader-hologram-rim-light/2936/">12 &#8211; 03 홀로그램(Hologram) 만들기 (Unity Shader)</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/unity/unity_shader/unity-shader-hologram-rim-light/2936/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_15_11_19_52.mp4" length="415490" type="video/mp4" />
<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_15_12_29_337.mp4" length="1110285" type="video/mp4" />
<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_15_16_27_300.mp4" length="1509941" type="video/mp4" />
<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_15_20_37_32.mp4" length="1043747" type="video/mp4" />
<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_15_25_54_541.mp4" length="1406549" type="video/mp4" />
<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_15_28_17_74.mp4" length="611718" type="video/mp4" />
<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_15_29_32_254.mp4" length="325196" type="video/mp4" />
<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_15_32_17_586.mp4" length="5003364" type="video/mp4" />
<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_15_34_44_771.mp4" length="4246465" type="video/mp4" />

			</item>
		<item>
		<title>12 &#8211; 01 ~ 02 Rim 라이트의 기초 (Unity Shader)</title>
		<link>https://lycos7560.com/unity/unity_shader/unity-shader-rim-light-fresnel/2900/</link>
					<comments>https://lycos7560.com/unity/unity_shader/unity-shader-rim-light-fresnel/2900/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Thu, 01 Dec 2022 05:34:19 +0000</pubDate>
				<category><![CDATA[Unity]]></category>
		<category><![CDATA[UnityShader]]></category>
		<category><![CDATA[fresnel]]></category>
		<category><![CDATA[loat3 lightDir]]></category>
		<category><![CDATA[normalmap]]></category>
		<category><![CDATA[pow]]></category>
		<category><![CDATA[Rim]]></category>
		<category><![CDATA[RimLight]]></category>
		<category><![CDATA[Shader]]></category>
		<category><![CDATA[Standard Surface Shader]]></category>
		<category><![CDATA[Unity Shader]]></category>
		<category><![CDATA[viewDir]]></category>
		<category><![CDATA[공식]]></category>
		<category><![CDATA[노멀맵]]></category>
		<category><![CDATA[림]]></category>
		<category><![CDATA[림라이트]]></category>
		<category><![CDATA[방향 벡터]]></category>
		<category><![CDATA[쉐이더]]></category>
		<category><![CDATA[유니티]]></category>
		<category><![CDATA[프레넬]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=2900</guid>

					<description><![CDATA[<p>Rim 라이트의 기초와 유니티에서 프레넬 공식을 통하여 구현하는 방법을 예제를 통해 간단하게 작성하였습니다. </p>
<p>The post <a href="https://lycos7560.com/unity/unity_shader/unity-shader-rim-light-fresnel/2900/">12 &#8211; 01 ~ 02 Rim 라이트의 기초 (Unity Shader)</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<div style="height:45px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">12 &#8211; 01 ~ 02 Rim 라이트의 기초 (Unity Shader)</h2>



<div style="height:26px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">주변을 자세히 보면 모든 물체는 기울어 질수록 반사가 심해집니다.</p>



<p class="has-medium-font-size">실제로 모든 물체는 기울어 질수록 심하게 반사가 되며 그 반사율은 재질에 따라 다르게 나타납니다.</p>



<div style="height:38px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="804" height="353" src="https://lycos7560.com/wp-content/uploads/image-432.png" alt="" class="wp-image-2901" srcset="https://lycos7560.com/wp-content/uploads/image-432.png 804w, https://lycos7560.com/wp-content/uploads/image-432-300x132.png 300w, https://lycos7560.com/wp-content/uploads/image-432-768x337.png 768w" sizes="(max-width: 804px) 100vw, 804px" /></figure>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">만약 역광이 있을 떄, 털이나 반투명의 재질을 가진 물체들은 이 현상이 매우 강렬하게 나타날 수 있고</p>



<p class="has-medium-font-size">재질에 따라 때로는 잘 보이지 않게 나타날 수도 있습니다.</p>



<div style="height:38px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">사진 분야에서는 이것을 Rim Light ( 림 라이트 ) 라고 부릅니다.</p>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="553" height="239" src="https://lycos7560.com/wp-content/uploads/image-433.png" alt="" class="wp-image-2902" srcset="https://lycos7560.com/wp-content/uploads/image-433.png 553w, https://lycos7560.com/wp-content/uploads/image-433-300x130.png 300w" sizes="(max-width: 553px) 100vw, 553px" /></figure>



<div style="height:41px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">우리가 사용하는 Standard Shader와 같은 물리 기반의 쉐이더는 이러한 재질의 특성에 따른 반사율이</p>



<p class="has-medium-font-size">BRDF(Bidirectional Reflectance Distribution Function &#8211;&nbsp;양방향 반사 분포 함수) 를 이용하여 구현되어 있습니다.</p>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1341" height="809" src="https://lycos7560.com/wp-content/uploads/image-434.png" alt="" class="wp-image-2903" srcset="https://lycos7560.com/wp-content/uploads/image-434.png 1341w, https://lycos7560.com/wp-content/uploads/image-434-300x181.png 300w, https://lycos7560.com/wp-content/uploads/image-434-768x463.png 768w" sizes="(max-width: 1341px) 100vw, 1341px" /></figure>



<div style="height:44px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">이러한 반사 공식을&nbsp;<strong>fresnel (프레넬)</strong>&nbsp;이라 부릅니다.</p>



<p class="has-medium-font-size">이번에 설명할 fresnel 공식은 그보다는 간단하게, 빛의 방향과는 전혀 상관이 없게 만드는 효과입니다.</p>



<p class="has-medium-font-size">기본적으로 배경과 캐릭터의 분리나 강조를 위해, 혹은 선택되었을때나 특정 상태를 표현하기 위한 특수한 효과를 위해 사용합니다.</p>



<div style="height:26px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="959" height="695" src="https://lycos7560.com/wp-content/uploads/image-435.png" alt="" class="wp-image-2904" srcset="https://lycos7560.com/wp-content/uploads/image-435.png 959w, https://lycos7560.com/wp-content/uploads/image-435-300x217.png 300w, https://lycos7560.com/wp-content/uploads/image-435-768x557.png 768w" sizes="(max-width: 959px) 100vw, 959px" /></figure>



<div style="height:143px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">직접 확인해보기 위해서 아래 에셋을 사용했습니다. (무료)</p>



<p class="has-medium-font-size"><a href="https://assetstore.unity.com/packages/3d/characters/humanoids/barbarian-warrior-75519" target="_blank" rel="noreferrer noopener">https://assetstore.unity.com/packages/3d/characters/humanoids/barbarian-warrior-75519</a>&nbsp;&lt;- TestAsset</p>



<div style="height:36px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><a href="https://assetstore.unity.com/packages/3d/characters/humanoids/barbarian-warrior-75519" target="_blank" rel="noreferrer noopener"><img decoding="async" width="1304" height="317" src="https://lycos7560.com/wp-content/uploads/image-388.png" alt="" class="wp-image-2824" srcset="https://lycos7560.com/wp-content/uploads/image-388.png 1304w, https://lycos7560.com/wp-content/uploads/image-388-300x73.png 300w, https://lycos7560.com/wp-content/uploads/image-388-768x187.png 768w" sizes="(max-width: 1304px) 100vw, 1304px" /></a></figure>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading"><strong>fresnel 공식 구현</strong></h2>



<div style="height:17px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">텍스쳐를 한장만 받는 기본형으로 쉐이더를 변경합니다.</p>



<div style="height:21px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Shader "Custom/RimLight"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        
        #pragma surface surf Lambert noambient
        #pragma target 3.0

        sampler2D _MainTex;

        struct Input
        {
            float2 uv_MainTex;
        };

        void surf (Input IN, inout SurfaceOutput o)
        {
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            o.Albedo = c.rgb;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}</pre>



<div style="height:41px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1313" height="545" src="https://lycos7560.com/wp-content/uploads/image-436.png" alt="" class="wp-image-2905" srcset="https://lycos7560.com/wp-content/uploads/image-436.png 1313w, https://lycos7560.com/wp-content/uploads/image-436-300x125.png 300w, https://lycos7560.com/wp-content/uploads/image-436-768x319.png 768w" sizes="(max-width: 1313px) 100vw, 1313px" /></figure>



<div style="height:58px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">o.Albedo 를 0 으로 만들어서 검게 만들고 시작하는 것이 좋습니다. </p>



<div style="height:36px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1533" height="476" src="https://lycos7560.com/wp-content/uploads/image-438.png" alt="" class="wp-image-2907" srcset="https://lycos7560.com/wp-content/uploads/image-438.png 1533w, https://lycos7560.com/wp-content/uploads/image-438-300x93.png 300w, https://lycos7560.com/wp-content/uploads/image-438-768x238.png 768w" sizes="(max-width: 1533px) 100vw, 1533px" /></figure>



<div style="height:38px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">이전에 배운 Lambert 공식은 노멀 벡터와 조명 벡터를 dot 연산한 공식입니다.</p>



<p class="has-medium-font-size">이 공식을 간단하게 정의하면 두 벡터, 즉 노멀벡터와 조명 벡터의 각도가 같으면 밝고, 90도가 되면 어두워져서 검정색이 된다는 것입니다.</p>



<p class="has-medium-font-size">그렇다면 여기에서 input 구조체에서 다른 값을 받아 봅시다.</p>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<p><a href="https://docs.unity3d.com/Manual/SL-SurfaceShaders.html" target="_blank" rel="noreferrer noopener">https://docs.unity3d.com/Manual/SL-SurfaceShaders.html</a> &lt;- 영문</p>



<div style="height:21px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><a href="https://docs.unity3d.com/Manual/SL-SurfaceShaders.html" target="_blank" rel="noreferrer noopener"><img decoding="async" width="1309" height="315" src="https://lycos7560.com/wp-content/uploads/image-439.png" alt="" class="wp-image-2908" srcset="https://lycos7560.com/wp-content/uploads/image-439.png 1309w, https://lycos7560.com/wp-content/uploads/image-439-300x72.png 300w, https://lycos7560.com/wp-content/uploads/image-439-768x185.png 768w" sizes="(max-width: 1309px) 100vw, 1309px" /></a></figure>



<div style="height:32px" aria-hidden="true" class="wp-block-spacer"></div>



<p><a href="https://docs.unity3d.com/kr/2021.3/Manual/SL-SurfaceShaders.html" target="_blank" rel="noreferrer noopener">https://docs.unity3d.com/kr/2021.3/Manual/SL-SurfaceShaders.html</a> &lt;- 한글</p>



<figure class="wp-block-image size-full"><a href="https://docs.unity3d.com/kr/2021.3/Manual/SL-SurfaceShaders.html" target="_blank" rel="noreferrer noopener"><img decoding="async" width="1302" height="315" src="https://lycos7560.com/wp-content/uploads/image-440.png" alt="" class="wp-image-2909" srcset="https://lycos7560.com/wp-content/uploads/image-440.png 1302w, https://lycos7560.com/wp-content/uploads/image-440-300x73.png 300w, https://lycos7560.com/wp-content/uploads/image-440-768x186.png 768w" sizes="(max-width: 1302px) 100vw, 1302px" /></a></figure>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">표면 셰이더 입력 구조</p>



<p class="has-medium-font-size">입력 구조 Input에는 일반적으로 셰이더가 필요로 하는 텍스처 좌표가 있습니다. 텍스처 좌표의 이름은 텍스처 이름 앞에 “uv”가 붙는 형식으로 지어야 합니다(또는 두 번째 텍스처 좌표 세트를 사용하려면 “uv2”로 시작해야 합니다.)</p>



<div style="height:55px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="has-medium-font-size wp-block-heading">다음 값을 입력 구조에 추가할 수 있습니다.</h2>



<p class="has-medium-font-size">float3 viewDir&nbsp;&#8211; 뷰 방향을 포함합니다. 패럴랙스 이펙트, 림 조명 등의 컴퓨팅에 사용합니다.</p>



<p class="has-medium-font-size">float4와&nbsp;COLOR&nbsp;시맨틱 &#8211; 보간된 버텍스당 컬러를 포함합니다.</p>



<p class="has-medium-font-size">float4 screenPos&nbsp;&#8211; 반사 또는 스크린 공간 효과를 위한 스크린 공간 포지션을 포함합니다.&nbsp;GrabPass에는 적합하지 않습니다.&nbsp;ComputeGrabScreenPos&nbsp;함수를 사용하여 커스텀 UV를 직접 계산해야 합니다.</p>



<p class="has-medium-font-size">float3 worldPos&nbsp;&#8211; 월드 공간 포지션을 포함합니다.</p>



<p class="has-medium-font-size">float3 worldRefl&nbsp;&#8211;&nbsp;표면 셰이더가 o.Normal에 기록하지 않는 경우&nbsp;월드 반사 벡터를 포함합니다. 예를 들어 리플렉트-디퓨즈(Reflect-Diffuse) 셰이더가 있습니다.</p>



<p class="has-medium-font-size">float3 worldNormal&nbsp;&#8211;&nbsp;표면 셰이더가 o.Normal에 기록하지 않는 경우&nbsp;월드 노멀 벡터를 포함합니다.</p>



<p class="has-medium-font-size">float3 worldRefl; INTERNAL_DATA&nbsp;&#8211;&nbsp;표면 셰이더가 o.Normal에 기록하는 경우&nbsp;월드 반사 벡터를 포함합니다. 픽셀당 노멀 맵을 기반으로 반사 벡터를 얻으려면&nbsp;WorldReflectionVector (IN, o.Normal)를 사용해야 합니다. 예를 들어 리플렉트-범프드(Reflect-Bumped) 셰이더가 있습니다.</p>



<p class="has-medium-font-size">float3 worldNormal; INTERNAL_DATA&nbsp;&#8211;&nbsp;표면 셰이더가 o.Normal에 기록하는 경우&nbsp;월드 노멀 벡터를 포함합니다. 픽셀당 노멀 맵에 기반한 노멀 벡터를 얻으려면&nbsp;WorldNormalVector (IN, o.Normal)를 사용해야 합니다.</p>



<div style="height:84px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">우리가 사용할 값은 float3 viewDir 입니다.</p>



<p class="has-medium-font-size">float3 는 3차원 벡터 Input 구조체 안에 있는 것으로 봐서 엔진에서 받을 수 있는 데이터입니다.</p>



<div style="height:27px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="718" height="186" src="https://lycos7560.com/wp-content/uploads/image-441.png" alt="" class="wp-image-2911" srcset="https://lycos7560.com/wp-content/uploads/image-441.png 718w, https://lycos7560.com/wp-content/uploads/image-441-300x78.png 300w" sizes="(max-width: 718px) 100vw, 718px" /></figure>



<div style="height:71px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">float3 lightDir가 <strong>버텍스에서 바라보는 조명의 방향을 나타내는 길이가 1인 벡터</strong>라면</p>



<div style="height:25px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1076" height="623" src="https://lycos7560.com/wp-content/uploads/image-442.png" alt="" class="wp-image-2912" srcset="https://lycos7560.com/wp-content/uploads/image-442.png 1076w, https://lycos7560.com/wp-content/uploads/image-442-300x174.png 300w, https://lycos7560.com/wp-content/uploads/image-442-768x445.png 768w" sizes="(max-width: 1076px) 100vw, 1076px" /></figure>



<div style="height:37px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">float3 viewDir 은 <strong>버텍스에서 바라보는 카메라의 방향</strong>을 나타냅니다.</p>



<div style="height:35px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1071" height="646" src="https://lycos7560.com/wp-content/uploads/image-443.png" alt="" class="wp-image-2913" srcset="https://lycos7560.com/wp-content/uploads/image-443.png 1071w, https://lycos7560.com/wp-content/uploads/image-443-300x181.png 300w, https://lycos7560.com/wp-content/uploads/image-443-768x463.png 768w" sizes="(max-width: 1071px) 100vw, 1071px" /></figure>



<div style="height:38px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">그럼 Normal dot lightDir&nbsp; 대신&nbsp; Normal dot viewDir 을 하면</p>



<p class="has-medium-font-size">카메라가 마치 조명처럼 인식되어 내가 바라보는 방향이 계속 밝아진다는 것입니다.&nbsp;</p>



<div style="height:29px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="878" height="445" src="https://lycos7560.com/wp-content/uploads/image-444.png" alt="" class="wp-image-2914" srcset="https://lycos7560.com/wp-content/uploads/image-444.png 878w, https://lycos7560.com/wp-content/uploads/image-444-300x152.png 300w, https://lycos7560.com/wp-content/uploads/image-444-768x389.png 768w" sizes="(max-width: 878px) 100vw, 878px" /></figure>



<div style="height:35px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="832" style="aspect-ratio: 1488 / 832;" width="1488" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_14_20_50_14.mp4"></video></figure>



<div style="height:64px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">반전</h2>



<div style="height:28px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="701" height="385" src="https://lycos7560.com/wp-content/uploads/image-445.png" alt="" class="wp-image-2916" srcset="https://lycos7560.com/wp-content/uploads/image-445.png 701w, https://lycos7560.com/wp-content/uploads/image-445-300x165.png 300w" sizes="(max-width: 701px) 100vw, 701px" /></figure>



<div style="height:22px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="832" style="aspect-ratio: 1216 / 832;" width="1216" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_14_22_41_652.mp4"></video></figure>



<div style="height:35px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Shader "Custom/RimLight"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        
        #pragma surface surf Lambert noambient
        #pragma target 3.0

        sampler2D _MainTex;

        struct Input
        {
            float2 uv_MainTex;
            float3 viewDir;
        };

        void surf (Input IN, inout SurfaceOutput o)
        {
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            float rim = dot(o.Normal, IN.viewDir);
            o.Emission = 1 - rim; // 결과 뒤집기
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}</pre>



<div style="height:88px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">위에서 조심할 내용은 dot 연산은 -1 까지 내려가서 나중에 결과가 이상해 질 수 가 있습니다.   saturate() 를 잊지마세요</p>



<div style="height:47px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">보는 각도를 바꿔도 언제나 외각이 밝아 보이면서 이제 Rim 라이트처럼 보이기 시작합니다.</p>



<p class="has-medium-font-size">그런데 Rim라이트가 너무 두꺼워서 Rim 라이트 느낌이 살아나지 않습니다.</p>



<p class="has-medium-font-size">흰테두리를 더 얇게 만들어줄 필요가 있습니다.</p>



<div style="height:55px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">검정부터 흰색까지 변하는 음영을 표로 보면 아래와 같습니다.</p>



<p class="has-medium-font-size">가로축은 1 &#8211; dot(o.Normal, IN.viewDir) 이고 세로축은 색상 (흑백)을 의미합니다. 두 벡터의 각도 차이가 벌어질수록, 색상도 흰색이 됩니다. </p>



<div style="height:65px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="563" height="457" src="https://lycos7560.com/wp-content/uploads/image-446.png" alt="" class="wp-image-2918" srcset="https://lycos7560.com/wp-content/uploads/image-446.png 563w, https://lycos7560.com/wp-content/uploads/image-446-300x244.png 300w" sizes="(max-width: 563px) 100vw, 563px" /></figure>



<div style="height:34px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">pow 를 이용하면 지수함수와 같은 그래프로 어두운 부분이 한참동안 존재하다가 갑자기 밝아지는 모양이 됩니다.</p>



<p class="has-medium-font-size">이 그래프를 이용하여 흰 테두리를 얇게 만듭니다.</p>



<div style="height:26px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="563" height="383" src="https://lycos7560.com/wp-content/uploads/image-447.png" alt="" class="wp-image-2919" srcset="https://lycos7560.com/wp-content/uploads/image-447.png 563w, https://lycos7560.com/wp-content/uploads/image-447-300x204.png 300w" sizes="(max-width: 563px) 100vw, 563px" /></figure>



<div style="height:46px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1538" height="639" src="https://lycos7560.com/wp-content/uploads/image-448.png" alt="" class="wp-image-2920" srcset="https://lycos7560.com/wp-content/uploads/image-448.png 1538w, https://lycos7560.com/wp-content/uploads/image-448-300x125.png 300w, https://lycos7560.com/wp-content/uploads/image-448-768x319.png 768w, https://lycos7560.com/wp-content/uploads/image-448-1536x638.png 1536w" sizes="(max-width: 1538px) 100vw, 1538px" /></figure>



<div style="height:64px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">이제 rim 라이트에 색상을 추가합니다.</h2>



<div style="height:41px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="895" height="891" src="https://lycos7560.com/wp-content/uploads/image-449.png" alt="" class="wp-image-2921" srcset="https://lycos7560.com/wp-content/uploads/image-449.png 895w, https://lycos7560.com/wp-content/uploads/image-449-300x300.png 300w, https://lycos7560.com/wp-content/uploads/image-449-150x150.png 150w, https://lycos7560.com/wp-content/uploads/image-449-768x765.png 768w" sizes="(max-width: 895px) 100vw, 895px" /></figure>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="972" style="aspect-ratio: 1424 / 972;" width="1424" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_14_25_40_789.mp4"></video></figure>



<div style="height:51px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">두께 조절 프로퍼티도 만들어줍니다.</p>



<div style="height:32px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="908" height="1051" src="https://lycos7560.com/wp-content/uploads/image-450.png" alt="" class="wp-image-2923" srcset="https://lycos7560.com/wp-content/uploads/image-450.png 908w, https://lycos7560.com/wp-content/uploads/image-450-259x300.png 259w, https://lycos7560.com/wp-content/uploads/image-450-768x889.png 768w" sizes="(max-width: 908px) 100vw, 908px" /></figure>



<div style="height:27px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="972" style="aspect-ratio: 1728 / 972;" width="1728" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_14_26_59_679.mp4"></video></figure>



<div style="height:59px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">NormalMap 추가</h2>



<div style="height:29px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">Rim 연산에서 o.Normal을 사용하기 때문에 반드시 Rim라이트 연산 이전에 NormalMap 을 적용시켜줘야 합니다.</p>



<div style="height:28px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="762" height="1063" src="https://lycos7560.com/wp-content/uploads/image-451.png" alt="" class="wp-image-2925" srcset="https://lycos7560.com/wp-content/uploads/image-451.png 762w, https://lycos7560.com/wp-content/uploads/image-451-215x300.png 215w" sizes="(max-width: 762px) 100vw, 762px" /></figure>



<div style="height:34px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="836" style="aspect-ratio: 1480 / 836;" width="1480" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_14_29_23_149.mp4"></video></figure>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">이제 dot 연산에서 -1로 넘어가는 부분을 막아주고 noambient 까지 지워서 완성합니다.</p>



<div style="height:35px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="818" height="1057" src="https://lycos7560.com/wp-content/uploads/image-452.png" alt="" class="wp-image-2927" srcset="https://lycos7560.com/wp-content/uploads/image-452.png 818w, https://lycos7560.com/wp-content/uploads/image-452-232x300.png 232w, https://lycos7560.com/wp-content/uploads/image-452-768x992.png 768w" sizes="(max-width: 818px) 100vw, 818px" /></figure>



<div style="height:74px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="836" style="aspect-ratio: 1480 / 836;" width="1480" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_14_30_45_465.mp4"></video></figure>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">이것이 Rim 라이트라고 부르는 Fresnel 이 적용된 결과 입니다.</p>



<p class="has-medium-font-size">게임에서 캐릭터가 데미지를 입었을 때나 선택할 때, 혹은 단순히 배경과 분리된 느낌을 원할 때 자주 사용되는 방식이지만</p>



<p class="has-medium-font-size">실제 존재하는 Rim 라이트를 구현했다고 부르기에는 약간 부족합니다.</p>



<p class="has-medium-font-size">우리가 만든 Rim 라이트는 조명의 방향과 전혀 연관이 없습니다.</p>



<p class="has-medium-font-size">이상적인 Rim 라이트는 역광일 때 주로 나타나고 직광일 때는 보이지 않습니다. (나중에 커스텀 라이트를 만들 때 가능합니다.)</p>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
<p>The post <a href="https://lycos7560.com/unity/unity_shader/unity-shader-rim-light-fresnel/2900/">12 &#8211; 01 ~ 02 Rim 라이트의 기초 (Unity Shader)</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/unity/unity_shader/unity-shader-rim-light-fresnel/2900/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_14_20_50_14.mp4" length="2364166" type="video/mp4" />
<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_14_22_41_652.mp4" length="3371153" type="video/mp4" />
<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_14_25_40_789.mp4" length="1297617" type="video/mp4" />
<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_14_26_59_679.mp4" length="1234314" type="video/mp4" />
<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_14_29_23_149.mp4" length="825114" type="video/mp4" />
<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_14_30_45_465.mp4" length="3354833" type="video/mp4" />

			</item>
		<item>
		<title>11 &#8211; 03 ~ 04 Half-Lambert(하프 램버트) 연산 및 완성 (Unity Shader)</title>
		<link>https://lycos7560.com/unity/unity_shader/unity_shader-half-lambert/2873/</link>
					<comments>https://lycos7560.com/unity/unity_shader/unity_shader-half-lambert/2873/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Thu, 01 Dec 2022 05:04:08 +0000</pubDate>
				<category><![CDATA[Unity]]></category>
		<category><![CDATA[UnityShader]]></category>
		<category><![CDATA[atten]]></category>
		<category><![CDATA[Half-Lambert]]></category>
		<category><![CDATA[Lambert]]></category>
		<category><![CDATA[light]]></category>
		<category><![CDATA[lighting]]></category>
		<category><![CDATA[Shader]]></category>
		<category><![CDATA[Standard Surface Shader]]></category>
		<category><![CDATA[Unity Shader]]></category>
		<category><![CDATA[공식]]></category>
		<category><![CDATA[램버트]]></category>
		<category><![CDATA[쉐이더]]></category>
		<category><![CDATA[연산]]></category>
		<category><![CDATA[영상]]></category>
		<category><![CDATA[유니티]]></category>
		<category><![CDATA[하프]]></category>
		<category><![CDATA[하프 램버트]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=2873</guid>

					<description><![CDATA[<p>Unity Shader에서 Half-Lambert(하프 램버트) 연산이 적용되는 방식을 간략하게 예제로 설명합니다.</p>
<p>The post <a href="https://lycos7560.com/unity/unity_shader/unity_shader-half-lambert/2873/">11 &#8211; 03 ~ 04 Half-Lambert(하프 램버트) 연산 및 완성 (Unity Shader)</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<div style="height:51px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">11 &#8211; 03 ~ 04 Half-Lambert(하프 램버트) 연산 및 완성 (Unity Shader)</h2>



<div style="height:28px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">Lambert 라이트는 꽤 가벼운 조명 공식이지만, cos 그래프 연산의 특성상 밝다가&nbsp;너무 갑자기 검게 음영이 떨어지는 단점이 있습니다.&nbsp;</p>



<p class="has-medium-font-size">그래서 이 단점을 해결하고자 만든 것이 Half-Lambert (하프 램버트) 공식입니다.</p>



<p class="has-medium-font-size">물리적으로는 옳지 않지만, 매우 가벼우며 보기 좋은 장점이 있습니다.</p>



<div style="height:24px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="870" height="407" src="https://lycos7560.com/wp-content/uploads/image-417.png" alt="" class="wp-image-2874" srcset="https://lycos7560.com/wp-content/uploads/image-417.png 870w, https://lycos7560.com/wp-content/uploads/image-417-300x140.png 300w, https://lycos7560.com/wp-content/uploads/image-417-768x359.png 768w" sizes="(max-width: 870px) 100vw, 870px" /></figure>



<div style="height:24px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">저번에 글에서 사용한 코드에서 시작하겠습니다.&nbsp;</p>



<div style="height:22px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Shader "Custom/CustomLight"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _BumpMap("Normal Map", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        #pragma surface surf _MyLight noambient  
        #pragma target 3.0

        sampler2D _MainTex;
        sampler2D _BumpMap;

        struct Input
        {
            float2 uv_MainTex;
            float2 uv_BumpMap;
        };

        void surf (Input IN, inout SurfaceOutput o)
        {

            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            float3 d = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
            o.Normal = d;
            o.Albedo = c.rgb;
            o.Alpha = c.a;
        }

        
        float4 Lighting_MyLight(SurfaceOutput s, float3 lightDir, float atten)
        {
            float ndotl = saturate(dot(s.Normal, lightDir));
            return ndotl;
        }

        ENDCG
    }
    FallBack "Diffuse"
}</pre>



<div style="height:51px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">직접 확인해보기 위해서 아래 에셋을 사용했습니다. (무료)</p>



<p class="has-medium-font-size"><a href="https://assetstore.unity.com/packages/3d/characters/humanoids/barbarian-warrior-75519" target="_blank" rel="noreferrer noopener">https://assetstore.unity.com/packages/3d/characters/humanoids/barbarian-warrior-75519</a>&nbsp;&lt;- TestAsset</p>



<div style="height:36px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><a href="https://assetstore.unity.com/packages/3d/characters/humanoids/barbarian-warrior-75519" target="_blank" rel="noreferrer noopener"><img decoding="async" width="1304" height="317" src="https://lycos7560.com/wp-content/uploads/image-388.png" alt="" class="wp-image-2824" srcset="https://lycos7560.com/wp-content/uploads/image-388.png 1304w, https://lycos7560.com/wp-content/uploads/image-388-300x73.png 300w, https://lycos7560.com/wp-content/uploads/image-388-768x187.png 768w" sizes="(max-width: 1304px) 100vw, 1304px" /></a></figure>



<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1520" height="508" src="https://lycos7560.com/wp-content/uploads/image-418.png" alt="" class="wp-image-2875" srcset="https://lycos7560.com/wp-content/uploads/image-418.png 1520w, https://lycos7560.com/wp-content/uploads/image-418-300x100.png 300w, https://lycos7560.com/wp-content/uploads/image-418-768x257.png 768w" sizes="(max-width: 1520px) 100vw, 1520px" /></figure>



<div style="height:29px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">위의 이미지는 saturate() 함수로 인하여 0 이하의 값은 전부 0 이 되었습니다.</p>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="885" height="860" src="https://lycos7560.com/wp-content/uploads/image-419.png" alt="" class="wp-image-2876" srcset="https://lycos7560.com/wp-content/uploads/image-419.png 885w, https://lycos7560.com/wp-content/uploads/image-419-300x292.png 300w, https://lycos7560.com/wp-content/uploads/image-419-768x746.png 768w" sizes="(max-width: 885px) 100vw, 885px" /></figure>



<div style="height:28px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">saturate() 를 다시 제거해서 다시 -1 ~ 1까지의 범위를 출력하도록 만들어 줍니다.</p>



<div style="height:22px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1181" height="234" src="https://lycos7560.com/wp-content/uploads/image-420.png" alt="" class="wp-image-2877" srcset="https://lycos7560.com/wp-content/uploads/image-420.png 1181w, https://lycos7560.com/wp-content/uploads/image-420-300x59.png 300w, https://lycos7560.com/wp-content/uploads/image-420-768x152.png 768w" sizes="(max-width: 1181px) 100vw, 1181px" /></figure>



<div style="height:37px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1097" height="578" src="https://lycos7560.com/wp-content/uploads/image-421.png" alt="" class="wp-image-2878" srcset="https://lycos7560.com/wp-content/uploads/image-421.png 1097w, https://lycos7560.com/wp-content/uploads/image-421-300x158.png 300w, https://lycos7560.com/wp-content/uploads/image-421-768x405.png 768w" sizes="(max-width: 1097px) 100vw, 1097px" /></figure>



<div style="height:41px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">변경 전</p>



<div style="height:45px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="840" style="aspect-ratio: 1272 / 840;" width="1272" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_13_40_14_926.mp4"></video></figure>



<div style="height:62px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">그리고 라이팅의 결과물에&nbsp; Half- Lamber ( 하프 람버트 ) 공식인&nbsp;&nbsp;<strong>* 0.5 + 0.5</strong>&nbsp; 를 적용해줍니다.</p>



<div style="height:52px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="948" height="167" src="https://lycos7560.com/wp-content/uploads/image-422.png" alt="" class="wp-image-2880" srcset="https://lycos7560.com/wp-content/uploads/image-422.png 948w, https://lycos7560.com/wp-content/uploads/image-422-300x53.png 300w, https://lycos7560.com/wp-content/uploads/image-422-768x135.png 768w" sizes="(max-width: 948px) 100vw, 948px" /></figure>



<div style="height:76px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">Half- Lamber ( 하프 람버트 공식) 적용 후</h2>



<div style="height:35px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="832" style="aspect-ratio: 1304 / 832;" width="1304" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_13_43_51_403.mp4"></video></figure>



<div style="height:55px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size"><strong>* 0.5 + 0.5</strong>&nbsp; 의 식은 -1 에서부터 1까지의 숫자를 0 에서 부터 1까지의 범위로 만들어 줍니다.</p>



<p class="has-medium-font-size">아래의 푸른 cos 이 붉은 라인으로 끌어 올라오게 됩니다.</p>



<p class="has-medium-font-size">이로 인하여 매우 부드러운 결과 값이 나오게 됩니다.</p>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="802" height="732" src="https://lycos7560.com/wp-content/uploads/image-423.png" alt="" class="wp-image-2882" srcset="https://lycos7560.com/wp-content/uploads/image-423.png 802w, https://lycos7560.com/wp-content/uploads/image-423-300x274.png 300w, https://lycos7560.com/wp-content/uploads/image-423-768x701.png 768w" sizes="(max-width: 802px) 100vw, 802px" /></figure>



<div style="height:25px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">실제 사용할 때에는 빛의 영향을 좀 줄이고자 제곱을 해서 사용합니다.&nbsp;&nbsp;</p>



<div style="height:39px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1078" height="196" src="https://lycos7560.com/wp-content/uploads/image-424.png" alt="" class="wp-image-2883" srcset="https://lycos7560.com/wp-content/uploads/image-424.png 1078w, https://lycos7560.com/wp-content/uploads/image-424-300x55.png 300w, https://lycos7560.com/wp-content/uploads/image-424-768x140.png 768w" sizes="(max-width: 1078px) 100vw, 1078px" /></figure>



<div style="height:21px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Shader "Custom/CustomLight"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _BumpMap("Normal Map", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        #pragma surface surf _MyLight noambient  
        #pragma target 3.0

        sampler2D _MainTex;
        sampler2D _BumpMap;

        struct Input
        {
            float2 uv_MainTex;
            float2 uv_BumpMap;
        };

        void surf (Input IN, inout SurfaceOutput o)
        {

            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            float3 d = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
            o.Normal = d;
            o.Albedo = c.rgb;
            o.Alpha = c.a;
        }

        
        float4 Lighting_MyLight(SurfaceOutput s, float3 lightDir, float atten)
        {
            float ndotl = dot(s.Normal, lightDir) * 0.5 + 0.5;
            return pow(ndotl, 3); // pow는 제곱
        }

        ENDCG
    }
    FallBack "Diffuse"
}</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">pow&nbsp; &nbsp;제곱 적용 후</p>



<div style="height:29px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="828" style="aspect-ratio: 1304 / 828;" width="1304" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_13_45_59_585.mp4"></video></figure>



<div style="height:129px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">Lambert 라이트 완성하기</h2>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">위의 상황은 빛 방향에 따른 밝기만 구현되었을 뿐, 조명의 색상과 강고 / 빛 감쇄 Albedo 텍스쳐 는 전혀 적용되지 않았습니다.</p>



<p class="has-medium-font-size">아래에서 나머지 내용을 추가하겠습니다.&nbsp;</p>



<p class="has-medium-font-size">pow와 dot 계산식을 하나로 병합합니다.</p>



<div style="height:29px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="968" height="171" src="https://lycos7560.com/wp-content/uploads/image-425.png" alt="" class="wp-image-2885" srcset="https://lycos7560.com/wp-content/uploads/image-425.png 968w, https://lycos7560.com/wp-content/uploads/image-425-300x53.png 300w, https://lycos7560.com/wp-content/uploads/image-425-768x136.png 768w" sizes="(max-width: 968px) 100vw, 968px" /></figure>



<div style="height:54px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">제 텍스쳐와 조명색상, 감쇠를 연산해서 조명을 완성해줍니다.</p>



<div style="height:28px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1023" height="258" src="https://lycos7560.com/wp-content/uploads/image-426.png" alt="" class="wp-image-2886" srcset="https://lycos7560.com/wp-content/uploads/image-426.png 1023w, https://lycos7560.com/wp-content/uploads/image-426-300x76.png 300w, https://lycos7560.com/wp-content/uploads/image-426-768x194.png 768w" sizes="(max-width: 1023px) 100vw, 1023px" /></figure>



<div style="height:78px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">전체 코드</p>



<div style="height:24px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Shader "Custom/CustomLight"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _BumpMap("Normal Map", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        #pragma surface surf _MyLight noambient  
        #pragma target 3.0

        sampler2D _MainTex;
        sampler2D _BumpMap;

        struct Input
        {
            float2 uv_MainTex;
            float2 uv_BumpMap;
        };

        void surf (Input IN, inout SurfaceOutput o)
        {

            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            float3 d = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
            o.Normal = d;
            o.Albedo = c.rgb;
            o.Alpha = c.a;
        }

        
        float4 Lighting_MyLight(SurfaceOutput s, float3 lightDir, float atten)
        {
            float ndotl = pow ( dot(s.Normal, lightDir) * 0.5 + 0.5 , 3 );
            float4 final;
            final.rgb = ndotl * s.Albedo * _LightColor0.rgb * atten;
            final.a = s.Alpha;
            return final; 
        }

        ENDCG
    }
    FallBack "Diffuse"
}</pre>



<div style="height:46px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="540" height="441" src="https://lycos7560.com/wp-content/uploads/image-427.png" alt="" class="wp-image-2887" srcset="https://lycos7560.com/wp-content/uploads/image-427.png 540w, https://lycos7560.com/wp-content/uploads/image-427-300x245.png 300w" sizes="(max-width: 540px) 100vw, 540px" /></figure>



<div style="height:36px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">비어있던 MainTex도 넣어줍니다.</p>



<div style="height:44px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="828" style="aspect-ratio: 1336 / 828;" width="1336" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_13_49_10_310.mp4"></video></figure>



<div style="height:41px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="935" height="134" src="https://lycos7560.com/wp-content/uploads/image-428.png" alt="" class="wp-image-2889" srcset="https://lycos7560.com/wp-content/uploads/image-428.png 935w, https://lycos7560.com/wp-content/uploads/image-428-300x43.png 300w, https://lycos7560.com/wp-content/uploads/image-428-768x110.png 768w" sizes="(max-width: 935px) 100vw, 935px" /></figure>



<div style="height:164px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading"><strong>s.Albedo&nbsp;</strong></h2>



<p class="has-medium-font-size">Albedo 로 입력받은 텍스쳐 입니다.</p>



<p class="has-medium-font-size">SurfaceOutput이 s 로 들어왔으니 s.Albedo 가 됩니다.</p>



<p class="has-medium-font-size">여기서 들어온 Albedo 텍스쳐가 Lambert 라이트와 연산이 되어서 Diffuse (확산) 됩니다.&nbsp;</p>



<div style="height:35px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading"><strong>_LightColor0.rgb</strong></h2>



<p class="has-medium-font-size">이전에 연산했던 Ndotl 연산은 조명과 노멀의 각도를 표현한 것 뿐입니다.</p>



<p class="has-medium-font-size">조명의 색상이나 강도는 이 내장 변수를 이용해서 조명의 색상이나 강도를 가져옵니다.</p>



<p class="has-medium-font-size">이 변수를 곱한 후 조명의 생상과 강도를 변화시키면 그대로 반영됩니다.&nbsp;</p>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading"><strong>atten</strong></h2>



<p class="has-medium-font-size">빛의 감쇠 현상을 시뮬레이트합니다.</p>



<p class="has-medium-font-size">빛의 감쇠가 일어나는 경우는 아래와 같습니다. (atten를 계산하지 않으면 다음 일이 일어나지 않습니다.)</p>



<div style="height:62px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading"><strong>1. self shadow가 생기지 않습니다.</strong></h2>



<p class="has-medium-font-size">자신의 그림자를 자신이 받지 않습니다.</p>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1132" height="446" src="https://lycos7560.com/wp-content/uploads/image-429.png" alt="" class="wp-image-2890" srcset="https://lycos7560.com/wp-content/uploads/image-429.png 1132w, https://lycos7560.com/wp-content/uploads/image-429-300x118.png 300w, https://lycos7560.com/wp-content/uploads/image-429-768x303.png 768w" sizes="(max-width: 1132px) 100vw, 1132px" /></figure>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading"><strong><u>2. receive shadow가 동작하지 않습니다.</u></strong></h2>



<p class="has-medium-font-size">다른 물체가 그림자를 드리우지 못합니다.</p>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1519" height="479" src="https://lycos7560.com/wp-content/uploads/image-430.png" alt="" class="wp-image-2891" srcset="https://lycos7560.com/wp-content/uploads/image-430.png 1519w, https://lycos7560.com/wp-content/uploads/image-430-300x95.png 300w, https://lycos7560.com/wp-content/uploads/image-430-768x242.png 768w" sizes="(max-width: 1519px) 100vw, 1519px" /></figure>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading"><strong>3. 조명의 감쇠 현상이 일어나지 않습니다.</strong></h2>



<p class="has-medium-font-size">Directional 라이트에서는 확인이 불가능하고&nbsp; point 라이트에서 확인이 가능합니다.</p>



<p class="has-medium-font-size">point 라이트가 멀어질수록 어두워지는데 이것이 atten가 하는 일입니다.&nbsp;</p>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">atten 미적용</p>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="832" style="aspect-ratio: 1280 / 832;" width="1280" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_13_54_13_816.mp4"></video></figure>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">atten 적용</p>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="832" style="aspect-ratio: 1280 / 832;" width="1280" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_13_55_17_400.mp4"></video></figure>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">//&nbsp; noambient&nbsp; 제거</p>



<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Shader "Custom/CustomLight"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _BumpMap("Normal Map", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        #pragma surface surf _MyLight //noambient  
        #pragma target 3.0

        sampler2D _MainTex;
        sampler2D _BumpMap;

        struct Input
        {
            float2 uv_MainTex;
            float2 uv_BumpMap;
        };

        void surf (Input IN, inout SurfaceOutput o)
        {

            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            float3 d = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
            o.Normal = d;
            o.Albedo = c.rgb;
            o.Alpha = c.a;
        }

        
        float4 Lighting_MyLight(SurfaceOutput s, float3 lightDir, float atten)
        {
            float ndotl = pow ( dot(s.Normal, lightDir) * 0.5 + 0.5 , 3 );
            float4 final;
            final.rgb = ndotl * s.Albedo * _LightColor0.rgb * atten;
            final.a = s.Alpha;
            return final; 
        }

        ENDCG
    }
    FallBack "Diffuse"
}</pre>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="832" style="aspect-ratio: 1480 / 832;" width="1480" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_13_56_59_799.mp4"></video></figure>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<figure class="wp-block-image size-full"><img decoding="async" width="1084" height="114" src="https://lycos7560.com/wp-content/uploads/image-431.png" alt="" class="wp-image-2895" srcset="https://lycos7560.com/wp-content/uploads/image-431.png 1084w, https://lycos7560.com/wp-content/uploads/image-431-300x32.png 300w, https://lycos7560.com/wp-content/uploads/image-431-768x81.png 768w" sizes="(max-width: 1084px) 100vw, 1084px" /></figure>



<div style="height:32px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">이렇게 적용하면 얼굴이 밝아지면서 atten으로 생기는 얼굴의 그림자가 두드러지게 보이는 단점이 생길 것 입니다.</p>



<p class="has-medium-font-size">정답은 없고 atten를 제거해도 좋고 pow 함수를 이용하여 적절하게 숨기는 것도 하나의 방법입니다.</p>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">이제 완전한 Lambert 가 완성되었습니다.</p>



<p class="has-medium-font-size">이것은 유니티4까지 사용되었던 Bump Diffuse와 완전히 같은 쉐이더이며</p>



<p class="has-medium-font-size">유니티5에서도 Legacy Shaders / Bumped Diffuse와도 완전히 같은 쉐이더입니다.</p>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
<p>The post <a href="https://lycos7560.com/unity/unity_shader/unity_shader-half-lambert/2873/">11 &#8211; 03 ~ 04 Half-Lambert(하프 램버트) 연산 및 완성 (Unity Shader)</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/unity/unity_shader/unity_shader-half-lambert/2873/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_13_40_14_926.mp4" length="1789228" type="video/mp4" />
<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_13_43_51_403.mp4" length="1396326" type="video/mp4" />
<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_13_45_59_585.mp4" length="1170911" type="video/mp4" />
<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_13_49_10_310.mp4" length="1081007" type="video/mp4" />
<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_13_54_13_816.mp4" length="527708" type="video/mp4" />
<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_13_55_17_400.mp4" length="823267" type="video/mp4" />
<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_13_56_59_799.mp4" length="1167010" type="video/mp4" />

			</item>
		<item>
		<title>11 &#8211; 01 ~ 02 커스텀 라이트 기본형 / Lambert 라이트 연산 (Unity Shader)</title>
		<link>https://lycos7560.com/unity/unity_shader/unity_shader-custom-lights-lambert-lights/2852/</link>
					<comments>https://lycos7560.com/unity/unity_shader/unity_shader-custom-lights-lambert-lights/2852/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Thu, 01 Dec 2022 02:50:54 +0000</pubDate>
				<category><![CDATA[Unity]]></category>
		<category><![CDATA[UnityShader]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[Lambert]]></category>
		<category><![CDATA[light]]></category>
		<category><![CDATA[lighting]]></category>
		<category><![CDATA[Shader]]></category>
		<category><![CDATA[Standard Surface Shader]]></category>
		<category><![CDATA[Unity Shader]]></category>
		<category><![CDATA[기본형]]></category>
		<category><![CDATA[쉐이더]]></category>
		<category><![CDATA[유니티]]></category>
		<category><![CDATA[유니티 쉐이더 스타트업]]></category>
		<category><![CDATA[커스텀라이트]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=2852</guid>

					<description><![CDATA[<p>커스텀 라이트의 기본형과 Lambert 라이트를 구현하는 방법을 예제로 간략하게 설명한 글입니다.</p>
<p>The post <a href="https://lycos7560.com/unity/unity_shader/unity_shader-custom-lights-lambert-lights/2852/">11 &#8211; 01 ~ 02 커스텀 라이트 기본형 / Lambert 라이트 연산 (Unity Shader)</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<div style="height:58px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">11 &#8211; 01 ~ 02 커스텀 라이트 기본형 / Lambert 라이트 연산 (Unity Shader)</h2>



<div style="height:25px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">텍스처 한 장만 받는 기본형 쉐이더를 만듭니다.</p>



<div style="height:46px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">직접 확인해보기 위해서 아래 에셋을 사용했습니다. (무료)</p>



<p class="has-medium-font-size"><a href="https://assetstore.unity.com/packages/3d/characters/humanoids/barbarian-warrior-75519" target="_blank" rel="noreferrer noopener">https://assetstore.unity.com/packages/3d/characters/humanoids/barbarian-warrior-75519</a>&nbsp;&lt;- TestAsset</p>



<div style="height:36px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><a href="https://assetstore.unity.com/packages/3d/characters/humanoids/barbarian-warrior-75519" target="_blank" rel="noreferrer noopener"><img decoding="async" width="1304" height="317" src="https://lycos7560.com/wp-content/uploads/image-388.png" alt="" class="wp-image-2824" srcset="https://lycos7560.com/wp-content/uploads/image-388.png 1304w, https://lycos7560.com/wp-content/uploads/image-388-300x73.png 300w, https://lycos7560.com/wp-content/uploads/image-388-768x187.png 768w" sizes="(max-width: 1304px) 100vw, 1304px" /></a></figure>



<div style="height:58px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Shader "Custom/CustomLight"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        #pragma surface surf Lambert noambient  
        // noambient - 주변광 또는 라이트 프로브를 적용하지 않습니다.
        #pragma target 3.0
        
        sampler2D _MainTex;

        struct Input
        {
            float2 uv_MainTex;
        };

        void surf (Input IN, inout SurfaceOutput o)
        {

            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            o.Albedo = c.rgb;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}</pre>



<div style="height:41px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1523" height="526" src="https://lycos7560.com/wp-content/uploads/image-404.png" alt="" class="wp-image-2853" srcset="https://lycos7560.com/wp-content/uploads/image-404.png 1523w, https://lycos7560.com/wp-content/uploads/image-404-300x104.png 300w, https://lycos7560.com/wp-content/uploads/image-404-768x265.png 768w" sizes="(max-width: 1523px) 100vw, 1523px" /></figure>



<div style="height:32px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">Lambert 라이트를 삭제하고 자신만의 라이트 이름을 지어서 커스텀 라이트를 구동시켜 보겠습니다.</p>



<div style="height:35px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="947" height="939" src="https://lycos7560.com/wp-content/uploads/image-405.png" alt="" class="wp-image-2854" srcset="https://lycos7560.com/wp-content/uploads/image-405.png 947w, https://lycos7560.com/wp-content/uploads/image-405-300x297.png 300w, https://lycos7560.com/wp-content/uploads/image-405-150x150.png 150w, https://lycos7560.com/wp-content/uploads/image-405-768x762.png 768w" sizes="(max-width: 947px) 100vw, 947px" /></figure>



<div style="height:49px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1530" height="476" src="https://lycos7560.com/wp-content/uploads/image-406.png" alt="" class="wp-image-2855" srcset="https://lycos7560.com/wp-content/uploads/image-406.png 1530w, https://lycos7560.com/wp-content/uploads/image-406-300x93.png 300w, https://lycos7560.com/wp-content/uploads/image-406-768x239.png 768w" sizes="(max-width: 1530px) 100vw, 1530px" /></figure>



<div style="height:68px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">바뀌거나 추가된 내용을 하나씩 보겠습니다.</p>



<div style="height:32px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="812" height="120" src="https://lycos7560.com/wp-content/uploads/image-407.png" alt="" class="wp-image-2856" srcset="https://lycos7560.com/wp-content/uploads/image-407.png 812w, https://lycos7560.com/wp-content/uploads/image-407-300x44.png 300w, https://lycos7560.com/wp-content/uploads/image-407-768x113.png 768w" sizes="(max-width: 812px) 100vw, 812px" /></figure>



<div style="height:26px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">Lambert 대신에 _MyLight로 바뀌었습니다.</p>



<p class="has-medium-font-size">여기는 이름을 마음대로 지어도 상관없습니다.</p>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="904" height="147" src="https://lycos7560.com/wp-content/uploads/image-408.png" alt="" class="wp-image-2857" srcset="https://lycos7560.com/wp-content/uploads/image-408.png 904w, https://lycos7560.com/wp-content/uploads/image-408-300x49.png 300w, https://lycos7560.com/wp-content/uploads/image-408-768x125.png 768w" sizes="(max-width: 904px) 100vw, 904px" /></figure>



<div style="height:23px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">우리가 만든 커스텀 함수의 모습입니다.</p>



<p class="has-medium-font-size">이전까지는 void surf 사용했습니다.</p>



<p class="has-medium-font-size">이 함수는 float4로 시작합니다. 함수가 float4 를 반환 하므로 return float4&nbsp; 출력값을 가지고 있습니다.&nbsp;</p>



<p class="has-medium-font-size">이어서 나오는 이름도 Lighting + &#8220;커스텀 라이트 이름&#8221; 을 추가해 주어야 합니다.</p>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="542" height="57" src="https://lycos7560.com/wp-content/uploads/image-409.png" alt="" class="wp-image-2858" srcset="https://lycos7560.com/wp-content/uploads/image-409.png 542w, https://lycos7560.com/wp-content/uploads/image-409-300x32.png 300w" sizes="(max-width: 542px) 100vw, 542px" /></figure>



<div style="height:21px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">SurfaceOutput 구조체를 통째로 받아옵니다.</p>



<div style="height:23px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="835" height="365" src="https://lycos7560.com/wp-content/uploads/image-410.png" alt="" class="wp-image-2859" srcset="https://lycos7560.com/wp-content/uploads/image-410.png 835w, https://lycos7560.com/wp-content/uploads/image-410-300x131.png 300w, https://lycos7560.com/wp-content/uploads/image-410-768x336.png 768w" sizes="(max-width: 835px) 100vw, 835px" /></figure>



<div style="height:26px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="693" height="400" src="https://lycos7560.com/wp-content/uploads/image-411.png" alt="" class="wp-image-2860" srcset="https://lycos7560.com/wp-content/uploads/image-411.png 693w, https://lycos7560.com/wp-content/uploads/image-411-300x173.png 300w" sizes="(max-width: 693px) 100vw, 693px" /></figure>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">float3 lightDir 은 이전 파트에서 배웠던 조명 방향의 벡터 입니다.</p>



<p class="has-medium-font-size">단, 조명 계산을 편하게 사용하기 위해서 뒤집혀지고 길이가 1인 단위 벡터의 상태입니다.</p>



<div style="height:27px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="818" height="455" src="https://lycos7560.com/wp-content/uploads/image-412.png" alt="" class="wp-image-2861" srcset="https://lycos7560.com/wp-content/uploads/image-412.png 818w, https://lycos7560.com/wp-content/uploads/image-412-300x167.png 300w, https://lycos7560.com/wp-content/uploads/image-412-768x427.png 768w" sizes="(max-width: 818px) 100vw, 818px" /></figure>



<div style="height:23px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">float atten</p>



<p class="has-medium-font-size">atten ( attenuation ) 감쇠</p>



<p class="has-medium-font-size">그림자를 받거나 거리가 멀어지면서 점점 조명이 흐려지는 라이트의 거리별 감쇠 현상을 나타냅니다.</p>



<p class="has-medium-font-size">내가 빛을 받는 것을 없앨 때 사용하는 부분입니다.</p>



<div style="height:28px" aria-hidden="true" class="wp-block-spacer"></div>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<p class="has-medium-font-size">Lambert&nbsp;라이트&nbsp;연산</p>



<p class="has-medium-font-size">우리가 만든 커스텀 라이트에서 변경합니다.</p>



<div style="height:37px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1058" height="403" src="https://lycos7560.com/wp-content/uploads/image-413.png" alt="" class="wp-image-2862" srcset="https://lycos7560.com/wp-content/uploads/image-413.png 1058w, https://lycos7560.com/wp-content/uploads/image-413-300x114.png 300w, https://lycos7560.com/wp-content/uploads/image-413-768x293.png 768w" sizes="(max-width: 1058px) 100vw, 1058px" /></figure>



<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Shader "Custom/CustomLight"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        #pragma surface surf _MyLight noambient  
        // noambient - 주변광 또는 라이트 프로브를 적용하지 않습니다.
        #pragma target 3.0

        sampler2D _MainTex;

        struct Input
        {
            float2 uv_MainTex;
        };

        void surf (Input IN, inout SurfaceOutput o)
        {

            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            o.Albedo = c.rgb;
            o.Alpha = c.a;
        }

        
        float4 Lighting_MyLight(SurfaceOutput s, float3 lightDir, float atten)
        {
            float ndotl = dot(s.Normal, lightDir);
            // dot 노멀 백터와 라이트 벡터를 내적 연산
            // surf 에서 Normal 값을 받지 않아도 버텍스에서 노말값을 평범하게 받음

            return ndotl;
        }

        ENDCG
    }
    FallBack "Diffuse"
}</pre>



<div style="height:43px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="688" style="aspect-ratio: 1464 / 688;" width="1464" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_11_38_53_802.mp4"></video></figure>



<div style="height:47px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">lightDir은 버텍스에서 바라보는 조명의 방향인 뒤집힌 방향 이기 때문에 두 벤터를 단순하게 내적해주면 cos 값이 나오게 됩니다.</p>



<div style="height:36px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1533" height="530" src="https://lycos7560.com/wp-content/uploads/image-414.png" alt="" class="wp-image-2864" srcset="https://lycos7560.com/wp-content/uploads/image-414.png 1533w, https://lycos7560.com/wp-content/uploads/image-414-300x104.png 300w, https://lycos7560.com/wp-content/uploads/image-414-768x266.png 768w" sizes="(max-width: 1533px) 100vw, 1533px" /></figure>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">위와 같은 코드는 가장 밝은 곳이 1 / 어두워 지는 경계선은 0 / 가장 어두운 곳은 -1 값으로 되어서</p>



<p class="has-medium-font-size">나중에 추가 라이트를 비추거나 할 때 문제가 됩니다.&nbsp;</p>



<p class="has-medium-font-size">이 현상을 방지하기 위해서&nbsp; saturate (값) 함수를 사용합니다.</p>



<p class="has-medium-font-size">max 함수도 사용하지만 최대 값이 없습니다.</p>



<p class="has-medium-font-size">max(0, dot(s.Normal, lightDir));</p>



<p class="has-medium-font-size">float&nbsp;ndotl&nbsp;=&nbsp;max(0,&nbsp;dot(s.Normal,&nbsp;lightDir));</p>



<div style="height:24px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="819" height="225" src="https://lycos7560.com/wp-content/uploads/image-415.png" alt="" class="wp-image-2865" srcset="https://lycos7560.com/wp-content/uploads/image-415.png 819w, https://lycos7560.com/wp-content/uploads/image-415-300x82.png 300w, https://lycos7560.com/wp-content/uploads/image-415-768x211.png 768w" sizes="(max-width: 819px) 100vw, 819px" /></figure>



<div style="height:28px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Shader "Custom/CustomLight"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        #pragma surface surf _MyLight noambient  
        // noambient - 주변광 또는 라이트 프로브를 적용하지 않습니다.
        #pragma target 3.0

        sampler2D _MainTex;

        struct Input
        {
            float2 uv_MainTex;
        };

        void surf (Input IN, inout SurfaceOutput o)
        {

            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            o.Albedo = c.rgb;
            o.Alpha = c.a;
        }

        
        float4 Lighting_MyLight(SurfaceOutput s, float3 lightDir, float atten)
        {
            float ndotl = saturate(dot(s.Normal, lightDir));

            // dot 노멀 백터와 라이트 벡터를 내적 연산
            // surf 에서 Normal 값을 받지 않아도 버텍스에서 노말값을 평범하게 받음
            // saturate 0 이하 값을 0으로 만들어줌
            
            // float ndotl = max(0, dot(s.Normal, lightDir));
            // max 함수도 있지만 최대 값이 없습니다.

            return ndotl;
        }

        ENDCG
    }
    FallBack "Diffuse"
}</pre>



<div style="height:37px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="688" style="aspect-ratio: 1464 / 688;" width="1464" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_11_41_55_314.mp4"></video></figure>



<div style="height:101px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">NormalMap 적용</p>



<div style="height:29px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Shader "Custom/CustomLight"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _BumpMap("Normal Map", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        #pragma surface surf _MyLight noambient  
        // noambient - 주변광 또는 라이트 프로브를 적용하지 않습니다.
        #pragma target 3.0

        sampler2D _MainTex;
        sampler2D _BumpMap;

        struct Input
        {
            float2 uv_MainTex;
            float2 uv_BumpMap;
        };

        void surf (Input IN, inout SurfaceOutput o)
        {

            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            float3 d = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
            o.Normal = d;
            o.Albedo = c.rgb;
            o.Alpha = c.a;
        }

        
        float4 Lighting_MyLight(SurfaceOutput s, float3 lightDir, float atten)
        {
            float ndotl = saturate(dot(s.Normal, lightDir));

            // dot 노멀 백터와 라이트 벡터를 내적 연산
            // surf 에서 Normal 값을 받지 않아도 버텍스에서 노말값을 평범하게 받음
            // saturate 0 이하 값을 0으로 만들어줌
            
            // float ndotl = max(0, dot(s.Normal, lightDir));
            // max 함수도 있지만 최대 값이 없습니다.

            return ndotl;
        }

        ENDCG
    }
    FallBack "Diffuse"
}</pre>



<div style="height:21px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="688" style="aspect-ratio: 1464 / 688;" width="1464" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_11_43_19_983.mp4"></video></figure>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">환경광 제거</p>



<div style="height:52px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="924" height="185" src="https://lycos7560.com/wp-content/uploads/image-416.png" alt="" class="wp-image-2868" srcset="https://lycos7560.com/wp-content/uploads/image-416.png 924w, https://lycos7560.com/wp-content/uploads/image-416-300x60.png 300w, https://lycos7560.com/wp-content/uploads/image-416-768x154.png 768w" sizes="(max-width: 924px) 100vw, 924px" /></figure>



<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="696" style="aspect-ratio: 1464 / 696;" width="1464" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_11_44_56_814.mp4"></video></figure>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
<p>The post <a href="https://lycos7560.com/unity/unity_shader/unity_shader-custom-lights-lambert-lights/2852/">11 &#8211; 01 ~ 02 커스텀 라이트 기본형 / Lambert 라이트 연산 (Unity Shader)</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/unity/unity_shader/unity_shader-custom-lights-lambert-lights/2852/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_11_38_53_802.mp4" length="1320242" type="video/mp4" />
<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_11_41_55_314.mp4" length="1044809" type="video/mp4" />
<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_11_43_19_983.mp4" length="2358455" type="video/mp4" />
<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_11_44_56_814.mp4" length="1993886" type="video/mp4" />

			</item>
		<item>
		<title>9 &#8211; 02 ~ 03 Lambert (램버트) / Blinn-Phong(블린-퐁) (Unity Shader)</title>
		<link>https://lycos7560.com/unity/unity_shader/unity_shader-lambert-blinn-phong/2841/</link>
					<comments>https://lycos7560.com/unity/unity_shader/unity_shader-lambert-blinn-phong/2841/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Thu, 01 Dec 2022 02:26:12 +0000</pubDate>
				<category><![CDATA[Unity]]></category>
		<category><![CDATA[UnityShader]]></category>
		<category><![CDATA[_SpecColor]]></category>
		<category><![CDATA[Blinn-Phong]]></category>
		<category><![CDATA[Lambert]]></category>
		<category><![CDATA[light]]></category>
		<category><![CDATA[lighting]]></category>
		<category><![CDATA[Shader]]></category>
		<category><![CDATA[Specular]]></category>
		<category><![CDATA[Standard Surface Shader]]></category>
		<category><![CDATA[Unity Shader]]></category>
		<category><![CDATA[라이트]]></category>
		<category><![CDATA[쉐이더]]></category>
		<category><![CDATA[유니티]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=2841</guid>

					<description><![CDATA[<p>Unity의 Lambert 라이트와 blinn-pong 라이트를 간단하게 설명하면서 구현하는 글입니다.</p>
<p>The post <a href="https://lycos7560.com/unity/unity_shader/unity_shader-lambert-blinn-phong/2841/">9 &#8211; 02 ~ 03 Lambert (램버트) / Blinn-Phong(블린-퐁) (Unity Shader)</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<div style="height:47px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">9 &#8211; 02 ~ 03 Lambert (램버트) / Blinn-Phong(블린-퐁) (Unity Shader)</h2>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">유니티4 이전 시절에 존재하던 가벼운 라이팅 방식인 Lambert 라이팅</p>



<p class="has-medium-font-size">램버트 라이팅 초기 구조</p>



<div style="height:28px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="709" height="854" src="https://lycos7560.com/wp-content/uploads/image-399.png" alt="" class="wp-image-2842" srcset="https://lycos7560.com/wp-content/uploads/image-399.png 709w, https://lycos7560.com/wp-content/uploads/image-399-249x300.png 249w" sizes="(max-width: 709px) 100vw, 709px" /></figure>



<div style="height:37px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Shader "Custom/Lambert"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        #pragma surface surf Lambert
        #pragma target 3.0

        sampler2D _MainTex;

        struct Input
        {
            float2 uv_MainTex;
        };

        void surf (Input IN, inout SurfaceOutput o)
        {
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            o.Albedo = c.rgb;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}</pre>



<div style="height:39px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">둔탁한 느낌의 이미지가 Lambert 라이트의 특징입니다.</p>



<p class="has-medium-font-size">o.Specular / o.Gloss 는 사용하지 않으므로 값을 넣어도 나타나지 않습니다.</p>



<p class="has-medium-font-size">겉으로는 크게 바뀐 것 같지 않지만 내장된 기본 라이팅 구조 중에서 가장 가벼운 라이트입니다. (저사양 기기에서도 잘 구동됩니다.)</p>



<div style="height:25px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1307" height="874" src="https://lycos7560.com/wp-content/uploads/image-400.png" alt="" class="wp-image-2843" srcset="https://lycos7560.com/wp-content/uploads/image-400.png 1307w, https://lycos7560.com/wp-content/uploads/image-400-300x201.png 300w, https://lycos7560.com/wp-content/uploads/image-400-768x514.png 768w" sizes="(max-width: 1307px) 100vw, 1307px" /></figure>



<div style="height:72px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1339" height="872" src="https://lycos7560.com/wp-content/uploads/image-401.png" alt="" class="wp-image-2844" srcset="https://lycos7560.com/wp-content/uploads/image-401.png 1339w, https://lycos7560.com/wp-content/uploads/image-401-300x195.png 300w, https://lycos7560.com/wp-content/uploads/image-401-768x500.png 768w" sizes="(max-width: 1339px) 100vw, 1339px" /></figure>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="836" style="aspect-ratio: 1440 / 836;" width="1440" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_11_15_46_258.mp4"></video></figure>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<h2 class="wp-block-heading">간단한 Blinn Phong 라이트 구현&nbsp;</h2>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="692" height="799" src="https://lycos7560.com/wp-content/uploads/image-402.png" alt="" class="wp-image-2846" srcset="https://lycos7560.com/wp-content/uploads/image-402.png 692w, https://lycos7560.com/wp-content/uploads/image-402-260x300.png 260w" sizes="(max-width: 692px) 100vw, 692px" /></figure>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Shader "Custom/BlinnPhong"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        #pragma surface surf BlinnPhong
        #pragma target 3.0

        sampler2D _MainTex;

        struct Input
        {
            float2 uv_MainTex;
        };


        void surf (Input IN, inout SurfaceOutput o)
        {
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            o.Albedo = c.rgb;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}</pre>



<div style="height:64px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">BlinnPhong 공식이 가동 되었지만 Specular는 보이지 않습니다.</p>



<p class="has-medium-font-size">Specular를 보기위해 추가로 데이터를 입력합니다.</p>



<div style="height:66px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="689" height="939" src="https://lycos7560.com/wp-content/uploads/image-403.png" alt="" class="wp-image-2847" srcset="https://lycos7560.com/wp-content/uploads/image-403.png 689w, https://lycos7560.com/wp-content/uploads/image-403-220x300.png 220w" sizes="(max-width: 689px) 100vw, 689px" /></figure>



<div style="height:49px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Shader "Custom/BlinnPhong"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _SpecColor("SpecColor", color) = (1,1,1,1)
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        #pragma surface surf BlinnPhong
        #pragma target 3.0

        sampler2D _MainTex;

        struct Input
        {
            float2 uv_MainTex;
        };


        void surf (Input IN, inout SurfaceOutput o)
        {
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            o.Albedo = c.rgb;
            o.Specular = 0.5;
            o.Gloss = 1;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}</pre>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="828" style="aspect-ratio: 1488 / 828;" width="1488" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_11_18_55_461.mp4"></video></figure>



<div style="height:51px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">위의 코드에서 어디에서도 _SpecColor 를 받는 부분이 없습니다.</p>



<p class="has-medium-font-size">_SpecColor 는 절대로 코드에서 받으면 안 되고, 단지&nbsp; Properties 에서만 만들어야 한다는 것 입니다.</p>



<p class="has-medium-font-size">그리고 _SpecColor 라는 이름 외에 다른 이름을 써서도 안됩니다.</p>



<p class="has-medium-font-size"><strong>BlinnPong 내부의 코드를 열어보면 _SpecColor 이름이 예약어이며 절대로 코드 내부에서 받으면 안된다는 특이한 예외 사항이 존재합니다.</strong></p>



<p class="has-medium-font-size">o.Gloss 는 0~ 1 사이의 값을 넣어야 하며 Specular 의 강도를 의미합니다.</p>



<p class="has-medium-font-size">0이면 둔탁한 재질 / 1이면 매끄러운 재질을 의미합니다.</p>



<p class="has-medium-font-size">o.Specular는 0~ 1 사이의 값을 넣어야 하며 Specular 의 크기를 의미합니다.</p>



<p class="has-medium-font-size">0이면 크기가 커지고&nbsp; / 1이면 크기가 작아집니다.</p>



<div style="height:70px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">확인용 코드</p>



<div style="height:25px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Shader "Custom/BlinnPhong"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _SpecColor("SpecColor", color) = (1,1,1,1)
        _SpecAmount("SpecAmount",Range(0,1)) = 0.5
        _GlossAmount("_GlossAmount",Range(0,1)) = 1
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        #pragma surface surf BlinnPhong
        #pragma target 3.0

        sampler2D _MainTex;
        float _SpecAmount;
        float _GlossAmount;

        struct Input
        {
            float2 uv_MainTex;
        };


        void surf (Input IN, inout SurfaceOutput o)
        {
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            o.Albedo = c.rgb;
            o.Specular = _SpecAmount;
            o.Gloss = _GlossAmount;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}</pre>



<div style="height:72px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="688" style="aspect-ratio: 1464 / 688;" width="1464" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_11_21_22_869.mp4"></video></figure>



<div style="height:133px" aria-hidden="true" class="wp-block-spacer"></div>
<p>The post <a href="https://lycos7560.com/unity/unity_shader/unity_shader-lambert-blinn-phong/2841/">9 &#8211; 02 ~ 03 Lambert (램버트) / Blinn-Phong(블린-퐁) (Unity Shader)</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/unity/unity_shader/unity_shader-lambert-blinn-phong/2841/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_11_15_46_258.mp4" length="1365005" type="video/mp4" />
<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_11_18_55_461.mp4" length="2616931" type="video/mp4" />
<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_11_21_22_869.mp4" length="900683" type="video/mp4" />

			</item>
		<item>
		<title>9 &#8211; 01 유니티에 내장된 라이팅 구조 (Unity Shader)</title>
		<link>https://lycos7560.com/unity/unity_shader-lighting-structure/2835/</link>
					<comments>https://lycos7560.com/unity/unity_shader-lighting-structure/2835/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Thu, 01 Dec 2022 02:08:42 +0000</pubDate>
				<category><![CDATA[Unity]]></category>
		<category><![CDATA[UnityShader]]></category>
		<category><![CDATA[Blinn Phong]]></category>
		<category><![CDATA[Lambert]]></category>
		<category><![CDATA[lighting]]></category>
		<category><![CDATA[Shader]]></category>
		<category><![CDATA[Standard Surface Shader]]></category>
		<category><![CDATA[Unity Shader]]></category>
		<category><![CDATA[구조체]]></category>
		<category><![CDATA[라이팅]]></category>
		<category><![CDATA[램버트]]></category>
		<category><![CDATA[블린퐁]]></category>
		<category><![CDATA[쉐이더]]></category>
		<category><![CDATA[스탠다드]]></category>
		<category><![CDATA[유니티]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=2835</guid>

					<description><![CDATA[<p>유니티에 내장된 라이팅 구조를 간략하게 설명하는 글입니다.</p>
<p>The post <a href="https://lycos7560.com/unity/unity_shader-lighting-structure/2835/">9 &#8211; 01 유니티에 내장된 라이팅 구조 (Unity Shader)</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<div style="height:57px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">9 &#8211; 01 유니티에 내장된 라이팅 구조 (Unity Shader)</h2>



<div style="height:24px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1019" height="303" src="https://lycos7560.com/wp-content/uploads/image-395.png" alt="" class="wp-image-2836" srcset="https://lycos7560.com/wp-content/uploads/image-395.png 1019w, https://lycos7560.com/wp-content/uploads/image-395-300x89.png 300w, https://lycos7560.com/wp-content/uploads/image-395-768x228.png 768w" sizes="(max-width: 1019px) 100vw, 1019px" /></figure>



<div style="height:47px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">쉐이더를 처음 만들면 자동으로 생성되는 Standard Shader 는 유니티 5부터 기본적으로 적용된 쉐이더 형태입니다.</p>



<p class="has-medium-font-size">Standard Shader의 라이팅은 좋은 라이팅이지만 물리기반의 쉐이더 라이트이기 때문에</p>



<p class="has-medium-font-size">모바일과 같은 저 사양 기기에서 구동하기에는 다소 무겁습니다.</p>



<p class="has-medium-font-size">그래서 유니티 내부적으로는 유니티4버전 이전부터 사용하던 라이트 구조도 그대로 구현되어 있습니다.</p>



<p class="has-medium-font-size">이 라이팅은 물리 기반의 쉐이더보다 품질을 떨어질 수 있지만 상대적으로 가볍기 때문에 물리 기반의 쉐이더를 사용할 필요 없이</p>



<p class="has-medium-font-size">가볍게 처리해야 하는 모바일 프로젝트에 적합한 쉐이더 구조라고 할 수 있습니다.</p>



<div style="height:78px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">우리가 지금까지 사용한 물리기반 쉐이더의 구조체</p>



<div style="height:25px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1206" height="402" src="https://lycos7560.com/wp-content/uploads/image-396.png" alt="" class="wp-image-2837" srcset="https://lycos7560.com/wp-content/uploads/image-396.png 1206w, https://lycos7560.com/wp-content/uploads/image-396-300x100.png 300w, https://lycos7560.com/wp-content/uploads/image-396-768x256.png 768w" sizes="(max-width: 1206px) 100vw, 1206px" /></figure>



<div style="height:32px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">또는</p>



<div style="height:44px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1162" height="408" src="https://lycos7560.com/wp-content/uploads/image-397.png" alt="" class="wp-image-2838" srcset="https://lycos7560.com/wp-content/uploads/image-397.png 1162w, https://lycos7560.com/wp-content/uploads/image-397-300x105.png 300w, https://lycos7560.com/wp-content/uploads/image-397-768x270.png 768w" sizes="(max-width: 1162px) 100vw, 1162px" /></figure>



<div style="height:63px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">물리 기반 쉐이더 이전의 쉐이더 구조인 램버트 / 블린퐁 라이트에서 사용하는 구조체 </p>



<div style="height:29px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1520" height="398" src="https://lycos7560.com/wp-content/uploads/image-398.png" alt="" class="wp-image-2839" srcset="https://lycos7560.com/wp-content/uploads/image-398.png 1520w, https://lycos7560.com/wp-content/uploads/image-398-300x79.png 300w, https://lycos7560.com/wp-content/uploads/image-398-768x201.png 768w" sizes="(max-width: 1520px) 100vw, 1520px" /></figure>



<div style="height:69px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="has-medium-font-size wp-block-heading"><strong>즉 유니티에 내장되어 있는 라이팅은 총 3가지라고 할 수 있습니다. </strong></h2>



<div style="height:53px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="has-medium-font-size wp-block-heading">1. Lambert 램버트</h2>



<p class="has-medium-font-size">Specular 의 공식이 없고 단지 빛에 의한 밝고 어두움이 구현된 가벼운 라이트 구조  / SurfaceOutput 구조체 사용</p>



<div style="height:52px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="has-medium-font-size wp-block-heading">2. Blinn Phong 블린퐁</h2>



<p class="has-medium-font-size">램버트 공식에 가벼운 Specular 공식인 블린퐁 공식이 더해진 라이트 구조,</p>



<p class="has-medium-font-size">Specular 공식은 보는 각도와 조명 각도에 따라 계산된 특정 색의 하이라이트 동그라미로 표현된다. / SurfaceOutput 구조체 사용</p>



<div style="height:47px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="has-medium-font-size wp-block-heading">3.&nbsp;&nbsp;Standard 스탠다드</h2>



<p class="has-medium-font-size">일명 PBS ( 물리 기반 쉐이더 : Physically Based Shader)</p>



<p class="has-medium-font-size">주변 환경을 반사하서 Specular 를 구현하며, Diffuse 와 Specular 가 에너지 보존 법칙에 의해 서로 보완관계를 자동적으로 가지며</p>



<p class="has-medium-font-size">Specular dml 칼라가 메탈릭 속성에 따라 자동적으로 결정되는 라이트 구조</p>



<p class="has-medium-font-size">SurfaceOutputStandard 또는 SurfaceOutputStandardSpecular 구조체 사용</p>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
<p>The post <a href="https://lycos7560.com/unity/unity_shader-lighting-structure/2835/">9 &#8211; 01 유니티에 내장된 라이팅 구조 (Unity Shader)</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/unity/unity_shader-lighting-structure/2835/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>8 &#8211; 04 Occlusion (오클루젼) (Unity Shader)</title>
		<link>https://lycos7560.com/unity/unity_shader/unity_shader-ambient-occlusion/2820/</link>
					<comments>https://lycos7560.com/unity/unity_shader/unity_shader-ambient-occlusion/2820/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Thu, 01 Dec 2022 01:54:04 +0000</pubDate>
				<category><![CDATA[Unity]]></category>
		<category><![CDATA[UnityShader]]></category>
		<category><![CDATA[Ambient]]></category>
		<category><![CDATA[Ambient Occlusion]]></category>
		<category><![CDATA[Occlusion]]></category>
		<category><![CDATA[Shader]]></category>
		<category><![CDATA[Standard Surface Shader]]></category>
		<category><![CDATA[struct]]></category>
		<category><![CDATA[Unity Shader]]></category>
		<category><![CDATA[쉐이더]]></category>
		<category><![CDATA[엠비언트 오클루젼]]></category>
		<category><![CDATA[오클루젼]]></category>
		<category><![CDATA[유니티]]></category>
		<category><![CDATA[환경광]]></category>
		<category><![CDATA[환경차폐]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=2820</guid>

					<description><![CDATA[<p>UnityShader에서 Ambient Occlusion을 사용하는 방법을 간략하게 예제로 설명한 글입니다.</p>
<p>The post <a href="https://lycos7560.com/unity/unity_shader/unity_shader-ambient-occlusion/2820/">8 &#8211; 04 Occlusion (오클루젼) (Unity Shader)</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<div style="height:55px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading"><strong>8 &#8211; 04 Occlusion (오클루젼) (Unity Shader)</strong></h2>



<div style="height:22px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">Occlusion (오클루젼)은 Ambient Occlusion (엠비언트 오클루젼) 이라고 부르며, 구석진 부분의 추가적인 음영을 표현하는 기능입니다.</p>



<p class="has-medium-font-size">일반적으로 세상에서 그림자가 드리워진 부분도 사방에서 오는 환경광 정도를 받고 있는 것이 일반적입니다.</p>



<p class="has-medium-font-size">하지만, 매우 구석져 있거나 복잡한 물체들로 가려져서 환경광도 닫지 못하는 부분은 더욱 더 어두워지는 데&nbsp;&nbsp;</p>



<p class="has-medium-font-size">이 부분은&nbsp;Ambient&nbsp;Occlusion (엠비언트 오클루젼) 환경차폐라고 부릅니다.</p>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1045" height="597" src="https://lycos7560.com/wp-content/uploads/image-385.png" alt="" class="wp-image-2821" srcset="https://lycos7560.com/wp-content/uploads/image-385.png 1045w, https://lycos7560.com/wp-content/uploads/image-385-300x171.png 300w, https://lycos7560.com/wp-content/uploads/image-385-768x439.png 768w" sizes="(max-width: 1045px) 100vw, 1045px" /></figure>



<div style="height:56px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size"><a href="https://docs.unity3d.com/Manual/SL-SurfaceShaders.html" target="_blank" rel="noreferrer noopener">https://docs.unity3d.com/Manual/SL-SurfaceShaders.html</a></p>



<div style="height:21px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><a href="https://docs.unity3d.com/Manual/SL-SurfaceShaders.html" target="_blank" rel="noreferrer noopener"><img decoding="async" width="1312" height="317" src="https://lycos7560.com/wp-content/uploads/image-386.png" alt="" class="wp-image-2822" srcset="https://lycos7560.com/wp-content/uploads/image-386.png 1312w, https://lycos7560.com/wp-content/uploads/image-386-300x72.png 300w, https://lycos7560.com/wp-content/uploads/image-386-768x186.png 768w" sizes="(max-width: 1312px) 100vw, 1312px" /></a></figure>



<div style="height:47px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="840" height="365" src="https://lycos7560.com/wp-content/uploads/image-387.png" alt="" class="wp-image-2823" srcset="https://lycos7560.com/wp-content/uploads/image-387.png 840w, https://lycos7560.com/wp-content/uploads/image-387-300x130.png 300w, https://lycos7560.com/wp-content/uploads/image-387-768x334.png 768w" sizes="(max-width: 840px) 100vw, 840px" /></figure>



<div style="height:72px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">직접 확인해보기 위해서 아래 에셋을 사용했습니다. (무료)</p>



<p class="has-medium-font-size"><a href="https://assetstore.unity.com/packages/3d/characters/humanoids/barbarian-warrior-75519" target="_blank" rel="noreferrer noopener">https://assetstore.unity.com/packages/3d/characters/humanoids/barbarian-warrior-75519</a>&nbsp;&lt;- TestAsset</p>



<div style="height:36px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1304" height="317" src="https://lycos7560.com/wp-content/uploads/image-388.png" alt="" class="wp-image-2824" srcset="https://lycos7560.com/wp-content/uploads/image-388.png 1304w, https://lycos7560.com/wp-content/uploads/image-388-300x73.png 300w, https://lycos7560.com/wp-content/uploads/image-388-768x187.png 768w" sizes="(max-width: 1304px) 100vw, 1304px" /></figure>



<div style="height:51px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">사용했던 바바리안 몸체는 잠시 비활성화 하고 도끼를 활성화 했습니다.</p>



<p class="has-medium-font-size">쉐이더 코드는 바바리안 바디에 적용했던 코드를 사용했습니다.</p>



<div style="height:45px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1298" height="900" src="https://lycos7560.com/wp-content/uploads/image-389.png" alt="" class="wp-image-2825" srcset="https://lycos7560.com/wp-content/uploads/image-389.png 1298w, https://lycos7560.com/wp-content/uploads/image-389-300x208.png 300w, https://lycos7560.com/wp-content/uploads/image-389-768x533.png 768w" sizes="(max-width: 1298px) 100vw, 1298px" /></figure>



<div style="height:64px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Shader "Custom/AxeOC"
{
    Properties
    {
        _MainTex("Albedo (RGB)", 2D) = "white" {}
        _BumpMap("Normal Map", 2D) = "white" {} // NormalMap
        _Test("TestFloat",Range(0.5, 3)) = 1
    }
        SubShader
        {
            Tags { "RenderType" = "Opaque" }
            LOD 200

            CGPROGRAM
            #pragma surface surf Standard
            #pragma target 3.0

            sampler2D _MainTex;
            sampler2D _BumpMap; // NormalMap
            float _Test;

            struct Input
            {
                float2 uv_MainTex;
                float2 uv_BumpMap; // NormalMap
            };

            void surf(Input IN, inout SurfaceOutputStandard o)
            {
                float4 c = tex2D(_MainTex, IN.uv_MainTex);

                float3 d = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
                o.Normal = float3(d.x * _Test, d.y * _Test, d.z);
                // _Test에 따라서 수치 변화  2  2배  0.5  0.5배 
                o.Albedo = c.rgb;
                o.Alpha = c.a;
            }
            ENDCG
        }
            FallBack "Diffuse"
}</pre>



<div style="height:81px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">Occlusion 추가</p>



<div style="height:37px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="761" height="999" src="https://lycos7560.com/wp-content/uploads/image-390.png" alt="" class="wp-image-2826" srcset="https://lycos7560.com/wp-content/uploads/image-390.png 761w, https://lycos7560.com/wp-content/uploads/image-390-229x300.png 229w" sizes="(max-width: 761px) 100vw, 761px" /></figure>



<div style="height:55px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Shader "Custom/AxeOC"
{
    Properties
    {
        _MainTex("Albedo (RGB)", 2D) = "white" {}
        _BumpMap("Normal Map", 2D) = "white" {}
        _Test("TestFloat",Range(0.5, 3)) = 1
        _Occlusion("Occlusion", 2D) = "white" {} // Occlusion
    }
        SubShader
    {
        Tags { "RenderType" = "Opaque" }
        LOD 200

        CGPROGRAM
        #pragma surface surf Standard
        #pragma target 3.0

        sampler2D _MainTex;
        sampler2D _BumpMap;
        sampler2D _Occlusion;

        float _Test;

        struct Input
        {
            float2 uv_MainTex;
            float2 uv_BumpMap;
            // 주의 uv_Occlusion 포함 X

        };

        void surf(Input IN, inout SurfaceOutputStandard o)
        {
            float4 c = tex2D(_MainTex, IN.uv_MainTex);
            o.Occlusion = tex2D(_Occlusion, IN.uv_MainTex); // Occlusion
            // _MainTex와 동일한 UV 값을 받습니다.

            float3 d = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
            o.Normal = float3(d.x * _Test, d.y * _Test, d.z);
            o.Albedo = c.rgb;
            o.Alpha = c.a;
        }
        ENDCG
    }
        FallBack "Diffuse"
}</pre>



<div style="height:58px" aria-hidden="true" class="wp-block-spacer"></div>



<div style="height:86px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">Occlusion 적용 전</p>



<div style="height:21px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="440" height="430" src="https://lycos7560.com/wp-content/uploads/image-391.png" alt="" class="wp-image-2827" srcset="https://lycos7560.com/wp-content/uploads/image-391.png 440w, https://lycos7560.com/wp-content/uploads/image-391-300x293.png 300w" sizes="(max-width: 440px) 100vw, 440px" /></figure>



<div style="height:52px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="688" style="aspect-ratio: 1232 / 688;" width="1232" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_10_43_19_134.mp4"></video></figure>



<div style="height:93px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">Occlusion 적용 후</p>



<div style="height:24px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="478" height="388" src="https://lycos7560.com/wp-content/uploads/image-392.png" alt="" class="wp-image-2829" srcset="https://lycos7560.com/wp-content/uploads/image-392.png 478w, https://lycos7560.com/wp-content/uploads/image-392-300x244.png 300w" sizes="(max-width: 478px) 100vw, 478px" /></figure>



<div style="height:32px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="688" style="aspect-ratio: 1232 / 688;" width="1232" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_10_45_53_811.mp4"></video></figure>



<div style="height:67px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1305" height="736" src="https://lycos7560.com/wp-content/uploads/image-393.png" alt="" class="wp-image-2831" srcset="https://lycos7560.com/wp-content/uploads/image-393.png 1305w, https://lycos7560.com/wp-content/uploads/image-393-300x169.png 300w, https://lycos7560.com/wp-content/uploads/image-393-768x433.png 768w" sizes="(max-width: 1305px) 100vw, 1305px" /></figure>



<div style="height:82px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">Normal Map 의 강도를 조절하면 더 확실하게 알 수 있습니다.</p>



<div style="height:43px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="612" style="aspect-ratio: 1480 / 612;" width="1480" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_10_48_01_712.mp4"></video></figure>



<div style="height:81px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="921" height="114" src="https://lycos7560.com/wp-content/uploads/image-394.png" alt="" class="wp-image-2833" srcset="https://lycos7560.com/wp-content/uploads/image-394.png 921w, https://lycos7560.com/wp-content/uploads/image-394-300x37.png 300w, https://lycos7560.com/wp-content/uploads/image-394-768x95.png 768w" sizes="(max-width: 921px) 100vw, 921px" /></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">지금 사용한 코드에서는 Occlusion은 half (SurfaceOutput -float4)를 받습니다. (r 채널만 사용합니다.)</p>



<p class="has-medium-font-size">Occlusion 기능을 위해서 rgb 채널을 사용하는 텍스쳐를 사용하는 것은 낭비입니다.</p>



<p class="has-medium-font-size">_MainTex의 a 채널에 Occlusion 맵을 넣고 사용한다면 텍스쳐를 절약 할 수 있습니다.</p>



<div style="height:105px" aria-hidden="true" class="wp-block-spacer"></div>



<p></p>



<p></p>



<p></p>



<p></p>
<p>The post <a href="https://lycos7560.com/unity/unity_shader/unity_shader-ambient-occlusion/2820/">8 &#8211; 04 Occlusion (오클루젼) (Unity Shader)</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/unity/unity_shader/unity_shader-ambient-occlusion/2820/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_10_43_19_134.mp4" length="700005" type="video/mp4" />
<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_10_45_53_811.mp4" length="1113394" type="video/mp4" />
<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_10_48_01_712.mp4" length="444913" type="video/mp4" />

			</item>
		<item>
		<title>8 &#8211; 03 Normal Map (노멀맵) (Unity Shader)</title>
		<link>https://lycos7560.com/unity/unity_shader/unity_shader-normal-map/2804/</link>
					<comments>https://lycos7560.com/unity/unity_shader/unity_shader-normal-map/2804/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Thu, 01 Dec 2022 01:20:15 +0000</pubDate>
				<category><![CDATA[Unity]]></category>
		<category><![CDATA[UnityShader]]></category>
		<category><![CDATA[normal]]></category>
		<category><![CDATA[normalmap]]></category>
		<category><![CDATA[Shader]]></category>
		<category><![CDATA[Standard Surface Shader]]></category>
		<category><![CDATA[struct]]></category>
		<category><![CDATA[SurfaceOutputStandard]]></category>
		<category><![CDATA[Unity Shader]]></category>
		<category><![CDATA[노멀맵]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=2804</guid>

					<description><![CDATA[<p>Unity Shader의 NormalMap과 struct SurfaceOutputStandard 구조체에 대한 간단한 설명 글입니다.</p>
<p>The post <a href="https://lycos7560.com/unity/unity_shader/unity_shader-normal-map/2804/">8 &#8211; 03 Normal Map (노멀맵) (Unity Shader)</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">8 &#8211; 03 Normal Map (노멀맵) (Unity Shader)</h2>



<div style="height:23px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">NormalMap이란, 실제 디테일이 없는 부분을 디테일이 있는 것처럼 보이게 만들기 위한 눈속임 맵입니다.</p>



<p class="has-medium-font-size">일반적으로 푸른색을 띄고 있으며, 빛을 속이기 위한 백터 데이터들로 이루어진 텍스쳐 파일입니다.</p>



<p class="has-medium-font-size">NormalMap을 이용해서 빛을 속이게 되면 마치 매우 많은 폴리곤으로 이루어진 오브젝트처럼 디테일이 표현되지만 실제로 폴리곤이 늘어나는 것은 아닙니다.</p>



<div style="height:70px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-x-large-font-size">struct SurfaceOutputStandard 구조체 확인</p>



<p class="has-medium-font-size"><a href="https://docs.unity3d.com/Manual/SL-SurfaceShaders.html" target="_blank" rel="noreferrer noopener">https://docs.unity3d.com/Manual/SL-SurfaceShaders.html</a></p>



<div style="height:26px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><a href="https://docs.unity3d.com/Manual/SL-SurfaceShaders.html" target="_blank" rel="noreferrer noopener"><img decoding="async" width="1095" height="268" src="https://lycos7560.com/wp-content/uploads/image-377.png" alt="" class="wp-image-2805" srcset="https://lycos7560.com/wp-content/uploads/image-377.png 1095w, https://lycos7560.com/wp-content/uploads/image-377-300x73.png 300w, https://lycos7560.com/wp-content/uploads/image-377-768x188.png 768w" sizes="(max-width: 1095px) 100vw, 1095px" /></a></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1071" height="428" src="https://lycos7560.com/wp-content/uploads/image-378.png" alt="" class="wp-image-2806" srcset="https://lycos7560.com/wp-content/uploads/image-378.png 1071w, https://lycos7560.com/wp-content/uploads/image-378-300x120.png 300w, https://lycos7560.com/wp-content/uploads/image-378-768x307.png 768w" sizes="(max-width: 1071px) 100vw, 1071px" /></figure>



<div style="height:74px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">normalmap을 직접 확인해보기 위해서 아래 에셋을 사용했습니다. (무료)</p>



<p class="has-medium-font-size"><a href="https://assetstore.unity.com/packages/3d/characters/humanoids/barbarian-warrior-75519" target="_blank" rel="noreferrer noopener">https://assetstore.unity.com/packages/3d/characters/humanoids/barbarian-warrior-75519</a>  &lt;- TestAsset</p>



<figure class="wp-block-image size-full"><a href="https://assetstore.unity.com/packages/3d/characters/humanoids/barbarian-warrior-75519" target="_blank" rel="noreferrer noopener"><img decoding="async" width="1519" height="367" src="https://lycos7560.com/wp-content/uploads/image-379.png" alt="" class="wp-image-2807" srcset="https://lycos7560.com/wp-content/uploads/image-379.png 1519w, https://lycos7560.com/wp-content/uploads/image-379-300x72.png 300w, https://lycos7560.com/wp-content/uploads/image-379-768x186.png 768w" sizes="(max-width: 1519px) 100vw, 1519px" /></a></figure>



<div style="height:35px" aria-hidden="true" class="wp-block-spacer"></div>



<div style="height:28px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Shader "Custom/TestShader"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _BumpMap("Normal Map", 2D) = "white" {} // NormalMap
        // NormalMap과 _BumpMap의 관계성이 없지만
        // 유니티의 다른 내장 쉐이더들이 저 명칭을 사용하고 있기 때문에 
        // 다른 쉐이더와의 호환성을 위해서 사용합니다.
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        #pragma surface surf Standard
        #pragma target 3.0

        sampler2D _MainTex;
        sampler2D _BumpMap; // NormalMap

        struct Input
        {
            float2 uv_MainTex;
            float2 uv_BumpMap; // NormalMap
        };

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            float4 c = tex2D (_MainTex, IN.uv_MainTex);
            o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));  // NormalMap
            o.Albedo = c.rgb;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}</pre>



<div style="height:53px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1415" height="644" src="https://lycos7560.com/wp-content/uploads/image-380.png" alt="" class="wp-image-2808" srcset="https://lycos7560.com/wp-content/uploads/image-380.png 1415w, https://lycos7560.com/wp-content/uploads/image-380-300x137.png 300w, https://lycos7560.com/wp-content/uploads/image-380-768x350.png 768w" sizes="(max-width: 1415px) 100vw, 1415px" /></figure>



<div style="height:48px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">위의 노말맵 텍스쳐를 데이터로 사용</p>



<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">확인을 위해 바디와 눈만 활성화</p>



<div style="height:32px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1502" height="863" src="https://lycos7560.com/wp-content/uploads/image-381.png" alt="" class="wp-image-2809" srcset="https://lycos7560.com/wp-content/uploads/image-381.png 1502w, https://lycos7560.com/wp-content/uploads/image-381-300x172.png 300w, https://lycos7560.com/wp-content/uploads/image-381-768x441.png 768w" sizes="(max-width: 1502px) 100vw, 1502px" /></figure>



<div style="height:67px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">위의 빨간 박스는 노말맵이 없을 경우 노말맵이 없는 쉐이더를 쓰는 것을 추천하는 문구입니다.&nbsp;</p>



<div style="height:83px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">노말맵 적용 전(좌) / 노말맵 적용 후(우)&nbsp;</p>



<div style="height:21px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1522" height="611" src="https://lycos7560.com/wp-content/uploads/image-382.png" alt="" class="wp-image-2810" srcset="https://lycos7560.com/wp-content/uploads/image-382.png 1522w, https://lycos7560.com/wp-content/uploads/image-382-300x120.png 300w, https://lycos7560.com/wp-content/uploads/image-382-768x308.png 768w" sizes="(max-width: 1522px) 100vw, 1522px" /></figure>



<div style="height:78px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">위와 같이 빛의 음영을 속여서 디테일이 늘어난 것처럼 만드는 속임수 입니다.</p>



<div style="height:37px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1474" height="303" src="https://lycos7560.com/wp-content/uploads/image-383.png" alt="" class="wp-image-2811" srcset="https://lycos7560.com/wp-content/uploads/image-383.png 1474w, https://lycos7560.com/wp-content/uploads/image-383-300x62.png 300w, https://lycos7560.com/wp-content/uploads/image-383-768x158.png 768w" sizes="(max-width: 1474px) 100vw, 1474px" /></figure>



<div style="height:81px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">NormalMap은 일반적인 텍스쳐가 아닙니다.</p>



<p class="has-medium-font-size">일반적인 게임용 포맷인 DXT1 혹은 DXT5가 아니라 DXTnm이라는 파일 포맷입니다.</p>



<p class="has-medium-font-size">이 파일 포맷은 일반적인 텍스쳐의 압축에 의한 NormalMap의 품질 저하를 막기 위하여 만든 AG파일 포맷입니다.</p>



<p class="has-medium-font-size">이 포맷은 NormalMap의 R과 G의 퀄리티를 최대한 보전하여 A와 G에 넣어 저장합니다.</p>



<p class="has-medium-font-size">이렇게 보전된 R과 G는 NormalMap의 X와 Y로 계산되며 Z는 삼각함수를 이용하여 수학적으로 추출됩니다.</p>



<p class="has-medium-font-size">그러므로 이 텍스쳐를 이용하여 NormalMap으로 온전하게 생성해내려면 앞에 설명한 공식이 적용되어 있는 함수를 이용합니다.</p>



<div style="height:56px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1086" height="225" src="https://lycos7560.com/wp-content/uploads/image-384.png" alt="" class="wp-image-2812" srcset="https://lycos7560.com/wp-content/uploads/image-384.png 1086w, https://lycos7560.com/wp-content/uploads/image-384-300x62.png 300w, https://lycos7560.com/wp-content/uploads/image-384-768x159.png 768w" sizes="(max-width: 1086px) 100vw, 1086px" /></figure>



<div style="height:67px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">아래와 같이 해주면 NormalMap의 강도를 조절할 수 있습니다.</p>



<div style="height:26px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Shader "Custom/TestShader"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _BumpMap("Normal Map", 2D) = "white" {} // NormalMap
        _Test("TestFloat",Range(0.5, 3)) = 1
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        #pragma surface surf Standard
        #pragma target 3.0

        sampler2D _MainTex;
        sampler2D _BumpMap; // NormalMap
        float _Test;

        struct Input
        {
            float2 uv_MainTex;
            float2 uv_BumpMap; // NormalMap
        };

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            float4 c = tex2D(_MainTex, IN.uv_MainTex);

            float3 d = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
            o.Normal = float3(d.x * _Test, d.y * _Test, d.z);
            // _Test에 따라서 수치 변화  2  2배  0.5  0.5배 

            o.Albedo = c.rgb;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}</pre>



<div style="height:81px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="808" style="aspect-ratio: 1080 / 808;" width="1080" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_10_12_46_526.mp4"></video></figure>



<div style="margin-top:var(--wp--preset--spacing--30);margin-bottom:var(--wp--preset--spacing--30);height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size"><a href="https://darkcatgame.tistory.com/84">https://darkcatgame.tistory.com/84</a>  &lt;- 추가적인 내용</p>



<div style="height:67px" aria-hidden="true" class="wp-block-spacer"></div>
<p>The post <a href="https://lycos7560.com/unity/unity_shader/unity_shader-normal-map/2804/">8 &#8211; 03 Normal Map (노멀맵) (Unity Shader)</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/unity/unity_shader/unity_shader-normal-map/2804/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_10_12_46_526.mp4" length="301248" type="video/mp4" />

			</item>
		<item>
		<title>8 &#8211; 01 ~ 02 Standard Shader / Metallic, Smoothness (Unity Shader)</title>
		<link>https://lycos7560.com/unity/unity_shader_standard-shader-metallic-smoothness-unity-shader/2791/</link>
					<comments>https://lycos7560.com/unity/unity_shader_standard-shader-metallic-smoothness-unity-shader/2791/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Wed, 30 Nov 2022 23:50:30 +0000</pubDate>
				<category><![CDATA[Unity]]></category>
		<category><![CDATA[UnityShader]]></category>
		<category><![CDATA[Albedo]]></category>
		<category><![CDATA[Emission]]></category>
		<category><![CDATA[Metallic]]></category>
		<category><![CDATA[Shader]]></category>
		<category><![CDATA[Smoothness]]></category>
		<category><![CDATA[Standard Shader / Metallic]]></category>
		<category><![CDATA[Standard Surface Shader]]></category>
		<category><![CDATA[Unity Shader]]></category>
		<category><![CDATA[쉐이더]]></category>
		<category><![CDATA[유니티]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=2791</guid>

					<description><![CDATA[<p>08 &#8211; 01 Standard Shader https://docs.unity3d.com/kr/2020.3/Manual/UpgradeGuide5.html 유니티 5.0이 되면서 다른 많은 그래픽 툴이나 엔진처럼 최신의 쉐이더 시스템인 &#8216;물리 기반 쉐이더&#8217; 시스템을 도입하게 되었습니다. 기존의 쉐이더 시스템과는 다르게, 주변 환경에 따른 재질 변화를 물리 법칙에 기반하여 실시간으로 재질을 구현해주는 사실적인 쉐이더 표현 기법입니다. 유니티에 있는 기본 Standard Shader 가 대표적인 물리 기반 쉐이더입니다. https://docs.unity3d.com/kr/2021.3/Manual/SL-SurfaceShaders.html 우리가 사용한&#160; [&#8230;]</p>
<p>The post <a href="https://lycos7560.com/unity/unity_shader_standard-shader-metallic-smoothness-unity-shader/2791/">8 &#8211; 01 ~ 02 Standard Shader / Metallic, Smoothness (Unity Shader)</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">08 &#8211; 01 Standard Shader</h2>



<div style="height:26px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size"><a href="https://docs.unity3d.com/kr/2020.3/Manual/UpgradeGuide5.html" target="_blank" rel="noreferrer noopener">https://docs.unity3d.com/kr/2020.3/Manual/UpgradeGuide5.html</a></p>



<div style="height:22px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><a href="https://docs.unity3d.com/kr/2020.3/Manual/UpgradeGuide5.html" target="_blank" rel="noreferrer noopener"><img decoding="async" width="1085" height="264" src="https://lycos7560.com/wp-content/uploads/image-370.png" alt="" class="wp-image-2792" srcset="https://lycos7560.com/wp-content/uploads/image-370.png 1085w, https://lycos7560.com/wp-content/uploads/image-370-300x73.png 300w, https://lycos7560.com/wp-content/uploads/image-370-768x187.png 768w" sizes="(max-width: 1085px) 100vw, 1085px" /></a></figure>



<div style="height:46px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">유니티 5.0이 되면서 다른 많은 그래픽 툴이나 엔진처럼 최신의 쉐이더 시스템인</p>



<p class="has-medium-font-size">&#8216;물리 기반 쉐이더&#8217; 시스템을 도입하게 되었습니다.</p>



<p class="has-medium-font-size">기존의 쉐이더 시스템과는 다르게, 주변 환경에 따른 재질 변화를 물리 법칙에 기반하여</p>



<p class="has-medium-font-size">실시간으로 재질을 구현해주는 사실적인 쉐이더 표현 기법입니다.</p>



<p class="has-medium-font-size">유니티에 있는 기본 Standard Shader 가 대표적인 물리 기반 쉐이더입니다.</p>



<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size"><a href="https://docs.unity3d.com/kr/2021.3/Manual/SL-SurfaceShaders.html" target="_blank" rel="noreferrer noopener">https://docs.unity3d.com/kr/2021.3/Manual/SL-SurfaceShaders.html</a></p>



<div style="height:26px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><a href="https://docs.unity3d.com/kr/2021.3/Manual/SL-SurfaceShaders.html" target="_blank" rel="noreferrer noopener"><img decoding="async" width="1098" height="271" src="https://lycos7560.com/wp-content/uploads/image-371.png" alt="" class="wp-image-2793" srcset="https://lycos7560.com/wp-content/uploads/image-371.png 1098w, https://lycos7560.com/wp-content/uploads/image-371-300x74.png 300w, https://lycos7560.com/wp-content/uploads/image-371-768x190.png 768w" sizes="(max-width: 1098px) 100vw, 1098px" /></a></figure>



<div style="height:36px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1322" height="336" src="https://lycos7560.com/wp-content/uploads/image-372.png" alt="" class="wp-image-2795" srcset="https://lycos7560.com/wp-content/uploads/image-372.png 1322w, https://lycos7560.com/wp-content/uploads/image-372-300x76.png 300w, https://lycos7560.com/wp-content/uploads/image-372-768x195.png 768w" sizes="(max-width: 1322px) 100vw, 1322px" /></figure>



<div style="height:54px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">우리가 사용한&nbsp; o.Emission과 o.Albedo 같은 변수들은 바로 이 구조체 안에 정의되어 있는 것을 사용한 것이고</p>



<p class="has-medium-font-size">우리는 여기에 알맞은 값을 넣어 주면 알아서 결과가 나오게 되는 것입니다.&nbsp;</p>



<p class="has-medium-font-size">이제 다른 구조체들을 사용해 보겠습니다.</p>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<h2 class="wp-block-heading">08 &#8211; 02 Metallic,&nbsp;Smoothness</h2>



<div style="height:27px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">새로운 쉐이더와 메테리얼을 만들어서 Sphere에 적용 시켜줍니다.</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Shader "Custom/Metallic"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        #pragma surface surf Standard
        #pragma target 3.0

        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"
}</pre>



<div style="height:29px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="704" height="679" src="https://lycos7560.com/wp-content/uploads/image-373.png" alt="" class="wp-image-2796" srcset="https://lycos7560.com/wp-content/uploads/image-373.png 704w, https://lycos7560.com/wp-content/uploads/image-373-300x289.png 300w" sizes="(max-width: 704px) 100vw, 704px" /></figure>



<div style="height:61px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">기존 쉐이더에 이미 Metallic, Smoothness 가 생성되어 있습니다.</p>



<p class="has-medium-font-size">공부를 위해서 만들어 봅시다.</p>



<p class="has-medium-font-size">이제 Properties에 Metallic, Smoothness를</p>



<div style="height:68px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1008" height="1026" src="https://lycos7560.com/wp-content/uploads/image-374.png" alt="" class="wp-image-2797" srcset="https://lycos7560.com/wp-content/uploads/image-374.png 1008w, https://lycos7560.com/wp-content/uploads/image-374-295x300.png 295w, https://lycos7560.com/wp-content/uploads/image-374-768x782.png 768w" sizes="(max-width: 1008px) 100vw, 1008px" /></figure>



<div style="height:39px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Shader "Custom/Metallic"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _Metallic ("Metallic", Range(0, 1)) = 0 
        _Smoothness("Smoothness", Range(0, 1)) = 0
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        #pragma surface surf Standard
        #pragma target 3.0

        sampler2D _MainTex;
        float _Smoothness;
        float _Metallic;

        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;
            o.Metallic = _Metallic;
            o.Smoothness = _Smoothness;
        }
        ENDCG
    }
    FallBack "Diffuse"
}</pre>



<div style="height:55px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">이제 적당한 텍스쳐를 넣고 결과를 확인합니다.</p>



<div style="height:34px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="488" style="aspect-ratio: 1040 / 488;" width="1040" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_08_38_26_196.mp4"></video></figure>



<div style="height:59px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">Smoothness는 이 재질이 매끄러운지 거친 지를 결정하는 부분입니다.</p>



<p class="has-medium-font-size">0이면 완벽히 거칠어서 난반사(Diffise)만 일어나고 1이면 완벽히 매끄러워서 정반사(Specular)만 일어나게 됩니다.</p>



<p class="has-medium-font-size">유니티에서 Standard Shader라는 물리기반렌더링의 기본 개념은</p>



<p class="has-medium-font-size">나가는 빛의 양은 들오는 빛의 양을 넘길 수 없다라는 에너지 보존법칙 개념입니다.</p>



<p class="has-medium-font-size">재질의 거칠기에 따라서 난반사와 정반사의 비율이 결정되므로 정반사가 높아지면 그만큼 난반사의 비율이 적어집니다.</p>



<p class="has-medium-font-size">물리 기반 쉐이더에서 Metallic 이 0이면 스페큘러 컬러가 흑백이 되며 1이면 Albedo에 넣은 색이 됩니다.</p>



<p class="has-medium-font-size">금속은 고유의 스펙큘러 컬러를 가지고 있기 때문입니다.</p>



<p class="has-medium-font-size">가급적 0과 1외의 값은 쓰지 않는 것이 정확한 물리 기반 쉐이더를 다루는 방법입니다.&nbsp;</p>



<div style="height:110px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size"><a href="https://docs.unity3d.com/Manual/StandardShaderMaterialCharts.html" target="_blank" rel="noreferrer noopener">https://docs.unity3d.com/Manual/StandardShaderMaterialCharts.html</a></p>



<div style="height:21px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><a href="https://docs.unity3d.com/Manual/StandardShaderMaterialCharts.html" target="_blank" rel="noreferrer noopener"><img decoding="async" width="1096" height="267" src="https://lycos7560.com/wp-content/uploads/image-375.png" alt="" class="wp-image-2799" srcset="https://lycos7560.com/wp-content/uploads/image-375.png 1096w, https://lycos7560.com/wp-content/uploads/image-375-300x73.png 300w, https://lycos7560.com/wp-content/uploads/image-375-768x187.png 768w" sizes="(max-width: 1096px) 100vw, 1096px" /></a></figure>



<div style="height:26px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">유니티에서는 이러한 재질의 올바른 사용법을 위해서 아래와 같은 차트를 제공합니다.</p>



<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1317" height="913" src="https://lycos7560.com/wp-content/uploads/image-376.png" alt="" class="wp-image-2800" srcset="https://lycos7560.com/wp-content/uploads/image-376.png 1317w, https://lycos7560.com/wp-content/uploads/image-376-300x208.png 300w, https://lycos7560.com/wp-content/uploads/image-376-768x532.png 768w" sizes="(max-width: 1317px) 100vw, 1317px" /></figure>



<div style="height:93px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">노멀맵 추가 후 확인해보면 진짜 금속같이 보이네요</p>



<div style="height:57px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="588" style="aspect-ratio: 1248 / 588;" width="1248" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_08_41_41_662.mp4"></video></figure>



<div style="height:49px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Shader "Custom/Metallic"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _Metallic ("Metallic", Range(0, 1)) = 0 
        _Smoothness("Smoothness", Range(0, 1)) = 0
        _BumpMap("NormalMAp", 2D) = "bump" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        #pragma surface surf Standard
        #pragma target 3.0

        sampler2D _MainTex;
        float _Smoothness;
        float _Metallic;
        sampler2D _BumpMap;

        struct Input
        {
            float2 uv_MainTex;
            float2 uv_BumpMap;
        };

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            float3 d = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
            o.Normal = d;
            o.Albedo = c.rgb;
            o.Alpha = c.a;
            o.Metallic = _Metallic;
            o.Smoothness = _Smoothness;
        }
        ENDCG
    }
    FallBack "Diffuse"
}</pre>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
<p>The post <a href="https://lycos7560.com/unity/unity_shader_standard-shader-metallic-smoothness-unity-shader/2791/">8 &#8211; 01 ~ 02 Standard Shader / Metallic, Smoothness (Unity Shader)</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/unity/unity_shader_standard-shader-metallic-smoothness-unity-shader/2791/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_08_38_26_196.mp4" length="4317206" type="video/mp4" />
<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_08_41_41_662.mp4" length="3072517" type="video/mp4" />

			</item>
		<item>
		<title>6 &#8211; 04 ~ 06 UV와 Time, 불 이펙트, 이미지 UV 제어 (Unity Shader)</title>
		<link>https://lycos7560.com/unity/unity_shader-uv-control-time-image/2755/</link>
					<comments>https://lycos7560.com/unity/unity_shader-uv-control-time-image/2755/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Wed, 30 Nov 2022 21:52:35 +0000</pubDate>
				<category><![CDATA[Unity]]></category>
		<category><![CDATA[UnityShader]]></category>
		<category><![CDATA[_Time]]></category>
		<category><![CDATA[Fire]]></category>
		<category><![CDATA[Shader]]></category>
		<category><![CDATA[Standard Surface Shader]]></category>
		<category><![CDATA[Unity Shader]]></category>
		<category><![CDATA[UV]]></category>
		<category><![CDATA[이펙트]]></category>
		<category><![CDATA[파티클]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=2755</guid>

					<description><![CDATA[<p>Unity Shager 에서 UV와 Time, image를 이용한 UV제어에 대한 간단한 정리와 코드입니다.</p>
<p>The post <a href="https://lycos7560.com/unity/unity_shader-uv-control-time-image/2755/">6 &#8211; 04 ~ 06 UV와 Time, 불 이펙트, 이미지 UV 제어 (Unity Shader)</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">6 &#8211; 04 UV와 Time</h2>



<div style="height:26px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">이번에는 UV가 자동으로 흘러가게 만들 것입니다.</p>



<p class="has-medium-font-size">UV에 숫자를 더하면 이미지가 이동하는 것을 알고 있습니다.</p>



<p class="has-medium-font-size">Unity에 내장된 변수인 _Time을 이용하여 시간에 따라 이미지가 흘러가는 것처럼 보이게 만들 것입니다.</p>



<div style="height:89px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size"><a href="https://docs.unity3d.com/kr/2021.3/Manual/SL-UnityShaderVariables.html" target="_blank" rel="noreferrer noopener">https://docs.unity3d.com/kr/2021.3/Manual/SL-UnityShaderVariables.html</a> &lt;- 한글</p>



<div style="height:10px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><a href="https://docs.unity3d.com/kr/2021.3/Manual/SL-UnityShaderVariables.html" target="_blank" rel="noreferrer noopener"><img decoding="async" width="961" height="235" src="https://lycos7560.com/wp-content/uploads/image-351.png" alt="" class="wp-image-2757" srcset="https://lycos7560.com/wp-content/uploads/image-351.png 961w, https://lycos7560.com/wp-content/uploads/image-351-300x73.png 300w, https://lycos7560.com/wp-content/uploads/image-351-768x188.png 768w" sizes="(max-width: 961px) 100vw, 961px" /></a></figure>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size"><a href="https://docs.unity3d.com/460/Documentation/Manual/SL-BuiltinValues.html" target="_blank" rel="noreferrer noopener">https://docs.unity3d.com/460/Documentation/Manual/SL-BuiltinValues.html</a>  &lt;- 영문</p>



<div style="height:10px" aria-hidden="true" class="wp-block-spacer"></div>



<div style="height:44px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1519" height="836" src="https://lycos7560.com/wp-content/uploads/image-354.png" alt="" class="wp-image-2760" srcset="https://lycos7560.com/wp-content/uploads/image-354.png 1519w, https://lycos7560.com/wp-content/uploads/image-354-300x165.png 300w, https://lycos7560.com/wp-content/uploads/image-354-768x423.png 768w" sizes="(max-width: 1519px) 100vw, 1519px" /></figure>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-table is-style-regular has-medium-font-size"><table><tbody><tr><td>이름</td><td>타입</td><td>값</td></tr><tr><td>_Time</td><td>float4</td><td>씬이 열린 다음부터의 시간<br><br>(x, y, z, w)는 (t / 20, t, t * 2, t * 3) 에 대응합니다.<br><br>_Time.x는 1/20 속도&nbsp;<br><br>_Time.y는 원래의 시간<br><br>_Time.z는 2배의 속도 시간<br><br>_Time.w는 3배의 속도 시간</td></tr><tr><td>_SinTime</td><td>float4</td><td>sin 그래프의 시간입니다.<br><br>(x, y, z, w)는 (t / 8, t / 4, t / 2, t) 에 대응합니다.</td></tr><tr><td>_CosTime</td><td>float4</td><td>cos 그래프의 시간입니다.<br><br>(x, y, z, w)는 (t / 8, t / 4, t / 2, t) 에 대응합니다.</td></tr><tr><td>Unity_DeltaTime</td><td>float4</td><td>Delta Time은 지금의 프레임과 이전 시간의 프레임의 시간차이를 나타냅니다.<br><br>컴퓨터의 성능에 따라 프레임을 조작해 줄 댸 주로 사용합니다.<br><br>(x, y, z, w)는 (dt, 1/dt, smoothDt, 1/smoothDt)와 대응합니다.</td></tr></tbody></table></figure>



<div style="height:124px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">간단하게 UV에 시간을 더해봅니다.</p>



<div style="height:37px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="707" height="363" src="https://lycos7560.com/wp-content/uploads/image-355.png" alt="" class="wp-image-2761" srcset="https://lycos7560.com/wp-content/uploads/image-355.png 707w, https://lycos7560.com/wp-content/uploads/image-355-300x154.png 300w" sizes="(max-width: 707px) 100vw, 707px" /></figure>



<div style="height:64px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="636" style="aspect-ratio: 1088 / 636;" width="1088" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_06_28_24_396.mp4"></video></figure>



<div style="height:88px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">이미지가 좌측 아래로 흘러가는 이유는 U/V 즉 X/Y에 동시에 _Time.y 를 더해주었기 때문입니다.</p>



<p class="has-medium-font-size">이를 이용하여 다양한 효과를 줄 수 있습니다.</p>



<div style="height:157px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">X방향으로만 흘러가게 할 때</p>



<p class="has-medium-font-size">(+ / &#8211; 의 조절로 방향도 전환 및 순자를 곱하여 속도 변경도 가능합니다.)</p>



<div style="height:34px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="636" style="aspect-ratio: 1088 / 636;" width="1088" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_06_33_26_306.mp4"></video></figure>



<div style="height:26px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="956" height="210" src="https://lycos7560.com/wp-content/uploads/image-358.png" alt="" class="wp-image-2767" srcset="https://lycos7560.com/wp-content/uploads/image-358.png 956w, https://lycos7560.com/wp-content/uploads/image-358-300x66.png 300w, https://lycos7560.com/wp-content/uploads/image-358-768x169.png 768w" sizes="(max-width: 956px) 100vw, 956px" /></figure>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">Y방향으로만 흘러가게 할 때</p>



<div style="height:26px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="636" style="aspect-ratio: 1088 / 636;" width="1088" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_06_29_48_573.mp4"></video></figure>



<div style="height:28px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="951" height="223" src="https://lycos7560.com/wp-content/uploads/image-357.png" alt="" class="wp-image-2765" srcset="https://lycos7560.com/wp-content/uploads/image-357.png 951w, https://lycos7560.com/wp-content/uploads/image-357-300x70.png 300w, https://lycos7560.com/wp-content/uploads/image-357-768x180.png 768w" sizes="(max-width: 951px) 100vw, 951px" /></figure>



<div style="height:23px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Shader "Custom/UVTest"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        #pragma surface surf Standard
        #pragma target 3.0

        sampler2D _MainTex;

        struct Input
        {
            float2 uv_MainTex;
        };

        void surf (Input IN, inout SurfaceOutputStandard o)
        {

            fixed4 c = tex2D (_MainTex, float2(IN.uv_MainTex.x, IN.uv_MainTex.y + _Time.y));
            o.Emission = c.rgb;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}</pre>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<h2 class="wp-block-heading">6 &#8211; 05 UV를 이용한 불 이펙트 만들기</h2>



<div style="height:32px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="888" height="310" src="https://lycos7560.com/wp-content/uploads/image-359.png" alt="" class="wp-image-2768" srcset="https://lycos7560.com/wp-content/uploads/image-359.png 888w, https://lycos7560.com/wp-content/uploads/image-359-300x105.png 300w, https://lycos7560.com/wp-content/uploads/image-359-768x268.png 768w" sizes="(max-width: 888px) 100vw, 888px" /></figure>



<div style="height:41px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">알파 채널을 가지고 있는 이미지를 준비하고 텍스쳐 하나만 받는 쉐이더를 만듭니다.</p>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Shader "Custom/fire3"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        #pragma surface surf Standard
        #pragma target 3.0

        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"
}</pre>



<div style="height:46px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">불이라기에는 투명하지도 않고 움직이지도 않으며 빛의 영향까지 받습니다.</p>



<div style="height:41px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1029" height="478" src="https://lycos7560.com/wp-content/uploads/image-360.png" alt="" class="wp-image-2769" srcset="https://lycos7560.com/wp-content/uploads/image-360.png 1029w, https://lycos7560.com/wp-content/uploads/image-360-300x139.png 300w, https://lycos7560.com/wp-content/uploads/image-360-768x357.png 768w" sizes="(max-width: 1029px) 100vw, 1029px" /></figure>



<div style="height:35px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">우선 빛의 영향을 받지 않게 하기 위해서 o.Albedo를 o.Emission으로 변경합니다.</p>



<p class="has-medium-font-size">이 불의 이미지는 알파 값을 가지고 있는데도 불구하고 투명해지지 않고 있습니다.</p>



<p class="has-medium-font-size">알파채널은 그냥 쉽게 작동하지 않고 활성화시키려면 더 근본적인 부분을 건드려야 합니다.</p>



<p class="has-medium-font-size">알파는 실제 게임에서 일반 오브젝트와 매우 다르게 처리되며, 상당히 무거운 연산중에 하나입니다.&nbsp;</p>



<p class="has-medium-font-size">우선 임시로 작동하도록 만듭니다.</p>



<div style="height:49px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1077" height="541" src="https://lycos7560.com/wp-content/uploads/image-361.png" alt="" class="wp-image-2770" srcset="https://lycos7560.com/wp-content/uploads/image-361.png 1077w, https://lycos7560.com/wp-content/uploads/image-361-300x151.png 300w, https://lycos7560.com/wp-content/uploads/image-361-768x386.png 768w" sizes="(max-width: 1077px) 100vw, 1077px" /></figure>



<div style="height:26px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Shader "Custom/fire3"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Transparent" "Queue" = "Transparent" }
        LOD 200

        CGPROGRAM
        #pragma surface surf Standard alpha:fade
        #pragma target 3.0

        sampler2D _MainTex;

        struct Input
        {
            float2 uv_MainTex;
        };

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            o.Emission = c.rgb;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}</pre>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">이제 불처럼 보이는 이미지를 만드는 데까지는 성공했습니다.</p>



<p class="has-medium-font-size">하지만 움직이지 않으니 그냥 정지된 불 이미지 같습니다.</p>



<p class="has-medium-font-size">일단 만들어 놓은 쉐이더에 새로운 이미지(알파 값을 가진)를 추가로 받을 수 있게 만들고 출력해 보겠습니다.</p>



<div style="height:41px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1085" height="946" src="https://lycos7560.com/wp-content/uploads/image-362.png" alt="" class="wp-image-2771" srcset="https://lycos7560.com/wp-content/uploads/image-362.png 1085w, https://lycos7560.com/wp-content/uploads/image-362-300x262.png 300w, https://lycos7560.com/wp-content/uploads/image-362-768x670.png 768w" sizes="(max-width: 1085px) 100vw, 1085px" /></figure>



<div style="height:36px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1086" height="876" src="https://lycos7560.com/wp-content/uploads/image-363.png" alt="" class="wp-image-2772" srcset="https://lycos7560.com/wp-content/uploads/image-363.png 1086w, https://lycos7560.com/wp-content/uploads/image-363-300x242.png 300w, https://lycos7560.com/wp-content/uploads/image-363-768x619.png 768w" sizes="(max-width: 1086px) 100vw, 1086px" /></figure>



<div style="height:35px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">추가로 이 이미지를 _Time.y를 이용하여 위쪽으로 흘러가게 만들겠습니다.</p>



<div style="height:34px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="720" style="aspect-ratio: 1232 / 720;" width="1232" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_06_38_15_621.mp4"></video></figure>



<div style="height:44px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1076" height="288" src="https://lycos7560.com/wp-content/uploads/image-364.png" alt="" class="wp-image-2774" srcset="https://lycos7560.com/wp-content/uploads/image-364.png 1076w, https://lycos7560.com/wp-content/uploads/image-364-300x80.png 300w, https://lycos7560.com/wp-content/uploads/image-364-768x206.png 768w" sizes="(max-width: 1076px) 100vw, 1076px" /></figure>



<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">이제 완성된 두 개의 이미지를 합쳐서 완성해 보겠습니다.</p>



<p class="has-medium-font-size">간단히&nbsp; c 와 d의 색상값. 알파 값을 곱해줍니다.</p>



<div style="height:34px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1086" height="237" src="https://lycos7560.com/wp-content/uploads/image-365.png" alt="" class="wp-image-2775" srcset="https://lycos7560.com/wp-content/uploads/image-365.png 1086w, https://lycos7560.com/wp-content/uploads/image-365-300x65.png 300w, https://lycos7560.com/wp-content/uploads/image-365-768x168.png 768w" sizes="(max-width: 1086px) 100vw, 1086px" /></figure>



<div style="height:44px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="1168" style="aspect-ratio: 1072 / 1168;" width="1072" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_06_40_28_734.mp4"></video></figure>



<div style="height:53px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Shader "Custom/fire3"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _MainTex2 ("Albedo2 (RGB)", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Transparent" "Queue" = "Transparent" }
        LOD 200

        CGPROGRAM
        #pragma surface surf Standard alpha:fade
        #pragma target 3.0

        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, float2(IN.uv_MainTex2.x, IN.uv_MainTex2.y - _Time.y));
            o.Emission = c.rgb * d.rgb;
            o.Alpha = c.a * d.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}</pre>



<div style="height:55px" aria-hidden="true" class="wp-block-spacer"></div>



<p>이런 방법으로 흐르는 물이나 폭포 플라스마 이펙트 등 다양한 표현이 가능합니다.</p>



<p>하지만 이 방법은 매우 무거운 Standard 라이팅이 돌아가고 있고,</p>



<p>뒤의 이미지와 겹쳐도 밝아지지 않는 불완전한 이펙트라고 할 수 있습니다.</p>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">6 &#8211; 06 이미지를 이용한 UV 제어</h2>



<p class="has-medium-font-size"><br>이미지를 2장 받을 수 있으며 반투명이 동작하도록 만들어 줍니다.</p>



<p class="has-medium-font-size">확실한 이미지를 알 수 있게 체크 무늬로 변경해줍니다.</p>



<p class="has-medium-font-size">추가적으로 두번째 이미지를 데이터로 사용하기 위하여 위치를 바꾸어 주고 값을 더 해줍니다.</p>



<div style="height:45px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Shader "Custom/fire3"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _MainTex2 ("Albedo2 (RGB)", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Transparent" "Queue" = "Transparent" }
        LOD 200

        CGPROGRAM
        #pragma surface surf Standard alpha:fade
        #pragma target 3.0

        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.Emission = c.rgb;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}</pre>



<div style="height:35px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1097" height="430" src="https://lycos7560.com/wp-content/uploads/image-366.png" alt="" class="wp-image-2777" srcset="https://lycos7560.com/wp-content/uploads/image-366.png 1097w, https://lycos7560.com/wp-content/uploads/image-366-300x118.png 300w, https://lycos7560.com/wp-content/uploads/image-366-768x301.png 768w" sizes="(max-width: 1097px) 100vw, 1097px" /></figure>



<div style="height:41px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">c 의 uv에 d.r을 더해 주었습니다.</p>



<p class="has-medium-font-size">d에 검은색을 넣어 주었으므로 d는 float(0, 0, 0, 1)입니다. 그리고 d.r은 0이 되어서 아무 일도 일어나지 않습니다.</p>



<p class="has-medium-font-size">하지만 텍스쳐를 변경한다면?</p>



<div style="height:54px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1086" height="651" src="https://lycos7560.com/wp-content/uploads/image-367.png" alt="" class="wp-image-2778" srcset="https://lycos7560.com/wp-content/uploads/image-367.png 1086w, https://lycos7560.com/wp-content/uploads/image-367-300x180.png 300w, https://lycos7560.com/wp-content/uploads/image-367-768x460.png 768w" sizes="(max-width: 1086px) 100vw, 1086px" /></figure>



<div style="height:56px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">d의 텍스쳐가 회색이라면 d.r은 0.5이므로 텍스쳐 전체 이미지의 절반 정도 이동할 것이고,</p>



<p class="has-medium-font-size">d의 텍스쳐가 흰색이라면 d.r은 1 이므로 텍스쳐 전체 이미지만큼 이동하여 원래 이미지와 같아질 것입니다.</p>



<p class="has-medium-font-size">그렇다면 단색이 아닌 다른 이미지를 넣으면?</p>



<div style="height:43px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="871" height="753" src="https://lycos7560.com/wp-content/uploads/image-368.png" alt="" class="wp-image-2779" srcset="https://lycos7560.com/wp-content/uploads/image-368.png 871w, https://lycos7560.com/wp-content/uploads/image-368-300x259.png 300w, https://lycos7560.com/wp-content/uploads/image-368-768x664.png 768w" sizes="(max-width: 871px) 100vw, 871px" /></figure>



<div style="height:45px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">이미지 밝기에 따라서 다르게 이동하였습니다.</p>



<p class="has-medium-font-size">이번에는 이미지를 흐르게 해보겠습니다.</p>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Shader "Custom/fire3"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _MainTex2 ("Albedo2 (RGB)", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Transparent" "Queue" = "Transparent" }
        LOD 200

        CGPROGRAM
        #pragma surface surf Standard alpha:fade
        #pragma target 3.0

        sampler2D _MainTex;
        sampler2D _MainTex2;

        struct Input
        {
            float2 uv_MainTex;
            float2 uv_MainTex2;
        };

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            fixed4 d = tex2D(_MainTex2, float2(IN.uv_MainTex2.x, IN.uv_MainTex2.y - _Time.y));
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex + d.r);
            o.Emission = c.rgb;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}</pre>



<div style="height:37px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="796" style="aspect-ratio: 1232 / 796;" width="1232" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_06_45_28_524.mp4"></video></figure>



<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">그리고 불이미지로 변경합니다.</p>



<div style="height:38px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-video"><video height="796" style="aspect-ratio: 1232 / 796;" width="1232" controls src="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_06_45_45_504.mp4"></video></figure>



<div style="height:37px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="588" height="88" src="https://lycos7560.com/wp-content/uploads/image-369.png" alt="" class="wp-image-2782" srcset="https://lycos7560.com/wp-content/uploads/image-369.png 588w, https://lycos7560.com/wp-content/uploads/image-369-300x45.png 300w" sizes="(max-width: 588px) 100vw, 588px" /></figure>



<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">위의 코드는 standard 쉐이더 즉, 현재 물리 기반의 라이팅이 작동되고 있다는 뜻 입니다.</p>



<p class="has-medium-font-size">이것은 상당히 무거운 공식이며, 실제로 이 쉐이더에서는 이 물리기반 라이팅 공식이 전혀 사용되지 않음에도 불구하고</p>



<p class="has-medium-font-size">이 공식이 구동되고 있다는 것을 의미합니다. (자원의 낭비)</p>



<p class="has-medium-font-size">이 부분은 나중에 라이팅 연산을 배우고 난 후, 라이팅을 전혀 처리하지 않는 코드로 고치면</p>



<p class="has-medium-font-size">실제로 부담없이 사용 할 수 있습니다.</p>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
<p>The post <a href="https://lycos7560.com/unity/unity_shader-uv-control-time-image/2755/">6 &#8211; 04 ~ 06 UV와 Time, 불 이펙트, 이미지 UV 제어 (Unity Shader)</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/unity/unity_shader-uv-control-time-image/2755/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_06_28_24_396.mp4" length="214639" type="video/mp4" />
<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_06_33_26_306.mp4" length="172760" type="video/mp4" />
<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_06_29_48_573.mp4" length="172078" type="video/mp4" />
<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_06_38_15_621.mp4" length="363138" type="video/mp4" />
<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_06_40_28_734.mp4" length="647436" type="video/mp4" />
<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_06_45_28_524.mp4" length="1301764" type="video/mp4" />
<enclosure url="https://lycos7560.com/wp-content/uploads/녹화_2022_12_01_06_45_45_504.mp4" length="450285" type="video/mp4" />

			</item>
	</channel>
</rss>
