기본 콘텐츠로 건너뛰기

1월, 2011의 게시물 표시

Light Pre-Pass Renderer

Geometry Pass Depth(xy), Normal(xy) Geometry Buffer(이하 G-Buffer) 저장 Light Properties Pass 아래 최종 색상 식에 미리 계산된 항목을 Light Buffer(이하 L-Buffer) 최종 색상 = Ambient + Shadow * Att * (N.L * diffuseColor * diffuseIntensity * diffuseLightColor + R.V^n * specularColor * specularIntensity * specularLightColor ) Light Properties - N.L - LightColor (Diffuse, Specular) - R.V^n - Attenuation Light Texture(A8R8G8B8 format) - Channel 1 : diffuseLightColor.r * N.L * Att - Channel 2 : diffuseLightColor.g * N.L * Att - Channel 3 : diffuseLightColor.b * N.L * Att - Channel 4 : R.V^n * N.L *Att 아래는 관련 Shader Code 입니다. half4 ps_main( PS_INPUT Input ) : COLOR { half4 G_Buffer = tex2D( G_Buffer, Input.texCoord ); // Compute pixel position half Depth = UnpackFloat16( G_Buffer.zw ); float3 PixelPos = normalize(Input.EyeScreenRay.xyz) * Depth; // Compute normal half3 Normal; Normal.xy = G_Buffer.xy*2-1; Normal.z = -sqrt(1-dot(Normal.xy,Normal.xy)); // Computes light attenuation and direction float3 LightDir = (Input.

D3D이용 2D출력시 마법의 숫자 -0.5 에 대하여

원본 : www.gamza.net ** D3D이용 2D출력시 마법의 숫자 -0.5 에 대하여 ** copyrightⓒ Gamza 2008-07-06 13:37:10 추천: 128 조회: 4,702 시대도 시대이니만큼 CPU의 픽셀연산을 몽땅 버리고, 블렌딩/확대/축소/필터링/멀티텍스쳐링/컬러쉐이딩등 수많은 하드웨어 가속기의 능력을 사용해 보려고 마음을 먹었습니다. 그런데 열받는것이....D3D로 2D출력을 해보니...이넘이 색상이 뭉개지는것 같기도 하고, 한 텍셀씩 밀린다거나 끝쪽에 한라인이 삐져나오는등...벼라별 문제가 다 일어나는겁니다. 모처럼만에 큰맘먹고 3D가속기를 써보려던 마음이 마구 흔들리는 순간입니다. 이럴때 구원의 숫자 -0.5가 등장하죠. D3D로 2D출력할때 x,y좌표에서 0.5를 빼주면 희한하게도 깔끔하게 나오는것을 보게되는데요. 여기선 그 증상과 이유를 간단히 설명드리려고 합니다. "난 -0.5 같은거 안해도 잘만나오는데.." 라고 하시는 분들은...반드시 읽어주세요. 1. 잘못된 구현 D3D로 2D를 표현하려고 할때 십중팔구는 아래처럼 잘못된 구현을 하게됩니다. void DrawTexture( long x, long y, long w, long h, loat tu, float tv, float tw, float th ) { ... Vertex[ 0 ] . position . x = ( float )x; Vertex[ 0 ] . position . y = ( float )y; Vertex[ 1 ] . position . x = Vertex[ 0 ] . position . x + w; Vertex[ 1 ] . position . y = Vertex[ 0 ] . position . y; Vertex[ 2 ] . position . x = Vertex[ 0 ] . position . x + w; Vertex[ 2 ] . position . y