Shader "Ageia/SimpleReflectionProbe" {

Properties {

_Color ("Color", Color) = (1,1,1,1)

_MainTex ("Albedo (RGB)", 2D) = "white" {}

[Normal]_Normal("Normal", 2D) = "bump"{}

_NormalPow("NormalPow", Range(0, 3)) = 1

_Metallic("Metallic", Range(0, 1)) = 1

}

SubShader {

Tags { "RenderType"="Opaque" }

LOD 200


CGPROGRAM

// Physically based Standard lighting model, and enable shadows on all light types

#pragma surface surf CumstomLighing fullforwardshadows


// Use shader model 3.0 target, to get nicer looking lighting

#pragma target 3.0


sampler2D _MainTex;

sampler2D _Normal;


struct Input {

float2 uv_MainTex;

half2 uv_Normal;

half3 viewDir;

half3 worldRefl; //WorldReflectionVector ๋ฐ์ดํ„ฐ์— ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.


INTERNAL_DATA

//worldRefl ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ค๊ธฐ ์œ„ํ•ด ํ•ด๋‹น ๋ฐ์ดํ„ฐ ๊ตฌ์กฐ๋ฅผ ํ•„์š”๋กœ ํ•จ.

};


fixed4 _Color;

half _NormalPow;

half _NormalPow2;

half _Metallic;


// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.

// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.

// #pragma instancing_options assumeuniformscaling

UNITY_INSTANCING_BUFFER_START(Props)

// put more per-instance properties here

UNITY_INSTANCING_BUFFER_END(Props)


void surf (Input IN, inout SurfaceOutput o) {

half3 NormalTest = UnpackNormal(tex2D(_Normal, IN.uv_Normal));

o.Normal = lerp(o.Normal, NormalTest, _NormalPow);


//simpleReflectionMap

half3 Reflection1 = UNITY_SAMPLE_TEXCUBE(unity_SpecCube0, WorldReflectionVector(IN, o.Normal)) * unity_SpecCube0_HDR.r;

//unity_SpecCube0_HDR.r : ๋ฆฌํ”Œ๋ ‰์…˜ ํ๋ธŒ์˜ Intensity๊ฐ’.

half3 Reflection2 = UNITY_SAMPLE_TEXCUBE_SAMPLER(unity_SpecCube1, unity_SpecCube0, WorldReflectionVector(IN, o.Normal)) * unity_SpecCube0_HDR.r;

//Reflection2๋Š” ๋‹ค๋ฅธ ๋ฆฌํ”Œ๋ ‰์…˜ ํ”„๋กœ๋ธŒ์™€์˜ ๋ณด๊ฐ„์„ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค. ํ•„์š”์—†๋Š” ๊ฒฝ์šฐ ์ œ๊ฑฐ ํ•˜์‹ญ์‹œ์˜ค.

half3 ReflectionFinal = lerp(Reflection2, Reflection1, unity_SpecCube0_BoxMin.w);

//unity_SpecCube0_BoxMin.w : ๋‘๊ฐœ์˜ ๋ฆฌํ”Œ๋ ‰์…˜ ํ”„๋กœ๋ธŒ๋ฅผ ๋ณด๊ฐ„ํ•ฉ๋‹ˆ๋‹ค.


fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;


o.Albedo = lerp(c.rgb, 0, _Metallic);

//o.Emission = pow(NdotV * 0.5 + 0.5, 20);

o.Emission = lerp(0, ReflectionFinal, _Metallic);

o.Alpha = c.a;

}


half4 LightingCumstomLighing(SurfaceOutput s, half3 lightDir, half atten)

{

half4 c;

c.rgb = s.Albedo;

c.a = s.Alpha;

return c;

}


ENDCG

}

FallBack "Diffuse"

}





๋ชจ๋ฐ”์ผ ์ „์šฉ ๋ฆฌํ”Œ๋ ‰์…˜ ํ”„๋กœ๋ธŒ ๋ธ”๋ Œ๋”ฉ ์‰์ด๋” ๋งŒ๋“ค์–ด๋ดค์Šต๋‹ˆ๋‹ค.


์‰์ด๋” ๋งŒ์งˆ์ค„ ์•„์‹œ๋Š” ๋ถ„์ด๋ฉด ์ด๊ฑธ๋กœ ๊ธˆ์† ์งˆ๊ฐ ์ฒ˜๋ฆฌํ•˜๊ฑฐ๋‚˜ ํ•˜์‹œ๋ฉด ๋ ๋“ฏ ํ•ฉ๋‹ˆ๋‹ค.