본문으로 바로가기

Unity compiler directives

category Technical Report/Unity Shader 2017. 6. 27. 16:56
반응형


Unity Surface Shader compiler directives

유니티 서피스 셰이더 컴파일러 지시문


링크 : https://docs.unity3d.com/Manual/SL-SurfaceShaders.html




Required parameters


surfaceFunction - which Cg function has surface shader code. The function should have the form of void surf (Input IN, inout SurfaceOutput o), where Input is a structure you have defined. Input should contain any texture coordinates and extra automatic variables needed by surface function.


Cg 함수에 Surface shader 코드 선언. 이 함수는 void surf (Input IN, inout SurfaceOutput o) 형식이어야 함. 여기서 Input은 사용자가 정의한 구조라는 의미. 보통 surface surf를 사용


lightModel - lighting model to use. Built-in ones are physically based Standard and StandardSpecular, as well as simple non-physically based Lambert (diffuse) and BlinnPhong (specular). See Custom Lighting Models page for how to write your own.


사용할 조명 선언. 미리 선언된 Lambert, Standard, BlinnPhong을 사용할때에는 선언만 하면 되나 Custom lighting을 사용할 경우는 조명 설계에 LightingCustom으로 사용된다. 자세한건 Custom Lighting 항목 참조


Standard lighting model uses SurfaceOutputStandard output struct, and matches the Standard (metallic workflow) shader in Unity.

StandardSpecular lighting model uses SurfaceOutputStandardSpecular output struct, and matches the Standard (specular setup) shader in Unity.

Lambert and BlinnPhong lighting models are not physically based (coming from Unity 4.x), but the shaders using them can be faster to render on low-end hardware.



Optional parameters


Transparency and alpha testing is controlled by alpha and alphatest directives. Transparency can typically be of two kinds: traditional alpha blending (used for fading objects out) or more physically plausible “premultiplied blending” (which allows semitransparent surfaces to retain proper specular reflections). Enabling semitransparency makes the generated surface shader code contain blending commands; whereas enabling alpha cutout will do a fragment discard in the generated pixel shader, based on the given variable.


투명도와 알파 테스트 : 알파 및 알파 태스트 (alphaatest) 지시어로 제어됩니다. 알파 블렌딩과 알파컷(alphacut : 알파테스트)로 제어된다. 자세한 항목은 아래 참조.


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:blend - Enable alpha blending. 알파 블렌드 허용


• alpha:fade - Enable traditional fade-transparency. 기존의 알파 투명도 허용


• alpha:premul - Enable premultiplied alpha transparency. 미리 곱해진 알파 투명도 허용

• alphatest:VariableName - Enable alpha cutout transparency. Cutoff value is in a float variable with VariableName. You’ll likely also want to use addshadow directive to generate proper shadow caster pass.

알파 컷 아웃 투명을 사용. 컷오프 값은 VariableName이있는 float 변수로 사용. 적절한 쉐도우 캐스팅 패스를 생성하기 위해 addshadow 지시어를 사용할 수도 있음.

 ex) property

     _Cutoff("Alpha blend", Range(0,1)) = 0.5

     compiler

     alphatest:_Cutoff,


• keepalpha - By default opaque surface shaders write 1.0 (white) into alpha channel, no matter what’s output in the Alpha of output struct or what’s returned by the lighting function. Using this option allows keeping lighting function’s alpha value even for opaque surface shaders.

기본적으로 불투명 서피스 쉐이더는 출력 구조체의 알파 또는 조명 함수에 의해 반환되는 것에 상관없이 1.0 (흰색)을 알파 채널에 사용한다. 이 옵션을 사용하면 불투명 한 표면 쉐이더에서도 조명 함수의 알파 값을 유지할 수 있다.


• decal:add - Additive decal shader (e.g. terrain AddPass). This is meant for objects that lie atop of other surfaces, and use additive blending. See Surface Shader Examples

추가 데칼 쉐이더 (예 : 지형 AddPass). additive blending을 사용


• decal:blend - Semitransparent decal shader. This is meant for objects that lie atop of other surfaces, and use alpha blending. See Surface Shader Examples

반투명 데칼 쉐이더. 이것은 메쉬 표면에 놓여있고 알파 블렌딩을 사용하는 개체를 의미



Custom modifier functions can be used to alter or compute incoming vertex data, or to alter final computed fragment color.

사용자 정의 수정 함수는 입력된 정점 데이터를 변경, 계산하거나 최종 계산 된 정점의 색상을 변경하는 데 사용


• vertex:VertexFunction - Custom vertex modification function. This function is invoked at start of generated vertex shader, and can modify or compute per-vertex data. See Surface Shader Examples.

생성된 버텍스가 시작될때 호출되며 버텍스별 데이터를 수정하거나 계산하는데 쓰임


• finalcolor:ColorFunction - Custom final color modification function. See Surface Shader Examples.

사용자에 의해 정의된 최종 정점 색상 수정


• finalgbuffer:ColorFunction - Custom deferred path for altering gbuffer content.

gbuffer 내용을 변경하기위한 사용자 정의 지연 경로.


• finalprepass:ColorFunction - Custom prepass base path.

사용자 정의 기본패스



Shadows and Tessellation - additional directives can be given to control how shadows and tessellation is handled.

그림자와 테셀레이션 관련 항목


• addshadow - Generate a shadow caster pass. Commonly used with custom vertex modification, so that shadow casting also gets any procedural vertex animation. Often shaders don’t need any special shadows handling, as they can just use shadow caster pass from their fallback.

그림자 캐스터 패스를 생성. 일반적으로 커스텀 버텍스 수정과 함께 사용되므로 쉐도우 캐스팅은 프로 시저 버텍스 애니메이션을 가져올때 사용. 보통 그림자 처리는 fallback에서 선언되는걸로 사용하므로 특별한 경우에만 사용


• fullforwardshadows - Support all light shadow types in Forward rendering path. By default shaders only support shadows from one directional light in forward rendering (to save on internal shader variant count). If you need point or spot light shadows in forward rendering, use this directive.

포워드 렌더링 패스에서 모든 광원 유형을 지원. 기본적으로 쉐이더는 (Quality setting의 count 수에 저장된 숫자만큼) 포워드 렌디링에서 하나의 디렉셔널 라이트의 그림자만 지원. 포인트 혹은 스팟 라이트 사용시에 사용


• tessellate:TessFunction - DX11 기반의 테셀레이션을 사용할때 사용. 자세한건 테셀관련 문서 참조



Code generation options - by default generated surface shader code tries to handle all possible lighting/shadowing/lightmap scenarios. However in some cases you know you won’t need some of them, and it is possible to adjust generated code to skip them. This can result in smaller shaders that are faster to load.

코드 생성 옵션 - 기본적으로 생성된 surface shader 코드는 가능한 모든 조명/셰도우/라이트맵 환경에서 처리하기 위해 variants를 생성하게 됨. 그중 일부를 제한하기 위한 용도를 위해 사용하는 컴파일러 명령어.


• exclude_path:deferred, exclude_path:forward, exclude_path:prepass - Do not generate passes for given rendering path (Deferred Shading, Forward and Legacy Deferred respectively).

주어진 렌더링 경로(디퍼드, 포워드, 레거시 디퍼드등)로는 패스를 생성하지 않음.

#pragma exclude_renderers space separated names 으로도 선언 가능

ex) #pragma exclude_renderes xbox360, ps4


• noshadow - Disables all shadow receiving support in this shader.

이셰이더에서 그림자를 받지 않음


• noambient - Do not apply any ambient lighting or light probes.

어떤 ambient light도, light probes도 적용받지 않음


• novertexlights - Do not apply any light probes or per-vertex lights in Forward rendering.

포워드 렌더링에서 어떤 light probes도, vertex-lit도 적용받지 않음


• nolightmap - Disables all lightmapping support in this shader.

라이트맵핑을 적용하지 않음


• nodynlightmap - Disables runtime dynamic global illumination support in this shader.

런타임에서 동적 GI를 적용하지 않음


• nodirlightmap - Disables directional lightmaps support in this shader.

directional lightmap을 적용하지 않음



• nofog - Disables all built-in Fog support.

내장 fog(안개)를 적용하지 않음


• nometa - Does not generate a “meta” pass (that’s used by lightmapping & dynamic global illumination to extract surface information).

"메타"패스를 생성하지 않음. 라이트맵핑 및 동적 GI를 사용해 표면정보를 추출


• noforwardadd - Disables Forward rendering additive pass. This makes the shader support one full directional light, with all other lights computed per-vertex/SH. Makes shaders smaller as well.

포워드 렌더링 추가패스를 사용하지 않음. 이것에 의해 셰이더는 1개의 디렉셔널 라이트를 지원. 다른 모든 라이트는 버텍스/SH(Spherical Harmonics - 구면조화함수) 마다 계산됨. 이는 셰이더를 더 작게 만든다.


• nolppv - Disables Light Probe Proxy Volume support in this shader.

Light Probe proxy volume을 사용하지 않음


• noshadowmask - Disables Shadowmask support for this shader (both Shadowmask and Distance Shadowmask).

Shadow mask를 사용하지 않음


Miscellaneous options

기타옵션


• softvegetation - Makes the surface shader only be rendered when Soft Vegetation is on.

softvegetation이 활성화 되어있을때만 렌더링 됨.(terrain 용)


• interpolateview - Compute view direction in the vertex shader and interpolate it; instead of computing it in the pixel shader. This can make the pixel shader faster, but uses up one more texture interpolator.

정점 셰이더에서 뷰 방향을 계산하고 보간. 픽셀 쉐이더에서 계산하는 대신에 이것은 픽셀 쉐이더를 더 빠르게 만들지만 하나 이상의 텍스처 인터폴 레이터를 사용.

• halfasview - Pass half-direction vector into the lighting function instead of view-direction. Half-direction will be computed and normalized per vertex. This is faster, but not entirely correct.

하프벡터를 뷰 방향 대신 조명 함수로 전달. 하프벡터는 정점당 계산되고 정규화(normalize된다). 이것은 빠르지만 정확하지는 않음.



• approxview - Removed in Unity 5.0. Use interpolateview instead.

사용하지 않음 5.0부터는 interpolateview 쓰삼


• dualforward - Use dual lightmaps in forward rendering path.

포워드 렌더링 패스에서 듀얼 라이트맵을 사용(역시 유니티5에서 없어짐)



To see what exactly is different from using different options above, it can be helpful to use “Show Generated Code” button in the Shader Inspector.

Shader Inspector에서 "Show Generated Code"버튼을 사용하면 어떻게 변환되고 몇개의 shader variants가 생성되는지 확인 가능하다.




반응형