본문 바로가기
카테고리 없음

Unity Tree Shader 교체 프로젝트 진행중

by 대마왕J 2012. 12. 7.

유니티 나무 셰이더 교체 프로젝트. 일단 데이터가 너무 없는게 문제..

몇 가지 작업중 요령 백업.

- "Hidden/Nature/Tree Creator Leaves Optimized" shader 에서 에러가 난다. 이것은  #include "Tree.cginc" 가 없다는 에러인데, 실제로 Tree.cginc 는 엔진에서 빠진듯. 그리고 구 shader의 Tree.cginc 를 보면 사실 구조체 정의랑 조명연산밖에 없다.

#ifndef TREE_CG_INCLUDED
#define TREE_CG_INCLUDED

#include "TerrainEngine.cginc"

fixed4 _Color;
fixed3 _TranslucencyColor;
fixed _TranslucencyViewDependency;
half _ShadowStrength;

struct LeafSurfaceOutput {
 fixed3 Albedo;
 fixed3 Normal;
 fixed3 Emission;
 fixed Translucency;
 half Specular;
 fixed Gloss;
 fixed Alpha;
};

inline half4 LightingTreeLeaf (LeafSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
{
 half3 h = normalize (lightDir + viewDir);
 
 half nl = dot (s.Normal, lightDir);
 
 half nh = max (0, dot (s.Normal, h));
 half spec = pow (nh, s.Specular * 128.0) * s.Gloss;
 
 // view dependent back contribution for translucency
 fixed backContrib = saturate(dot(viewDir, -lightDir));
 
 // normally translucency is more like -nl, but looks better when it's view dependent
 backContrib = lerp(saturate(-nl), backContrib, _TranslucencyViewDependency);
 
 fixed3 translucencyColor = backContrib * s.Translucency * _TranslucencyColor;
 
 // wrap-around diffuse
 nl = max(0, nl * 0.6 + 0.4);
 
 fixed4 c;
 c.rgb = s.Albedo * (translucencyColor * 2 + nl);
 c.rgb = c.rgb * _LightColor0.rgb + spec;
 
 // For directional lights, apply less shadow attenuation
 // based on shadow strength parameter.
 #if defined(DIRECTIONAL) || defined(DIRECTIONAL_COOKIE)
 c.rgb *= lerp(2, atten * 2, _ShadowStrength);
 #else
 c.rgb *= 2*atten;
 #endif
 
 return c;
}

#endif

그러므로 여기서 구조체를 일반 구조체로 사용하고 Unity.cginc 를 부르면 될듯. 조명연산도 일반 연산을 이용해도 아무 문제 없을듯.

여기서 조명 연산을 해버리니까 디퍼드로 연산이 안되고 포워드가 되는 듯 하는데,
실제 엔진 안에 Tree.cginc 가 빠져버린지라 확인할 수가 없다.

그리고 Tree shader 안에 마지막 부분,

 

Dependency "BillboardShader" = "Hidden/Nature/Tree Creator Leaves Rendertex"

 

이 구문은 강제로 어디에선가 정의된 구문인 듯 하다. 실제로 이 부분을 안 써 넣으면 쓰라고 경고 메시지가 나온다.
이건 강제로 써 줘서 일단 가동시키고, 추후 진행을 보는 식으로 해야겠다.

- Free 나무 셰이더가 있는 듯 하다. 이 셰이더를 나중에 분석해서 개량하는것도 의미가 있겠다.

 

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

http://answers.unity3d.com/questions/251060/custom-tree-shading-issue.html

여러 문제가 보인다.

alt text

역시 이런 문제도 발생하는듯. 나랑 똑같다. ㅋㅋㅋ

 

반응형

댓글