상세 컨텐츠

본문 제목

[Unity] 유니티 오브젝트 구성 겹칠때 안보여야할 안쪽오브젝트 비추는 현상 또는 깨지는현상 Material 옵션수정 관련

게임엔진관련/유니티 엔진

by AlrepondTech 2019. 5. 4. 00:40

본문

반응형

 

 

 

=======================

=======================

=======================

 

 

 

 

메인카메라 90도인 상황에서 겹치는 오브젝트로 구성해서 만들떄.

3D격자에 하얀색 네모큐브오브젝트로 타일을 만드는데 오브젝트가 겹쳐서

제대로 안나오거나 깨지는 경우가 있다.

 

랜더링 모드에서 "Opaque" 를

 

 

 

//--------------------------------------------------------------------

 

랜더링 모드에서 Cutout 로 바꾸어주자 그리고 겹치는 오브젝트를 안보이게

"Alpha Cutoff" 값을 높은값 적용해주면된다 개인적으론 "1"로 맞추어 주었다

 

 

=======================

=======================

=======================

 

 

 

반응형

 

728x90

 

 

 

 

출처: http://ko.esotericsoftware.com/forum/Unity3D-11776

 

Unity3D 에서 스파인 오브젝트가 스파인 모션에 의해 모든 파츠들의 opacity 가 255 -> 0 으로 감소할 때

파츠끼리 겹치는 부분이 덧그려지는걸 방지하기위해 

Spine-Skeleton.shader 에서 Cull Back, ZWrite On 으로 모두 수정했지만 별 효과가 없는것 같습니다



기본 Spine-Skeleton.shader 에서 코드를 수정하여 덧그려지는 문제를 방지할 방법이 있을까요?

--- 아래는 수정한 Spine-Skeleton.shader 코드 전체 입니다 ---

Shader "Spine/Skeleton" {
Properties {
_Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1
[NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {}
}

SubShader {
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane"}

Fog { Mode Off }
Cull Back
ZWrite On
Blend One OneMinusSrcAlpha
Lighting Off

Pass {
Fog { Mode Off }
ColorMaterial AmbientAndDiffuse
SetTexture [_MainTex] {
Combine texture * primary
}
}

Pass {
Name "Caster"
Tags { "LightMode"="ShadowCaster" }
Offset 1, 1
ZWrite On
ZTest LEqual

Fog { Mode Off }
Cull Back
Lighting Off

CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_shadowcaster
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
sampler2D _MainTex;
fixed _Cutoff;

struct v2f { 
V2F_SHADOW_CASTER;
float2 uv : TEXCOORD1;
};

v2f vert (appdata_base v) {
v2f o;
TRANSFER_SHADOW_CASTER(o)
o.uv = v.texcoord;
return o;
}

float4 frag (v2f i) : COLOR {
fixed4 texcol = tex2D(_MainTex, i.uv);
clip(texcol.a - _Cutoff);
SHADOW_CASTER_FRAGMENT(i)
}
ENDCG
}
}

SubShader {
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }

Cull Back
ZWrite On
Blend One OneMinusSrcAlpha
Lighting Off

Pass {
ColorMaterial AmbientAndDiffuse
SetTexture [_MainTex] {
Combine texture * primary DOUBLE, texture * primary
}
}
}
}

----------------------------------------------------------------------------------------------------------------------------------------------------

 

이 작업을 원할 경우 다음을 확인해야합니다.
If you want to make this work, you have to ensure the following:

1) 메시 내부의 순서 정렬 그리기가 앞뒤로 변경되어야합니다 (Spine은 투명도를 올바르게 처리하기 위해 앞뒤 순서를 사용합니다)
2) ZWrite를 활성화해야합니다.
3) ZTest를 활성화해야합니다.
4) 알파 테스트는 매우 적극적으로 폐기해야하며 1.0 이하의 모든 불투명도는 잘립니다. 그렇지 않으면 이상한 테두리 윤곽 효과가 나타납니다.

1) Draw order sorting inside the mesh needs to be changed to front-to-back (Spine uses back-to-front order to handle transparency correctly)
2) ZWrite needs to be enabled
3) ZTest needs to be enabled
4) Alpha Test needs to discard very agressively, everything below 1.0 opacity should be clipped. Otherwise you would receive strange border outline effects.

컬 모드를`컬백 (Cull Back) '으로 설정하여 달성하고자하는 것을 이해하지 못합니다.
I do not quite understand what you wanted to achieve by setting cull mode to Cull Back. 

--- 

하나의 대안은 RenderTexture를 사용하는 것입니다 : https://docs.unity3d.com/Manual/class-RenderTexture.html.
One alternative would be to use a RenderTexture: https://docs.unity3d.com/Manual/class-RenderTexture.html.

RenderTexture를 100 % 불투명도로 렌더링하고 투명도를 적용하지 않고 RenderTexture를 원하는 불투명도로 오버레이하여 RenderTexture를 간단한 투명한 재질로 적용한 간단한 쿼드를 통해 렌더링 할 수 있습니다 (50 % 투명한). 이것은 귀하의 경우에 가장 빠르고 쉬운 해결책이 될 것입니다.

You could render the character to the RenderTexture at 100% opacity (so without the transparency applied yet) and then overlay the RenderTexture to your scene at the desired opacity via a simple quad with the RenderTexture applied at a simple transparent material (lets say 50% transparent). This would be the quickest and easiest solution in your case.

앞으로는 일반적인 페이드 아웃 시나리오를 보여주기 위해 예제 장면을 제공 할 계획입니다.

We are planning to provide an example scene in the future to show common fade-out scenarios.

 

 

=======================

=======================

=======================

 

 

반응형


관련글 더보기

댓글 영역