본문 바로가기
Shader

유니티 5.0의 shader

by 대마왕J 2015. 3. 6.

Shaders - 5.0 Upgrade Guide

These are notes to be aware of when upgrading projects from Unity 4 to Unity 5, if your project uses custom shader code.

유니티 커스텀 쉐이더 5.0으로 짤때 주의할거

Shaders no longer apply a 2x multiply of light intensity
더이상 2배 * 라이팅이 적용되지 않는다.

 

Shaders no longer apply a 2x multiply of light intensity. Instead lights are automatically upgraded to be twice as bright.
커스텀 쉐이더에서 *2 하던거 안해도 됩니다. 알아서 할께요 .
more consistency and simplicity in light rigs. For example a directional light shining on a white diffuse surface will get the exact color of the light.
라이팅이 더 일관적이고 단순해졌어요 예를 들어 흰 색 디퓨즈 면에다가 디렉셔널 라이트 쏘는건 더 정확한 색상을 나타내게 되었죠


The upgrade does not affect animation, thus if you have an animated light intensity value you must change your animation curves or script code and make them 2x as large to get the same look.
그런데 이 업그레이드는 에니메이션에는 적용되지 않아요. 그래서 애니메이션되는 라이트 강도값을 가진다면 에니메이션 커브값이나 스크립트로 2배 쎄게 해야 같게 보일 겁니다. (주: 뭐야??? 스테틱에만 적용되는 거였냐????)

In the case of custom shaders where you define your own lighting functions, you need to remove the * 2 yourself. Surface shaders do not suffer from this problem.
커스텀 쉐이더 코드에서 라이트를 정의했으면 *2 제거하세요. 서피스 쉐이더는 이 문제 없습니다. (주: 걍 일반 서피스 쉐이더는 괜찮다는 뜻인듯)

// A common pattern in shader code that has this problem will look like this
c.rgb = s.Albedo * _LightColor0.rgb * (diff * atten * 2);
// You need to fix the code so it looks more like this
c.rgb = s.Albedo * _LightColor0.rgb * (diff * atten);

Increased interpolator and instruction counts for some surface shaders
일부의 서피스 쉐이더에서의 보간과 인스트럭션 카운트가 증가됨 

Built-in lighting pipeline in Unity 5 can in some cases use more texture coordinate interpolators or math instruction count (to get things like non-uniform mesh scale, dynamic GI etc. working).
유니티5에 들어가 있는 빌트인 라이팅 파이프라인은 몇몇 경우에서 텍스쳐 코디네이트 인터폴레이션이나 계산 인스트럭선 카운트를 더 사용할 수 있습니다. ( 뭐.. 논 유니폼 메쉬 스케일이나, 다이나믹 Gi등등에서)
Some of your existing surface shaders might be running into texture coordinate or ALU instruction limits, especially if they were targeting shader model 2.0 (default). Adding “#pragma target 3.0” can work around this issue. See http://docs.unity3d.com/Manual/SL-ShaderPrograms.html for the reference.
그래서 예전에 멀쩡했던 쉐이더가 계산양 오버가 나서 ALU 경고를 띄울 수 있어요.뭐 그럴땐 상콤하게 3.0 타겟으로 올려주세요.
“#pragma target 3.0” 으로 말이죠.

Non-uniform mesh scale has to be taken into account in shaders
논 - 유니폼 메쉬 스케일은 쉐이더에 영향을 끼침

In Unity 5.0, non-uniform meshes are not “prescaled” on the CPU anymore.
유니티 5에서 논 유니폼 메쉬들은 이제 더이상 CPU에서 '프리스케일드' 되지 않습니다. (주: 역시 논 유니폼 스케일을 죽입시다)
This means that normal & tangent vectors can be non-normalized in the vertex shader.
이 말은 노말과 탄젠트 벡터들이 버텍스 쉐이더에서 논-노말라이즈가 가능하다는 말입니다.
If you’re doing manual lighting calculations there, you’d have to normalize them. If you’re using Unity’s surface shaders, then all necessary code will be generated for you.
만약 당신이 거기서 수작업 라이팅을 계산한다면, 노말라이즈 하셔야 해요. 만약 서피스 쉐이더를 사용하신다면, 그럼 모든 필요한 코드는 뭐 알아서 만들어 질거예요.

Fog handling was changed
포그 처리가 달라짐

Unity 5.0 makes built-in Fog work on WP8 and consoles, but in order to achieve that we’ve changed how Fog is done a bit.
유니티 5.0의 내장 포그는 윈도우폰8과 콘솔에서 가동됩니다. 그러나 그걸 달성하기 위해서 포그 작동을 쫌 바꿨죠.
For surface shaders and fixed function shaders, nothing extra needs to be done - fog will be added automatically (you can add “nofog” to surface shader #pragma line to explicitly make it not support fog).
서피스 쉐이더나 고정 파이프라인 쉐이더에서는 뭐 할게 없습니다. - 자동으로 추가돼요 ( nofog 라고 #pragma 라인에 추가하면 포그 적용 피할 수 있죠 )

For manually written vertex/fragment shaders, fog does not happen automagically now. You need to add #pragma multi_compile_fog and fog handling macros to your shader code. Check out built-in shader source, for example Unlit-Normal how to do it.
수동으로 작성하는 버텍스/프레그먼트 쉐이더에서는 포그는 자동으로 추가되지 않습니다. 그럴때는  #pragma multi_compile_fog 추가해서 해야 합니다. 빌트인 쉐이더를 체크해 보세요. 예시로 Unlit-Normal 을 보시면 어케 하는지 나와있을겨.

Surface shaders alpha channel change
서피스 쉐이더 알파 채널 바뀜

By default all opaque surface shaders output 1.0 (“white”) into alpha channel now. If you want to stop that, use “keepalpha” option on the #pragma surface line.
기본으로 모든 불투명 오브젝트에서는 알파가 1.0이 박혀 나오죠. 만약 그걸 중지시키고 싶으시다면, #pragma 에 "keepalpha" 옵션을 추가하세요

All alpha blended surface shaders use alpha component computed by the lighting function as blend factor now (instead of s.Alpha). If you’re using custom lighting functions, you probably want to add something like “c.a = s.Alpha” towards the end of it.
모든 알파 블렌드 서피스 쉐이더는 라이팅 함수에서 블렌드 펙터를 이용해 알파 컴포넌트를 계산함. (s.Alpha 대신에 ) 만약 커스텀 라이트 펑션을 사용하고 싶으면, 아마 c.a = s.Alpha 같은걸 마지막에 사용하려 할 것임 (주: 어쩌자고)

Sorting by material index has been removed
메터리얼 인덱스 소팅이 제거됨

Unity no longer sorts by material index in the forward renderloop.
유니티는 더이상 메터리얼 인덱스를 포워드 렌더 루프에서 사용하지 않음 (주: 했었냐?!?!?)
This improves performance because more objects can be rendered without state changes between them.
이건 퍼포먼스를 증가시키는데 왜냐면 더 많은 오브젝트들이 그들의 스테이트를 바꾸지 않은 채 렌더링 될 수 있기 때문임.
This breaks compatibility for content that relies on material index as a way of sorting.
이것은 정렬 하는 방법으로 메터리얼에 의존하는 콘텐츠를 깨서 호환성 있게 시키는 것임.
In 4.x a mesh with two materials would always render the first material first, and the second material second.
4.x 때에서는 메쉬가 두 메터리얼을 가지고 있으면 언제나 첫 번째 메터리얼이 먼저, 두 번째 메터리얼이 둘째로 렌더링 되었음.
In Unity 5 this is not the case, the order depends on what reduces the most state changes to render the scene.
유니티5의 이 경우에는. 오더가 렌더링할 때 어떻게 스테이트 체인지 순서를 줄일 수 있는지에 달려 있습니다.

Fixed function TexGen, texture matrices and some SetTexture combiner modes were removed
고정 파이프라인 TexGen, 텍스쳐 메트릭스와 몇몇 셋 텍스쳐 컴바이너 모드가 삭제됨  

Unity 5.0 removed support for this fixed function shader functionality:
유니티 5.0은 고정 파이프 라인 쉐이더 기능 지원을 제거했습니다.

  • UV coordinate generation (TexGen command).
    UV 좌표 생성 (TexGen 커멘드)
  • UV transformation matrices (Matrix command on a texture property or inside a SetTexture).
    UV 트랜스폼 메트릭스 (셋 텍스쳐 안이나 텍스쳐 프로퍼티에 있는  메트릭스 커멘드)
  • Rarely used SetTexture combiner modes: signed add (a+-b), multiply signed add (ab+-c), multiply subtract (ab-c), dot product (dot3, dot3rgba).
    잘 안쓰는 컴바이너 모드 : signed add (a+-b), multiply signed add (ab+-c), multiply subtract (ab-c), dot product (dot3, dot3rgba).

Any of the above will do nothing now, and shader inspector will show warnings about their usage. You should rewrite affected shaders using programmable vertex+fragment shaders instead.
위 기능은 이제 암 것도 하지 않아요. 이걸 쓰면 인스펙터에서 경고 나올걸요. 버텍스 + 프레그먼트 쉐이더를 대신 쓰세요.
All platforms support them nowadays, and there are no advantages whatsoever to use fixed function shaders.

모든 플렛폼에서 이제는 이걸 지원 안하고요, 고정 파이프라인을 쓰는 어떠한 이득도 없을 거예요

If you have fairly old versions of Projector or Water shader packages in your project, the shaders there might be using this functionality. Upgrade the packages to 5.0 version.
만약 당신의 프로젝트에 상당히 오랜 버전의 프로젝터나 물 쉐이더 패키지를 사용하고 있으면 그 쉐이더들은 이 기능을 사용하고 있을 거예요. 5.0 버전의 패키지로 업데이트 하세요

Mixing programmable & fixed function shader parts is not allowed anymore
믹스드 프로그래머블 & 고정 함수 쉐이더 파츠는 이제 허용되지 않는다.

Mixing partially fixed function & partially programmable shaders (e.g. fixed function vertex lighting & pixel shader; or a vertex shader and texture combiners) is not supported anymore.
부분적인 고정파이프라인 과 부분적인 프로그래머블 쉐이더 (예를 들어 고정파이프라인의 버텍스라이팅 & 픽셀 쉐이더 혹은 버텍스 쉐이더와 텍스쳐 컴바이너) 는 이제 사용되지 않습니다.
It was never working on mobile, consoles or DirectX 11 anyway. This required changing behavior of Legacy/Reflective/VertexLit shader to not do that - it lost per-vertex specular support; on the plus side it now behaves consistently between platforms.
이건 이제 모바일에서도 안되고 콘솔이나 다이렉트 x11 다 안돼요.

D3D9 shader compiler was switched from Cg 2.2 to HLSL
D3D9 쉐이더 컴파일러는 CG2.2에서 HLSL로 변화되었습니다.

Mostly this should be transparent (just result in less codegen bugs and slightly faster shaders). However HLSL compiler can be slightly more picky about syntax. Some examples:
대부분 이것은 트렌스퍼런트일 것이다(주: 명백할 것이다?) (단지 결과는 좀 적은 코드 제네이트 버그와 약간 빠른 결과이다 ) 어쨌건 HLSL 컴파일러는 문법에서 약간 더 복잡해질 것입니다. 예를 들자면  

  • You need to fully initialize output variables. Use UNITY_INITIALIZE_OUTPUT helper macro, just like you would on D3D11.
    당신은 UNITY_INITIALIZE_OUTPUT 헬퍼 메크로를 사용해서 풀버전으로 아웃풋 벨류를 이니셜라이즈 해야 합니다. 마치 D3D11에서 사용했던 것 처럼 말입니다.
  • “float3(a_4_component_value)” constructors do not work. Use “a_4_component_value.xyz” instead.
    “float3(a_4_component_value)” 는 작동하지 않습니다. “a_4_component_value.xyz” 를 대신 쓰세요.

“unity_Scale” shader variable has been removed
"Unity_Scale" 쉐이더 변수는 제거되었습니다.

The “unity_Scale” shader property has been removed. In 4.x unity_Scale.w was the 1 / uniform Scale of the transform, Unity 4.x only rendered non-scaled or uniformly scaled models. Other scales were performed on the CPU, which was very expensive & had an unexpected memory overhead.
 “unity_Scale” 쉐이더 프로퍼티가 제거되었습니다. 4.x 에서 unity_Scale.w 는 1/트렌스폼 유니폼 스케일이었습니다, 유니티 4.x는 단지 논 스케일이나 유니폼 스케일 모델만 렌더링 했습니다. 다른 스케일은 CPU에서 계산되었고, 이것은 매우 비싸서 예상치 못한 메모리 오버헤드를 낳았습니다.  

In Unity 5.0 all this is done on the GPU by simply passing matrices with non-uniform scale to the shaders.
유니티 5.0 에서는 모든 이러한 것들을 논 유니폼 스케일과 함께 GPU에서 단순한 메트릭스 패싱으로 쉐이더로 처리합니다.
Thus unity_Scale has been removed because it can not represent the full scale.
이렇게 unity_Scale은 풀 스케일을 나타낼 수 없었기 때문에 삭제되었습니다.
In most cases where “unity_Scale” was used we recommend instead transforming to world space first. In the case of transforming normals, you always have to use normalize on the transformed normal now. In some cases this leads to slightly more expensive code in the vertex shader.

대부분의 경우  unity_Scale 은 월드 스페이스 트렌스폼 대신에 첫 번째 하는 것으로 추천되었으나, 노말을 트랜스폼 하는 경우에는 당신은 언제나 트렌스폼된 노말을 노말라이즈 해야 합니다. 일부 경우에서 이건 버텍스 쉐이더 코드에서 약간 좀 무거운 경우가 있습니다  

// Unity 4.x
float3 norm = mul ((float3x3)UNITY_MATRIX_IT_MV, v.normal * unity_Scale.w);




// Becomes this in Unity 5.0
float3 norm = normalize(mul ((float3x3)UNITY_MATRIX_IT_MV, v.normal)); (주: 노말인 경우에는음 노말라이즈 하고 있습니다)
// Unity 4.x
temp.xyzw = v.vertex.xzxz * unity_Scale.xzxz * _WaveScale4 + _WaveOffset;
// Becomes this in Unity 5.0 float4 wpos = mul (_Object2World, v.vertex); temp.xyzw = wpos.xzxz * _WaveScale4 + _WaveOffset;
(주: 이전보다 더 자연스러운 코드네요)

Shadows, Depth Textures and ShadowCollector passes
그림자와 댑스 텍스쳐와 쉐도우 콜렉터 패스

Forward rendered directional light shadows do not do separate “shadow collector” pass anymore. Now they calculate screenspace shadows from a camera’s depth texture (just like in deferred lighting).
포워드 렌더링의 디렉셔널 라이트 그림자는 어쨌거나 '쉐도우 콜렉터' 패스랑 뗄레야 뗄 수가 없었습니다. 이제 그들은 카메라의 댑스 텍스쳐에서 스크린스페이스로 계산됩니다! (마치 디퍼드 처럼 말입니다)  (주 : 유후)

This means that LightMode=ShadowCollector passes in shaders aren’t used for anything; you can just remove them from your shaders.
이 의미는 LightMode=ShadowCollector 패스는 이제 더이상 안쓴다는 말입니다; 그냥 심플하게 삭제 플리즈.

Depth texture itself is not generated using shader replacement anymore; it is rendered with ShadowCaster shader passes.
깊이 버퍼 그 자체는 더이상 쉐이더 리플레이스먼트를 사용해서 만들어지지 않습니다 ; 이것은 그냥 쉐도우캐스터 쉐이더 패스에서 만들어 지죠.
This means that as long as your objects can cast proper shadows, then they will also appear in camera’s depth texture properly (was very hard to do before, if you wanted custom vertex animation or funky alpha testing).
이 말은 당신의 오브젝트가 적당한 정도의 그림자를 캐스트 할 수 있다는 말이며, 그래서 그들은  이제 제대로 카메라 댑스 텍스쳐에 나타납니다. (이전에는 만약 커스텀 버텍스 에니메이션이나 펑키한 알파 테스팅을 표현하려면 힘들었다고요)
It also means that Camera-DepthTexture.shader is not used for anything now. And also, all built-in shadow shaders used no backface culling; that was changed to match culling mode of regular rendering.

이것은 또한 Camera-DepthTexture.shader 가 아무것도 하지 않는다는 말을 의미합니다. 그리고 또한 모든 내장 쉐도우 쉐이더는 백페이스 컬링을 사용하지 않습니다.; 이것은 일반 렌더링의 컬링과 일치하도록 만들었습니다.

 

 

 

 

 

 

 

반응형

댓글