https://github.com/netpyoung/bs.physically_based_shader_develop_for_unity
:books:๐์ฑ
๊ณต๋ถ. ์ ๋ํฐ ๋ฌผ๋ฆฌ ๊ธฐ๋ฐ ์
ฐ์ด๋ ๊ฐ๋ฐ
https://github.com/netpyoung/bs.physically_based_shader_develop_for_unity
bs shader urp
Last synced: about 1 month ago
JSON representation
:books:๐์ฑ ๊ณต๋ถ. ์ ๋ํฐ ๋ฌผ๋ฆฌ ๊ธฐ๋ฐ ์ ฐ์ด๋ ๊ฐ๋ฐ
- Host: GitHub
- URL: https://github.com/netpyoung/bs.physically_based_shader_develop_for_unity
- Owner: netpyoung
- Created: 2021-02-04T04:15:25.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-03-04T22:31:48.000Z (about 4 years ago)
- Last Synced: 2025-02-13T21:45:00.701Z (3 months ago)
- Topics: bs, shader, urp
- Language: ShaderLab
- Homepage:
- Size: 4.56 MB
- Stars: 6
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ์ ๋ํฐ ๋ฌผ๋ฆฌ ๊ธฐ๋ฐ ์์ด๋ ๊ฐ๋ฐ

- [๋ฒ์ญํ](http://www.acornpub.co.kr/book/physically-unity-shader)
- [source](https://github.com/Apress/physically-based-shader-dev-for-unity-2017)Legacy(Built-in)์์ด๋๋ก ์์ฑ๋์ด์๋๋ฐ, ์ด์ฐจํผ Legacy์ฌ์ฉ๋ฒ๋ ์ ๋ชจ๋ฅด๊ณ URP๋ก ๊ณง๋ฐ๋ก ์ฐ์ตํด ๋ณด๋๋ก ํ์.
## URP (Universal Render Pipeline)
- [Dev Weeks: URP ๊ธฐ๋ณธ ๊ตฌ์ฑ๊ณผ ํ๋ฆ](https://www.youtube.com/watch?v=QRlz4-pAtpY)
- [Dev Weeks: URP ์ ฐ์ด๋ ๋ฏ์ด๋ณด๊ธฐ](https://www.youtube.com/watch?v=9K1uOihvNyg)``` tree
Packages/
|-- Core RP Library/
| |-- ShaderLibrary/
| | |-- SpaceTransform.hlsl - ๊ณต๊ฐ๋ณํ ํ๋ ฌ. Tangent<->Worldํ๋ ฌ
| | |-- Common.hlsl - ๊ฐ์ข ์ํ. ํ ์ค์ณ ์ ํธ, ๋์ค ๊ณ์ฐ ..
| | |-- >>> EntityLighting.hlsl - SH, ProveVolume, Lightmap๊ณ์ฐ ???
| | |-- ImageBasedLighting - IBL๊ด๋ จ ๋ถ๋ถ(GGX, Anisotropy, ImportanceSample)
|-- Universal RP/
| |-- ShaderLibrary/
| | |-- Core.hlsl - ๋ฒํ ์ค ์ธํ ๊ตฌ์กฐ์ฒด, ์คํฌ๋ฆฐUV๊ณ์ฐ,Fog๊ณ์ฐ
| | |-- Lighting.hlsl - ๋ผ์ดํธ ๊ตฌ์กฐ์ฒด, diffuse, specular, GI
| | |-- Shadows.hlsl - ์๋์ฐ๋งต ์ํ๋ง, ์บ์ค์ผ์ด๋ ๊ณ์ฐ, ShadowCoord๊ณ์ฐ , Shadow Bias๊ณ์ฐ
| |-- Shaders/
```## 1์ฅ. ์ ฐ์ด๋ ๊ฐ๋ฐ ๊ณผ์
### Forward
``` ruby
for object in objects
for light in lights
FrameBuffer = LightModel(object, light);
end
endfor light in lights
for object in GetObjectsAffectedByLight(light)
FrameBuffer += LightModel(object, light);
end
end
```
๋ผ์ดํธ ๊ฐฏ์ ์ฆ๊ฐ> ์ฐ์ฐ๋ ์ฆ๊ฐ
### Deferred
``` ruby
for object in objects:
GBuffer = GetLightingProperties(object)
endfor light in lights
Framebuffer += LightModel(GBuffer, light)
end
```
- ๋ฐํฌ๋ช ๋ถ๊ฐ
- URP - ํ์ฌ(10.3.1) deferred ์ง์ ์ํจ.
- [URP ๋ก๋๋งต](https://portal.productboard.com/8ufdwj59ehtmsvxenjumxo82/tabs/3-universal-render-pipeline)
- [๋ธ๋ผ์ธ๋ ๋ ๋๋ฌ - ์๋ก์ด ๊ธฐ๋ฒ != ์ ์ฅ๋๊ฐ](https://kblog.popekim.com/2012/02/blog-post.html)## 2์ฅ. ์ฒซ ์ ๋ํฐ ์ ฐ์ด๋
- [Built-in vs URP](https://docs.unity3d.com/Packages/[email protected]/manual/universalrp-builtin-feature-comparison.html)
``` txt
Create> Rendering> Universal Render Pipeline> Pipeline Asset(Forward Renderer)Assets/
|-- UniversalRenderPipelineAsset.asset
|-- UniversalRenderPipelineAsset_Renderer.assetProject Settings> Graphics> Scriptable Render Pipeline Settings> UniversalRenderPipelineAsset.asset
UniversalRenderPipelineAsset.asset> Quality> HDR check
Project Settings> Player> Other Settings> Color Space> Linear
```- [URP unlit basic shader](https://docs.unity3d.com/Packages/[email protected]/manual/writing-shaders-urp-basic-unlit-structure.html)
``` hlsl
Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" }
Tags { "LightMode" = "SRPDefaultUnlit" } // ๋ผ์ดํธ ๋ชจ๋ ํ๊ทธ ๊ธฐ๋ณธ๊ฐ
```- [URP ShaderLab Pass tags](https://docs.unity3d.com/Packages/[email protected]/manual/urp-shaders/urp-shaderlab-pass-tags.html)
| LightMode | URP Support |
|----------------------|-------------|
| UniversalForward | O |
| UniversalGBuffer | O |
| UniversalForwardOnly | O |
| Universal2D | O |
| ShadowCaster | O |
| DepthOnly | O |
| Meta | O |
| SRPDefaultUnlit | O(๊ธฐ๋ณธ๊ฐ) |
| Always | X |
| ForwardAdd | X |
| PrepassBase | X |
| PrepassFinal | X |
| Vertex | X |
| VertexLMRGBM | X |
| VertexLM | X |## 3์ฅ. ๊ทธ๋ํฝ์ค ํ์ดํ๋ผ์ธ
``` cs
// #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
// |-- #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"// Core RP Library/ShaderLibrary/SpaceTransforms.hlsl
// UNITY_MATRIX_M * (UNITY_MATRIX_VP * positionOS)
float4 TransformObjectToHClip(float3 positionOS)
{
// More efficient than computing M*VP matrix product
return mul(GetWorldToHClipMatrix(), mul(GetObjectToWorldMatrix(), float4(positionOS, 1.0)));
}
```## 4์ฅ. ์ขํ ๊ณต๊ฐ ๋ณํ
| Space | |
|-------|------------------------|
| WS | world space |
| VS | view space |
| OS | object space |
| CS | Homogenous clip spaces |
| TS | tangent space |
| TXS | texture space || built-in(legacy) | URP |
|--------------------------|------------------------------|
| UnityObjectToWorldDir | TransformObjectToWorldDir |
| UnityObjectToWorldNormal | TransformObjectToWorldNormal |
| UnityWorldSpaceViewDir | TransformWorldToViewDir |
| UnityWorldSpaceLightDir | x |``` hlsl
float4x4 GetObjectToWorldMatrix() UNITY_MATRIX_M;
float4x4 GetWorldToObjectMatrix() UNITY_MATRIX_I_M;
float4x4 GetWorldToViewMatrix() UNITY_MATRIX_V;
float4x4 GetWorldToHClipMatrix() UNITY_MATRIX_VP;
float4x4 GetViewToHClipMatrix() UNITY_MATRIX_P;
```| built-in(legacy) | URP |
|----------------------|------------------------|
| UnityObjectToClipPos | TransformObjectToHClip |
| UnityWorldToClipPos | TransformWorldToHClip |
| UnityViewToClipPos | TransformWViewToHClip |-
-## 5์ฅ. ์ต์ด ๋ผ์ดํ ์ ฐ์ด๋
``` hlsl
// #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
struct Light
{
half3 direction;
half3 color;
half distanceAttenuation;
half shadowAttenuation;
};Light GetMainLight()
light.direction = _MainLightPosition.xyz;Light GetMainLight(float4 shadowCoord)
// #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Macros.hlsl"
#define TRANSFORM_TEX(tex, name) ((tex.xy) * name##_ST.xy + name##_ST.zw)// #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/API/D3D11.hlsl"
#define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2)
```- [URP - Drawing a texture](https://docs.unity3d.com/Packages/[email protected]/manual/writing-shaders-urp-unlit-texture.html)
## 6์ฅ. ์คํํ๋ฌ ๊ตฌํ
- TODO ๋ ๋ง์ ๊ด์ ์ง์ํ๊ธฐ(2 Directional Light)
-## 7์ฅ. ์ํผ์ค ์ ฐ์ด๋
- Surface๋ URP์์ ์์ธ๊บผ๋ผ์ Vert/Frag๋ก ๊ตฌํ
- 2๊ฐ Albedo๋ฅผ lerp์ํค๋๊ฒ.
- NormapMap์ ์ฉ.## 8์ฅ. ๋ฌผ๋ฆฌ ๊ธฐ๋ฐ ์ ฐ์ด๋ฉ์ด๋?
- ๋น์ ์ธก์ ํ๋ ๋ฐฉ๋ฒ
| | ๋จ์ | ์ค๋ช |
|-----------------------|--------------------|--------------------------------------------------|
| ์ ์ฒด๊ฐ Solid Angle | sr(steradian) | ๋จ์ ๊ตฌ๋ก ์ด๋ ํ ํ์์ ์ฌ์ํ ๊ฒ. |
| ํ์ Power | W | ์ฌ๋ฌ ๋ฐฉํฅ์์ ํ๋ฉด์ ํต๊ณผํด ์ ๋ฌ๋๋ ์๋์ง ํฌ๊ธฐ |
| ์ผ๋ ๋์์ค Irradiance | E (W/m^2) | ๋ชจ๋ ๊ด์ ์์ ์ ์ ์ ๋ฌ๋๋ ๋น์ ํฌ๊ธฐ |
| ๋ ๋์์ค Radiance | L_0 (W/(m^2 * sr)) | ํ๋์ ๊ด์ ์์ ์ ์ ์ ๋ฌ๋๋ ๋น์ ํฌ๊ธฐ |- ์ฌ์ง์ ํํํ๋ ๋ฐฉ๋ฒ
์๋ฐฉํฅ ๋ฐ์ฌ ๋ถํฌ ํจ์ BRDF Bidirectional Reflectance Distribution Function
๋น์ด ํ๋ฉด์์ ์ด๋ป๊ฒ ๋ฐ์ฌ๋ ์ง์ ๋ํด ์ ์ํ ํจ์.| BRDF ์์ฑ | |
|------------------------|----------------------------------------------------------------------------------------------|
| positivity | BRDF๊ฐ์ 0์ด์์ด๋ค |
| symmetry (reciprocity) | ๋น์ด ๋ค์ด์ค๋ ๋ฐฉํฅ๊ณผ ๋ฐ์ฌ๋๋ ๋ฐฉํฅ์ ๊ฐ์ ๋์ผํ๋ค |
| conservation of energy | ๋๊ฐ๋ ๋น์ ์์ ๋ค์ด์ค๋ ๋น์ ์์ ๋์ด์ค ์ ์๋ค(๋ฌผ์ฒด๊ฐ ์์ฒด์ ์ผ๋ก ๋น์ ๋ฐ์ฐํ์ง ์๋๋ค๋ฉด) |## 9์ฅ. ๋ฌผ๋ฆฌ ๊ธฐ๋ฐ ์ ฐ์ด๋ ์ ์ํ๊ธฐ
``` hlsl
half3 LightingPhong(half3 lightColor, half3 lightDir, half3 normal, half3 viewDir, half4 specularColor, half3 albedo, half shininess)
{
half NdotL = saturate(dot(normal, lightDir));
half3 diffuseTerm = NdotL * albedo * lightColor;half3 reflectionDirection = reflect(-lightDir, normal);
half3 specularDot = max(0.0, dot(viewDir, reflectionDirection));
half3 specular = pow(specularDot, shininess);
half3 specularTerm = specularColor.rgb * specular * lightColor;return diffuseTerm + specularTerm;
}// Lafortune and Willems (1994)
half3 LightingPhongModified(half3 lightColor, half3 lightDir, half3 normal, half3 viewDir, half4 specularColor, half3 albedo, half shininess)
{
half NdotL = saturate(dot(normal, lightDir));
half3 diffuseTerm = NdotL * albedo * lightColor;half norm = (shininess + 2) / (2 * PI);
half3 reflectionDirection = reflect(-lightDir, normal);
half3 specularDot = max(0.0, dot(viewDir, reflectionDirection));half3 specular = norm * pow(specularDot, shininess);
half3 specularTerm = specularColor.rgb * specular * lightColor;
return diffuseTerm + specularTerm;
}
```## 10์ฅ. ํ์ฒ๋ฆฌ ํจ๊ณผ
``` hlsl
// com.unity.render-pipelines.core/ShaderLibrary/API/D3D11.hlsl
#define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2)
#define SAMPLE_DEPTH_TEXTURE(textureName, samplerName, coord2) SAMPLE_TEXTURE2D(textureName, samplerName, coord2).r
`````` hlsl
// com.unity.render-pipelines.core/ShaderLibrary/API/Common.hlsl
// Z buffer to linear 0..1 depth (0 at near plane, 1 at far plane).
// Does NOT correctly handle oblique view frustums.
// Does NOT work with orthographic projection.
// zBufferParam = { (f-n)/n, 1, (f-n)/n*f, 1/f }
float Linear01DepthFromNear(float depth, float4 zBufferParam)
{
return 1.0 / (zBufferParam.x + zBufferParam.y / depth);
}// Z buffer to linear 0..1 depth (0 at camera position, 1 at far plane).
// Does NOT work with orthographic projections.
// Does NOT correctly handle oblique view frustums.
// zBufferParam = { (f-n)/n, 1, (f-n)/n*f, 1/f }
float Linear01Depth(float depth, float4 zBufferParam)
{
return 1.0 / (zBufferParam.x * depth + zBufferParam.y);
}// Z buffer to linear depth.
// Does NOT correctly handle oblique view frustums.
// Does NOT work with orthographic projection.
// zBufferParam = { (f-n)/n, 1, (f-n)/n*f, 1/f }
float LinearEyeDepth(float depth, float4 zBufferParam)
{
return 1.0 / (zBufferParam.z * depth + zBufferParam.w);
}// Z buffer to linear depth.
// Correctly handles oblique view frustums.
// Does NOT work with orthographic projection.
// Ref: An Efficient Depth Linearization Method for Oblique View Frustums, Eq. 6.
float LinearEyeDepth(float2 positionNDC, float deviceDepth, float4 invProjParam)
{
float4 positionCS = float4(positionNDC * 2.0 - 1.0, deviceDepth, 1.0);
float viewSpaceZ = rcp(dot(positionCS, invProjParam));// If the matrix is right-handed, we have to flip the Z axis to get a positive value.
return abs(viewSpaceZ);
}// Z buffer to linear depth.
// Works in all cases.
// Typically, this is the cheapest variant, provided you've already computed 'positionWS'.
// Assumes that the 'positionWS' is in front of the camera.
float LinearEyeDepth(float3 positionWS, float4x4 viewMatrix)
{
float viewSpaceZ = mul(viewMatrix, float4(positionWS, 1.0)).z;// If the matrix is right-handed, we have to flip the Z axis to get a positive value.
return abs(viewSpaceZ);
}
```| | Built-in | URP |
|--------|---------------|-----------------------|
| Camera | Camera: | RenderPipelineManager |
| | OnPreCull | beginFrameRendering |
| | OnPreRender | beginCameraRendering |
| | OnPostRender | endCameraRendering |
| | OnRenderImage | endFrameRendering |`Create> Rendering> Universal Render Pipeline> Renderer Feature`
| | ์๋ ์์ฑ๋จ | |
|----------------------------|-------------|-----------------------------------|
| _CameraDepthTexture | O | Pipeline Settings> Depth Texture |
| _CameraOpaqueTexture | O | Pipeline Settings> Opaque Texture |
| _CameraColorTexture | ?? | |
| _CameraDepthNormalsTexture | X | |-
``` txt
- Camera> Rendering> Post-Processing ์ฒดํฌ
- Hierachy> Volume> Global Volume
- Global Volume> Volume> Profile> New
- Global Volume> Volume> Add Override
```## 11์ฅ. BRDF ๋๊ฐ ๋๊ตฌ์ธ๊ฐ?
-
-
-
- [[ ๋ฒ์ญ ] Physically-Based Shading at Disney](https://lifeisforu.tistory.com/350)
| ๊ธฐํธ | ์ค๋ช |
|------|-----------------------------------|
| N | ๋ ธ๋ง |
| H | ํํ๋ฒกํฐ `H = normalize( L + V )` |
| L | ๋ผ์ดํธ(๊ด์) |
| V | ๋ทฐ(์นด๋ฉ๋ผ) |
| T | ํ์ ํธ |
| ฮ | (Theta) ๋ฐฉ์๊ฐ |
| ฮฆ | (Phi) ์๊ฐ(์ฌ๋ ค๋ณธ๊ฐ) |### BRDF ์ข ๋ฅ
#### Ashikhmin Shirley ์ดํฌ๋จผ ์ ๋ฆฌ
2000 - Michael Ashikhmin & Peter Shirley - An Anisotropic Phong BRDF Model
ํ ์คํํ๋ฌ
#### Cook Torrance ์ฟกํ ๋ ์ค
1982 - Robert L.Cook & Kenneth E. Torrance - A Reflectance Model For Computer Graphics
๋ฏธ์ธ๋ฉด์ด๋ก
#### Oren Nayar ์ค๋ ๋ค์ด์ด
1994 - Michael Oren & Shree K. Nayar - Generalization of Lambertโs Reflectance Model
๋ํจ์ฆ ์ ์ฉ
#### Ward ์๋
1992 - Gregory J. Ward - Measuring and modeling anisotropic reflection
๊ฒฝํ์ ๋ฐ์ดํฐ ๊ธฐ๋ฐ, ๊ฑฐ์ ์ฌ์ฉ๋์ง ์์.
#### Disney ๋์ฆ๋
SIGGRAPH 2012 - Brent Burley - Physically Based Shading at Disney
์ฌ๋ฌ ํ๋ผ๋ฏธํฐ
## 12์ฅ. BRDF ๊ตฌํํ๊ธฐ
- ์ฐธ๊ณ
- [[NDC19] ๋ชจ๋ฐ์ผ์์ ์ฌ์ฉ๊ฐ๋ฅํ ์ ๋ํฐ ์ปค์คํ ์ญ์คํด์ค PBR ์ ฐ์ด๋ ๋ง๋ค๊ธฐ](https://www.slideshare.net/dongminpark71/ndc19-pbr-143928930)### ๋ ํผ๋ฐ์ค BRDF
#### Cook Torrance ๋ ํผ๋ฐ์ค
| | |
|--------------------------------------------------------------------------------------|--------------------------------------------------------------------|
| Physics and Math of Shading by Naty Hoffman | SIGGRAPH every year from 2012 to 2015 |
| Real Shading in Unreal Engine 4 by Brian Karis | SIGGRAPH, 2013 |
| BRDF Explorer (GLSL) - CookTorrance BRDF | |
| Specular BRDF Reference on Brian Karisโ blog | |
| Introduction to BRDF Models by Daniรซl Jimenez Kwast | |
| A Reflectance Model for Computer Graphics from 1981 | |
| Understanding the Masking-Shadowing Function in Microfacet-Based BRDFs by Eric Heitz | SIGGRAPH, 2014 - ๋ฏธ์ธ๋ฉด์ดํด ์ถ์ฒ |
| Microfacet Models for Refraction through Rough Surfaces | EGSR, 2017 |#### Disney ๋ ํผ๋ฐ์ค
| | |
|---------------------------------------------------------------------------|------------------------------------------------------------------------------------|
| Physically Based Shading at Disney | SIGGRAPH, 2012, by Brent Burley |
| BRDF Explorer (GLSL) - Disney BRDF | |
| Extending the Disney BRDF to a BSDF with Integrated Subsurface Scattering | SIGGRAPH, 2015, by Brent Burley |
| Moving Frostbite to Physically Based Rendering | SIGGRAPH, 2015, by Sรฉbastien Lagarde and Charlesde Rousiers (only for the Diffuse) |### ์ด๋ก BRDF
#### Cook Torrance ์ด๋ก
๋ฏธ์ธ๋ฉด ์ด๋ก
| | | | ๊ด์ฌ ๋ฒกํฐ | | |
|---|--------------------------------|--------------|-----------|-------|-------------------------------------------------------------------|
| D | Normal `Distribution` Function | ์ ๊ท๋ถํฌํจ์ | (H) | ์์ | ํฌ๊ธฐ, ๋ฐ๊ธฐ, ์คํํ๋ฌ ๋ชจ์ |
| F | Fresnel | ํ๋ ๋ฌ | (L, H) | 0 ~ 1 | ๋ณด๋ ๊ฐ๋์ ๋ฐ๋ฅธ ๋ฐ์ฌ์จ๊ณผ ๊ตด์ ์จ |
| G | Geometry | ๊ธฐํํจ์ | (L, V, H) | | ๋ฉด์ด ์๋ก ๊ฒน์ณ์ ๋น์ ์ฐจ๋จํ๋ ์ ๋์ ๊ทผ์ฌ์น๋ฅผ ํต๊ณ์ ์ผ๋ก ๊ตฌํ๋ค. |- NDF (Normal `Distribution` Function)
- Beckmann
- Phong
- GGX์ฑ ์ ๊ตฌํ์์๋
| | |
|---|----------------------|
| D | Trowbridge-Reitz GGX |
| F | Fresnel-Schlick |
| G | Smith's Schlick-GGX |#### Disney ์ด๋ก
### ๊ตฌํ BRDF
#### Cook Torrance ๊ตฌํ
#### Disney ๊ตฌํ
## 13์ฅ. ํ์ค ์ ฐ์ด๋ ํํน
- 16์ฅ. ๋ณต์ก๋์ ์ฐ๋ฒ์ ฐ์ด๋ ์ฐธ์กฐ.
``` hlsl
// com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlslstruct BRDFData
{
half3 albedo;
half3 diffuse;
half3 specular;
half reflectivity;
half perceptualRoughness;
half roughness;
half roughness2;
half grazingTerm;// We save some light invariant BRDF terms so we don't have to recompute
// them in the light loop. Take a look at DirectBRDF function for detailed explaination.
half normalizationTerm; // roughness * 4.0 + 2.0
half roughness2MinusOne; // roughness^2 - 1.0
};
```- [Custom Shader GUI](https://docs.unity3d.com/2021.1/Documentation/Manual/SL-CustomShaderGUI.html)
- [ShaderGUI: Custom Material Inspectors in Unity 5+](https://www.alanzucconi.com/2016/11/07/shadergui-custom-material-inspectors-unity-5/)## 14์ฅ. ๊ณ ๊ธ ๊ธฐ์ ๊ตฌํ
### ๋ฐํฌ๋ช (Translucency)
๋ฐํฌ๋ช ์ BRDF๋ก ์ฒ๋ฆฌํ๊ธฐ ๊ณค๋.
| | | |
|------|---------------------------------------------------|------------------------------------------------|
| BRDF | Bidirectional reflectance distribution function | ๋ ๋น์ด ์ด๋ค ๋ฐฉํฅ์ผ๋ก ๋ฐ์ฌ๊ฐ ๋๋์ง |
| BTDF | Bidirectional transmittance distribution function | ๋ ๋น์ด ์ด๋ค ๋ฐฉํฅ์ผ๋ก ํฌ๊ณผ๊ฐ ๋๋์ง |
| BSDF | Bidirectional scattering distribution function | ์ด ๋์ ํฉ์ณ ๋น์ด ์ฌ์ง๊ณผ ์ด๋ป๊ฒ ์ํธ์์ฉํ๋์ง |- TODO ์์ ์์ 2๊ฐ์ Directional Light์ฌ์ฉ...
``` hlsl
// ref: GPG Pro 2//Translucency
// - ๋ ธ๋ง๊ณผ ๋ผ์ดํธ์ ํํ์ ์ญ๋ฐฉํฅ์ (๋ฌผ์ฒด ๋ท๋ถ๋ถ)
// - ๋ทฐ๋ฅผ ๋ท์ฐ์ฐ์ผ๋ก ๋ฌถ์ด์ค๋ค. (ํ์ฐํจ๊ณผ)float thickness = SAMPLE_TEXTURE2D(_Thickness, sampler_Thickness, IN.uv).r;
float3 translucencyLightDir = L + N * _Distortion;
float translucencyDot = pow(saturate(dot(V, -translucencyLightDir)), _Power) * _Scale;
float3 translucency = translucencyDot * thickness * _SubsurfaceColor.rgb;
diffuse += translucency;
```### IBL
-
| Cubemap์์ฑ ๋๊ตฌ | |
|----------------------------------------------------------|-------------|
| [cmftStudio](https://github.com/dariomanesku/cmftStudio) | BSD 2 |
| [Knald's Lys](https://www.knaldtech.com/lys/) | Commercial |
| [IBLBaker](https://github.com/derkreature/IBLBaker) | MIT License |
| [CubeMapGen](https://gpuopen.com/archived/cubemapgen/) | old |## 15์ฅ. ์ํฐ์คํธ๊ฐ ์ฌ์ฉํ ์ ฐ์ด๋ ์ ์
์ํฐ์คํธ๊ฐ ์กฐ์ํ๊ธฐ ํธํ๊ฒ
1. ์ ์ ํ ์ ํ ๊ฐฏ์
2. ์ ์ ํ ์ ํ ๋ค์ด๋ฐ
3. ์ํธ ์์ฉํ๋ ์ ํ ๊ฐ์ ์ํ ๋ฌธ์ํ
4. ํ ์ค์ณ์ ์ฌ๋ฌ ์ ๋ณด(albedo + specular๋ฑ)์ ๋ฃ๋ ๊ฒฝ์ฐ๊ฐ ๋ง์๋ฐ, ๋ช ํํ๊ฒ ์ ํ ๊ฐ๊ณผ ์ ํ ๋ค์ด๋ฐ์ ํ์
5. ์ฌ๋ฌ ๋ฒ์ ํผํฉ์ฌ์ฉ ํผํ๊ธฐ(๋๋๋ก์ด๋ฉด `0 ~ 1`๋ก...)ํ๋ผ๋ฏธํฐ ๋ณํ๊ฐ ๋ณ๋ก ์์ ์ฌ ์์ผ๋ฉด ์ข๊ฒ ๋ค..
## 16์ฅ. ๋ณต์ก๋์ ์ฐ๋ฒ์ ฐ์ด๋
์์ด๋ ํ๋๋ฅผ ์ด์ฉํด์ ์ฌ๋ฌ๊ฐ์ง ๊ฒฝ์ฐ๋ฅผ ์ฒ๋ฆฌํ๊ณ ์ถ์ ๊ฒฝ์ฐ, ํ์ํ ๋ชจ๋ ์ฝ๋๋ฅผ ์์ด๋ ํ๋์ ์ง์ด๋ฃ๊ฒ๋๋ฉด ๊ทธ๊ฒ ๋ฐ๋ก ์ฐ๋ฒ์ ฐ์ด๋.
- `if`์ ๊ฐ์ ๋์ ๋ถ๊ธฐ๋ ์ฑ๋ฅ์ ํ.
- `#if`์ ๊ฐ์ด ์ ์ฒ๋ฆฌ๊ธฐ๋ฅผ ์ด์ฉํ, ์ ์ ๋ถ๊ธฐ๋ฅผ ์ด์ฉํ์ฌ ์ฒ๋ฆฌํ๋ค.์ ๋ํฐ์์๋ ํค์๋๋ฅผ ์ด์ฉ ์์ด๋ ์กฐํฉ์ ํธ๋ฆฌํ๊ฒ ํด์ฃผ๋ ๊ธฐ๋ฅ์ด ์์.
- [Shader variants and keywords](https://docs.unity3d.com/2021.1/Documentation/Manual/SL-MultipleProgramVariants.html)
- ์ด 256๊ฐ์ ๊ธ๋ก๋ฒ ํค์๋.
- 64๊ฐ์ ๋ก์ปฌ ํค์๋.- `#pragma shader_feature KEYWORD`
- `#pragma multi_compile KEYWORD`| | ๊ฒ์๋น๋์ ํฌํจ |
|----------------|---------------------|
| shader_feature | ์ฌ์ฉ๋๋ ๊ฒ๋ง |
| multi_compile | ์กฐํฉ ๊ฐ๋ฅํ ๋ชจ๋ ๊ฒ |``` txt
#pragma multi_compile A B C
#pragma multi_compile D E์กฐํฉํด์ ๋์ฌ ์ ์๋ ์ด ๊ฐฏ์: 6๊ฐ
A+D, B+D, C+D
A+E, B+E, C+E
`````` hlsl
[KeywordEnum(Off, On)] _UseNormal("Use Normal Map", Float) = 0
#pragma shader_feature _USENORMAL_OFF _USENORMAL_ON
#if _USENORMAL_ON
#endif[Toggle] _ModifiedMode("Modified?", Float) = 0
#pragma shader_feature _MODIFIEDMODE_OFF _MODIFIEDMODE_ON
#if _MODIFIEDMODE_ON
#endif
```## 17์ฅ. ์ ฐ์ด๋๊ฐ ์ ์์๋ํ์ง ์์ ๋
### ์ผ๋ฐ์ ํธ๋ฆญ
- shader๋ก ๋ ธ๋ง๊ฐ ์๊ฐํ
``` hlsl
struct Attributes
{
float4 positionOS : POSITION;
float3 normalOS : NORMAL;
float4 tangent : TANGENT;
float2 uv : TEXCOORD0;
};struct Varyings
{
float4 positionHCS : SV_POSITION;
float2 uv : TEXCOORD0;float3 T : TEXCOORD1;
float3 B : TEXCOORD2;
float3 N : TEXCOORD3;float3 positionWS : TEXCOORD4;
};// ----------
inline void ExtractTBN(in half3 normalOS, in float4 tangent, inout half3 T, inout half3 B, inout half3 N)
{
N = TransformObjectToWorldNormal(normalOS);
T = TransformObjectToWorldDir(tangent.xyz);
B = cross(N, T) * tangent.w * unity_WorldTransformParams.w;
}inline half3 CombineTBN(in half3 tangentNormal, in half3 T, in half3 B, in half3 N)
{
return mul(tangentNormal, float3x3(normalize(T), normalize(B), normalize(N)));
}Varyings vert(Attributes IN)
{
//Varyings OUT;
Varyings OUT = (Varyings)0;;
OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz);
OUT.uv = TRANSFORM_TEX(IN.uv, _BumpMap);ExtractTBN(IN.normalOS, IN.tangent, OUT.T, OUT.B, OUT.N);
OUT.positionWS = TransformObjectToWorld(IN.positionOS.xyz);
return OUT;
}// ---------------
half4 frag(Varyings IN) : SV_Target
{
#if _ENABLENORMALMAP_ON
float3 tangentNormal = UnpackNormal(SAMPLE_TEXTURE2D(_BumpMap, sampler_BumpMap, IN.uv));
tangentNormal.xy *= _BumpMapStrength; // BumpMap Strength.float3 N = CombineTBN(tangentNormal, IN.T, IN.B, IN.N);
#else
float3 N = normalize(IN.N);
#endif
return half4(N * 0.5 + 0.5, 1);
}
```### ๋๋ฒ๊น ๋๊ตฌ
- Window> Analysis> Frame Debugger
- RenderDoc ํ๋ก๊ทธ๋จ
-### ํ๋กํ์ผ๋ง
| | |
|---------------------------------|--|
| ๋ฐฐ์น ์ | |
| ๋๋ก์ฐ์ฝ | |
| SetPass | |
| Vertex | |
| ํ ์ค์ณ ๊ฐฏ์/๋ฉ๋ชจ๋ฆฌ /์ค์์น ํ์ | |
| Shadow Casters | |
| Vertex Buffer Object | |- CPU์ ์น์ค? GPU์ ์น์ค?
- Static GameObject ํ์ฉ ์ํ๊ธฐ.## 18์ฅ. ์ต์ ํธ๋ ๋ ๋ฐ๋ผ์ก๊ธฐ
### ์ปจํผ๋ฐ์ค
| | |
|-----------------|------------------------------|
| GDC | GDC Vault ๊ตฌ๋ 1๋ 400๋ถ์ ๋ |
| Siggraph | 1๋ 45๋ฌ๋ฌ |
| Unite | |
| Digital Dragons | ์์์๋ฃ ๊ณต๊ฐ |
| Eurographics | ํ์ ์์ฃผ |### ์์
์ด๋ ต์ง๋ง ๊ตฌ์ ํด์ ์ฝ์ด๋ณผ ๊ฐ์น ์์.
| | |
|----------|--|
| GPU Gems | |
| ShaderX | |
| GPU PRO | |
| GPU Zen | |### ์ฌ์ดํธ
-
-
-
-
-
-
-
-
-
-
-
-
-## etc
- [Microfacet BRDF](http://www.pbr-book.org/3ed-2018/Reflection_Models/Microfacet_Models.html#)
-