Skip to content
This repository has been archived by the owner on Sep 24, 2024. It is now read-only.

๐Ÿ“š๐ŸŒ”์ฑ…๊ณต๋ถ€. ์œ ๋‹ˆํ‹ฐ ์‰์ด๋” ์Šคํƒ€ํŠธ์—…

Notifications You must be signed in to change notification settings

netpyoung/bs.shader_startup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

7 Commits
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

์œ ๋‹ˆํ‹ฐ ์‰์ด๋” ์Šคํƒ€ํŠธ์—… http://vielbooks.com/235

example : https://drive.google.com/uc?id=0B10G1-ySdDd1VVZiQzQyRll4RlE&export=download password : utshader576

Free MatCap Shaders

ch04

Albedo : ๋ฌผ์ฒด ๊ณ ์œ  ์ƒ‰๊น”. Diffuse : ๋น›์— ์˜ํ•œ ์ƒ‰์ƒ. normal์˜ํ–ฅ์„ ๋ฐ›๋Š”. Specular : ๋น›์— ์˜ํ•ด ํ•˜์ด๋ผ์ดํŠธ. Emission : ์ž์ฒด๋ฐœ๊ด‘์ƒ‰, ๋น›์˜ ๊ฐ„์„ญ ์—†์ด ์ˆœ์ˆ˜ํ•œ ์ƒ‰์ƒ ์—ฐ์‚ฐ ๋ณผ ๋•Œ.

noambient : ambient color๋ฅผ ๋ˆ๋‹ค. Window/Lighting/Settings [Scene] Environment

  • Environment Reflections
    • Source : Custom
#pragma surface surf Standard fullforwardshadows noambient

ch05

texture 2๊ฐœ lerp

ch06

texture uv, ์‹œ๊ฐ„์— ๋”ฐ๋ฅธ ๋ณ€ํ™”

float4 _Time; (x, y, z, w) = (t/20, t, t * 2, t * 3) float4 _SinTime; (x, y, z, w) = (t/8, t/4, t/2, t) float4 _CosTime; (x, y, z, w) = (t/8, t/4, t/2, t) float4 unity_DeltaTime; (x, y, z, w) = (dt, 1/dt, smoothDt, 1/smoothDt)

	Tags { "RenderType"="Transparent" "Queue" = "Transparent" }

Queue ํƒœ๊ทธ Transparent - ์ด ๋ Œ๋” ํ๋Š” _Geometry_์™€ AlphaTest ํ›„์— ๋’ค๋ถ€ํ„ฐ ์ˆœ์„œ๋Œ€๋กœ(back-to-front) ๋ Œ๋”๋ง๋ฉ๋‹ˆ๋‹ค. ์•ŒํŒŒ ๋ธ”๋ Œ๋”ฉํ•˜๋Š” ๊ฒƒ (์ฆ‰, ๊นŠ์ด ๋ฒ„ํผ์— ๊ธฐ๋กํ•˜์ง€ ์•Š๋Š” ์‰์ด๋”)์€ ๋ชจ๋‘ ์—ฌ๊ธฐ์— ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค(์œ ๋ฆฌ, ํŒŒํ‹ฐํด ํšจ๊ณผ).

	#pragma surface surf Standard alpha:fade

alpha or alpha:auto - Will pick fade-transparency (same as alpha:fade) for simple lighting functions, and premultiplied transparency (same as alpha:premul) for physically based lighting functions. alpha:fade - Enable traditional fade-transparency. alpha:premul - Enable premultiplied alpha transparency.

Scene ์ฐฝ์˜ ์‚ฐ๊ทธ๋ฆผ Animated Material ํ™œ์„ฑํ™”

ch07

vertex color

ch08

metallic chart https://docs.unity3d.com/Manual/StandardShaderMaterialCharts.html

Shader Calibration Scene https://www.assetstore.unity3d.com/en/#!/content/25422

_BumpMap ๋ณ€์ˆ˜ ์ด๋ฆ„์€, ๋‹ค๋ฅธ ๋‚ด์žฅ ์‰์ด๋”์—์„œ ์“ฐ๊ณ  ์žˆ๊ธฐ์—, ํ˜ธํ™˜์„ฑ์„ ์œ„ํ•ด ๋งž์ถฐ์ฃผ์ž

DXT5nm - NormalMap ํ’ˆ์งˆ์„ ์ €ํ•˜๋ฅผ ๋ง‰๊ธฐ ์œ„ํ•ด ๋งŒ๋“  AGํŒŒ์ผ ํฌ๋ฉง. R๊ณผG์˜ ํ€„๋ฆฌํ‹ฐ๋ฅผ ์ตœ๋Œ€ํ•œ ๋ณด์ „, A, G์— ๋„ฃ์–ด ์ €์žฅ. NormalMap์˜ X,Y๋กœ ๊ณ„์‚ฐ๋˜๋ฉฐ, Z๋Š” ์‚ผ๊ฐํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•˜์—ฌ ์ˆ˜ํ•™์ ์œผ๋กœ ์ถ”์ถœ. fixed3 n = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));

Occlusion : ๊ตฌ์„์ง„ ๋ถ€๋ถ„ ์ถ”๊ฐ€ ์Œ์˜์ฒ˜๋ฆฌ. ํ™˜๊ฒฝ๊ด‘(Ambient Color)๊ฐ€ ๋‹ฟ์ง€ ์•Š๋Š” ๋ถ€๋ถ„์„ Ambient Occlusion์ด๋ผ ๋ถ€๋ฆ„.

Occlusion ๊ธฐ๋Šฅ์„ ๋„ฃ๊ธฐ ์œ„ํ•ด, ํ…์Šค์ณ๋ฅผ ํ•œ์žฅ ๋” ์‚ฌ์šฉํ•˜๋Š”๊ฒƒ์€ ์šฉ๋Ÿ‰ ๋‚ญ๋น„๊ฐ€ ์žˆ์œผ๋ฏ€๋กœ, ๋‹ค๋ฅธ ๊ณณ์— ์ฐก๊ฒจ๋„ฃ๋Š” ๊ฒƒ๋„ ์ƒ๊ฐํ•ด๋ณด์ž(๋ฉ”์ธํ…์Šค์ณ ์•ŒํŒŒ๋ผ๋˜๊ฐ€).

ch09

struct SurfaceOutputStandard {
    fixed3 Albedo;
    fixed3 Normal;
    fixed3 Emission;
    half Metallic;
    half Smoothness;
    half Occlusion;
    half Alpha;
}
struct SurfaceOutput {
    fixed3 Albedo;
    fixed3 Normal;
    fixed3 Emission;
    half Specular; // specular range.
    half Gloss; // specular power.
    half Alpha;
}

BlinnPhong ์‰์ด๋”์—๋Š” _SpecColor ๋ณ€์ˆ˜๊ฐ€ ํ•„์š”ํ•˜๋‹ค.

ch10

img

ch11

float4 LightingTest(SurfaceOutput s, float3 lightDir, float atten)

lightDir - (๋’ค์ง‘ํžŒ)์กฐ๋ช…๋ฒกํ„ฐ atten : attenuation - ๊ฐ์‡ 

ch12

BRDF(Bidirectional Reflectance Distribute Function)

๊ฐ™์€ ๊ด‘์›์ผ์ง€๋ผ๋„ ๊ฐ๋„๊ฐ€ ์ž‘์œผ๋ฉด ์ŠคํŽ™ํ˜๋Ÿฌ๊ฐ€ ํ›จ์”ฌ ๋ฐ๊ฒŒ ๋ณด์ด๋Š” ํ˜„์ƒ. Fresnel

  • ๋น›์ด ์„œ๋กœ ๋‹ค๋ฅธ ๊ตด์ ˆ๋ฅ ์„ ๊ฐ–๋Š” ๋งค์งˆ์˜ ๊ฒฝ๊ณ„๋ฉด์„ ํ†ต๊ณผํ•  ๋•Œ์˜ ๋ฐ˜์‚ฌ

http://www.gamedevforever.com/35 http://hwan0123.tistory.com/entry/ํ”„๋ ˆ๋„ฌ-๋ฐฉ์ •์‹

float3 viewDir; ๋ทฐ์˜ ๋ฐฉํ–ฅ
float4 color:Color; ๋ณด๊ฐ„๋œ ๋ฒ„ํ…์Šค ์นผ๋ผ
float4 screenPos; ์Šคํฌ๋ฆฐ ๊ณต๊ฐ„์ƒ์˜ ์œ„์น˜
float3 worldPos; ์›”๋“œ ๊ณต๊ฐ„์ƒ์˜ ์œ„์น˜
float3 worldRefl; o.Normal์ด ์—†๋Š”๊ฒฝ์šฐ, ์›”๋“œ ๋ฐ˜์‚ฌ ๋ฒกํ„ฐ(diffuse์‰์ด๋” ์ฐธ์กฐ)
float3 worldNormal; o.Normal์ด ์—†๋Š”๊ฒฝ์šฐ, ์›”๋“œ ๋…ธ๋ฉ€๋ฒกํ„ฐ
float3 worldRefl; INTERNAL_DATA o.Normal์ด ์žˆ๋Š” ๊ฒฝ์šฐ, ์›”๋“œ ๋ฐ˜์‚ฌ๋ฒกํ„ฐ ํฌํ•จ.
ํ”ฝ์…€๋‹น ๋…ธ๋ฉ€๋งต์— ๊ธฐ์ดˆํ•˜์—ฌ, ๋ฐ˜์‚ฌ ๋ฒกํ„ฐ๋ฅผ ์–ป์œผ๋ ค๋ฉด WorldReflectionVector(IN, o.Normal).(Reflect-Bumped์‰์ด๋” ์ฐธ์กฐ)
float3 worldNormal; INTERNAL_DATA o.Normal์ด ์žˆ๋Š” ๊ฒฝ์šฐ, ์›”๋“œ ๋…ธ๋ง๋ฒกํ„ฐ ํฌํ•จ.
ํ”ฝ์…€๋‹น ๋…ธ๋ฉ€๋งต์— ๊ธฐ์ดˆํ•˜์—ฌ, ๋…ธ๋ง ๋ฒกํ„ฐ๋ฅผ ์–ป์œผ๋ ค๋ฉด WorldNormalVector(IN, o.Normal).

ch13

_SpecColor๋Š” ์ด๋ฏธ ์œ ๋‹ˆํ‹ฐ์—์„œ ์“ฐ๊ณ  ์žˆ๋‹ค.

์–ด์ฐจํ”ผ rim์—์„œ ๊ฐ€์ ธ๋‹ค ์“ฐ๋Š”๊ฑฐ๊ณ  ํ•ด์„œ, rim์„ ๊ฐ€์งœ ์ŠคํŽ™์ฟจ๋Ÿฌ๋กœ ํ™œ์šฉํ•˜๋ฉด ๊ฐ€์งœ๋กœ ์กฐ๋ช…ํ•˜๋‚˜ ์–ป๋Š” ๊ธฐ๋ถ„์„ ๋Š๋‚„ ์ˆ˜ ์žˆ๋‹ค.

ch14

PR(Photo Realistic) NPR(Non-Photo Realistic)

https://en.wikipedia.org/wiki/Cel_shading

์™ธ๊ณฝ์„ 

2pass

  • ๋…ธ๋ง๊ฐ’์„ ํ‚ค์›Œ ํ•œ๋ฒˆ ๋” ๊ทธ๋ ค์ค€๋‹ค.
  • 2๋ฒˆ ๊ทธ๋ฆฌ๋‹ˆ ๋ฌด๊ฒ๋‹ค.
  • Plane์œผ๋กœ ๋๋‚œ ์˜ค๋ธŒ์ ํŠธ์—๋Š” ์™ธ๊ณฝ์„  ์•ˆ์ƒ๊น€
  • ๋งค์‰ฌ๋ผ๋ฆฌ ์นจ๋ฒ”ํ•˜๊ฑฐ๋‚˜ ์ฐŒ๊บผ๊ธฐ ๋ณด์ผ ์ˆ˜ ์žˆ๋‹ค.
    • ์„ ์„ ์–‡๊ฒŒํ•œ๋‹ค.
    • ๋ฒ„ํ…์Šค ์นผ๋ผ ๋งˆ์Šคํ‚น ๋“ฑ์„ ํ†ตํ•ด ์™ธ๊ณฝ์„ ์ด ๋Œ์ถœ ๋˜์ง€ ์•Š๋„๋ก.
  • Hard Edge์—๋Š” ์„ ์ด ๋Š๊น€
    • ๋ชจ๋ธ๋ง ํˆด์—์„œ smooth ๊ทธ๋ฃน์œผ๋กœ ๋ฌถ์–ด์ฃผ๊ฑฐ๋‚˜ ํ•ด์•ผํ•จ

Fresnel

  • rim์„ ๋’ค์ง‘๊ฑฐ๋‚˜, ์™ธ๊ณฝ๋ผ์ธ ๊ฒ€์ถœ
  • ํ”ฝ์…€๊ณผ ๋…ธ๋ง๊ณผ ์‹œ์„ ๋ฐฉํ–ฅ์˜ ์ฐจ์ด์— ๋”ฐ๋ผ ๊ณ„์‚ฐ๋จ์œผ๋กœ, ํ‰๋ฉด์„ ๊ฐ€์ง„ ์˜ค๋ธŒ์ ํŠธ์—๋Š” ์ด์ƒํ•˜๊ฒŒ ๋ณด์ž„.

Poss Effect

UnityCG.cginc appdata_base: position, normal and one texture coordinate. appdata_tan: position, tangent, normal and one texture coordinate. appdata_full: position, tangent, normal, four texture coordinates and color.

http://www.valvesoftware.com/publications/2007/NPAR07_IllustrativeRenderingInTeamFortress2.pdf

Warped diffuse

ch15

cubemap o.Albedo ? o.Emission? ๋ฐ˜์‚ฌ๋Š” ๋ฐ๊ฑฐ๋‚˜ ์–ด๋‘์šด ์ฃผ๋ณ€์ด๋ฏธ์ง€๋ฅผ ๋ฐ˜์‚ฌํ•˜๋Š” ๊ฒƒ์ด๋ฏ€๋กœ, o.Emission์— ๋„ฃ์–ด์•ผํ•œ๋‹ค.

ch16

float2 sPos = float2(IN.screenPos.x, IN.screenPos.y) / IN.screenPos.w; float4 Depth = tex2D(_CameraDepthTexture, sPos);

Deferred rendering. - ์นด๋ฉ”๋ผ ๊นŠ์ด๋ฒ„ํผ ์‚ฌ์šฉ(ํฌ์›Œ๋“œ ๋ Œ๋”๋ง ์—ญ์‹œ ๊นŠ์ด๋ฒ„ํผ๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ์ง€๋งŒ...)

deferred rendering์—์„œ๋Š” ๋ฐ˜ํˆฌ๋ช…์„ ๋‹ค๋ฃจ๊ธฐ ํž˜๋“ค๋‹ค.

๊ทธ๋ฆผ์ž ์‰์ด๋”์™€ ์—ฐ๊ด€๋˜์–ด ์žˆ๋‹ค.

FallBack "Legacy Shaders/Transparent/VertexLit"

ํ’€ ๊ฐ™์€ ์ž์—ฐ๋ฌผ์€ ์ฃผ๋กœ AlphaTest(Cutout)์‰์ด๋”๋ฅผ ์‚ฌ์šฉ.

Opaque ์˜ค๋ธŒ์ ํŠธ๋Š” ๋จผ์ € ๊ทธ๋ฆฐ๋‹ค. Transparent ์˜ค๋ธŒ์ ํŠธ๋Š” ๋‚˜์ค‘์— ๊ทธ๋ฆฐ๋‹ค. ๋ฉ€๋ฆฌ ์žˆ๋Š” ๊ฒƒ๋ถ€ํ„ฐ ๊ฐ€๊นŒ์šด ๊ฒƒ๊นŒ์ง€ ์ฐจ๋ก€๋Œ€๋กœ - alpha shorting ์•ŒํŒŒ์†ŒํŒ…์„ ์จ๋ดค์ž, ์•ž๋’ค ํŒ์ •์„ ์ œ๋Œ€๋กœ ํ•  ์ˆ˜ ์—†์œผ๋‹ˆ, ๋ฌธ์ œ๋Š” ์ผ์–ด๋‚  ์ˆ˜ ๋ฐ–์— ์—†๋‹ค. ์•ŒํŒŒ๋ธ”๋ Œ๋”ฉ์„ ์‚ฌ์šฉํ•˜์˜€์„ ๋•Œ๋Š” zwrite๋ฅผ ํ•˜์ง€ ์•Š๋Š”๋‹ค. ์ด ๋ฌธ์ œ๋“ค์„ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ๊ฐ์ข… ๋ฐฉ๋ฒ•์ด ์—ฐ๊ตฌ๋˜๊ณ  ์žˆ๋‹ค.

๊ทธ๋ฆผ์ž๊ฐ€ ๋‚˜์˜ค๊ฒŒ ํ• ๋ ค๋ฉด

FallBack "Legacy Shaders/Transparent/Cutout/VertexLit"

https://docs.unity3d.com/Manual/SL-SurfaceShaders.html - Optional parameters

ch17

ch18

https://docs.unity3d.com/Manual/SL-Pass.html

ColorMask

  • 2pass ์•ŒํŒŒ๋ธ”๋žœ๋”ฉ

    • (Pass ํ‚ค์›Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ) Vertex/Fragment Shader๋Š” Multi-Pass๋กœ ํ•ฉ์น  ์ˆ˜ ์žˆ๋‹ค.
    • (Pass ํ‚ค์›Œ๋“œ๋Š” ์—†์ด) Surface Shader์™€ Surface Shader์˜ Multi-Pass๋„ ๊ฐ€๋Šฅํ•˜๋‹ค.
  • ํƒ€์ด๋ฐ ๋ฐ˜์ง์ž„

  • ํƒ€๋“ค์–ด๊ฐ€๋Š” ๊ธฐ๋Šฅ - dissolve

  • ํ”๋“ค๋ฆฌ๋Š” ํ’€ - vertex

  • matcap Mateiral

    • Material Capture
    • ViewDir๊ธฐ๋ฐ˜ ์นด๋ฉ”๋ผ๋ฅผ ํšŒ์ „ํ•˜์ง€ ์•Š๋Š” ์ƒํ™ฉ์—์„œ ์ข‹์€ ํšจ๊ณผ
  • ๊ตด์ ˆ - Refraction.

                GrabPass { }
                sampler2D _GrabTexture;
  • ๋ฌผ

    • Snell's law : ์ง๊ฐ์œผ๋กœ ๋‚ด๋ ค๋‹ค๋ณด๋Š” ๊ฐ๋„์— ๊ฐ€๊นŒ์›Œ์ง€๋ฉด ๋ฐ˜์‚ฌ๋ณด๋‹ค๋Š” ํˆฌ๋ช…ํ•จ์ด ๋” ๋งŽ์ด ๋ณด์ž„. ์‹œ์„ ๊ณผ ํ‰ํ–‰ํ•ด์ง€๋ฉด, ํˆฌ๊ณผ๋ณด๋‹ค๋Š” ๋ฐ˜์‚ฌ๊ฐ€ ๋งŽ์ด ์ผ์–ด๋‚จ
  • ๋ฌผ ํ”๋“ค๋ฆฌ๋Š”

  • ๋ฌผ ๊ตด์ ˆ

  • triplanar ํŠธ๋ผ์ด ํ”Œ๋ž˜๋„ˆ

ch19

LOD VertexLit = 100 Deval, Refective VertexLit = 150 Diffuse = 200 Diffuse Detail, Reflective Bumped Unlit, Reflective Bumped VertexLit = 250 Bumped, Specular = 300 Bumped Specular = 400 Parallax = 500 Parallax Specular = 600

"Queue" Background - 1000 Geometry - 2000 AlphaTest - 2500 Transparent - 3000 Overlay - 4000

[NoScaleOffset] [Normal] [Enum] [PowerSlider] [KeywordEnum] [Gamma]

interpolateview halfasview nofowardadd noambient novertexlights noshadow nolightmap

About

๐Ÿ“š๐ŸŒ”์ฑ…๊ณต๋ถ€. ์œ ๋‹ˆํ‹ฐ ์‰์ด๋” ์Šคํƒ€ํŠธ์—…

Topics

Resources

Stars

Watchers

Forks