Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

D2 Rain (2/2)

892 views

Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

D2 Rain (2/2)

  1. 1. RAIN in Karon2.0<br />김정희<br />최유표<br />
  2. 2. Simple Flow<br />VertexBuffer미리 생성<br />RainAdvance.fx<br />Texture(128*128, ARGB16)에 위치 기록<br />RainShade.fx<br />1에서 만들어진 Buffer가 VS In으로 들어옴<br />2에서 만들어진 Texture 접근하여 빌보드<br />DeferredShade.fx<br />섭동과 Splash<br />
  3. 3. VertexBuffer<br />VertexFormat<br />Short : Texture Index (0000, 1111, 2222, …)<br />Short : Vertex Index (0123, 0123, …)<br /># of Particle = 128 * 128 = 16384<br /># of Vertices = Particle * 4 = 65536<br /># of Indices = Particle * 6 = 98304<br />
  4. 4. RainAdvance.fx<br />float4 RainPS( OUTPUT_VS In) : COLOR<br />{<br />float4 position = tex2D(Position_Sampler, In.tex); // 비의 Position<br />float3 seed = tex2D(Seed_Brightness_Sampler, In.tex).xyz; // 비가 새로 내리기 시작하는 위치<br />float3 speed = tex2D(Speed_Type_Sampler, In.tex).xyz; // 비가 내리는 속도<br />float3 move = Wind; move.y -= 1; // 아래 방향으로 내리도록<br />float3 totalMove = (speed + move * 20) * elapsedTime;<br />position.xyz += totalMove;<br />if (position.y <= eyePos.y - 40 )<br />{<br />float x = seed.x + eyePos.x;<br />float z = seed.z + eyePos.z;<br />float y = seed.y + eyePos.y;<br />position.xyz = float3(x,y,z);<br />}<br />return float4(position.xyz, 1);<br />}<br />
  5. 5. RainShade.fx<br />OUTPUT_VS RainVs(INPUT_VS In)<br />{<br />int texIndex = In.index[0];<br />int vertIndex = In.index[1];<br />int y =texIndex/128;<br />int x = texIndex - y*128;<br />float4 positionUV = float4(float2(x,y)/128.0f, 0, 0);<br />float4 position = tex2Dlod(Position_Sampler, positionUV);<br />float3 speed = tex2Dlod(Speed_Type_Sampler, positionUV).xyz;<br />float3 move = Wind; move.y -= 1;<br />float3 totalMove = (speed + move * 20) * elapsedTime;<br />float3 pos[4];<br />GenRainSpriteVertices(position.xyz, totalMove, relativeEyePos, pos); // 빌보드 만드는 함수<br />OUTPUT_VS output;<br />output.pos = mul(float4(pos[vertIndex], 1.0f), WorldViewProjMatrix);<br />output.tex = g_texcoords[vertIndex]; // (0, 0), (0, 1), (1, 0), (1, 1)<br />return output;<br />}<br />
  6. 6. DeferredShade.fx<br />float4 DeferredShadePS( OUTPUT_VS In, uniform bool usedSSAO, uniform bool usedSpecular, <br />uniform bool usedShadow, uniform bool usedRain) : COLOR<br />{<br />// 비<br />float3 splashDiffuse = 0;<br />if (usedRain)<br />{<br /> float4 baseGeometry = tex2D(MRTSampler1, In.tex);<br /> float3 baseViewNormal = baseGeometry.xyz;<br /> float baseDepth = baseGeometry.a; // ViewZ<br /> float4 baseViewPosition = GetViewPosition4(In.tex, baseDepth, InvProjectionM11M22);<br /> float2 positionXZ = float2(dot(baseViewPosition, transposeInvViewMat[0]), <br /> dot(baseViewPosition, transposeInvViewMat[2]));<br /> float normalY = dot(baseViewNormal, transposeInvViewMat[1]);<br /> float wetSurf = saturate(normalY - baseDepth * 0.05f); // 기울기, 멀어지면 감쇠<br /> In.tex += wetSurf * tex3D(rainSampler, float3(positionXZ*0.5f, g_timeCycle*2)).r * 0.05f; // 섭동<br /> splashDiffuse = wetSurf * tex3D(rainSampler, float3(positionXZ, g_timeCycle*2)); // Splash<br /> }<br />… 생략…<br />
  7. 7. Performance<br /><ul><li>No Rain 107FPS </li></ul>vs Instancing 98FPS <br />vs Pre-made104FPS<br /><ul><li>메모리는 Instancing 보다 약 200KB 정도 더 사용하지만 FPS 우위</li></ul>구현 사항은 콘솔창에“option rain true/false로 확인 가능”<br />
  8. 8. Future Work<br />CenterMap이 바뀔 때<br />건물 안에서도 비가 옴<br />경사면에서의 Splash<br />물체에 흐르는 빗물<br />내리는 빗물과 물방울 일치(?)<br />
  9. 9. ?<br />

×