Like this presentation? Why not share!

# D2 Rain (2/2)

## by 유표 최, Programmer at 게임하이 on Jul 01, 2011

• 327 views

### Views

Total Views
327
Views on SlideShare
250
Embed Views
77

Likes
0
0
0

### 1 Embed77

 http://aker.tistory.com 77

### Categories

Uploaded via SlideShare as Microsoft PowerPoint

## D2 Rain (2/2)Presentation Transcript

• RAIN in Karon2.0
김정희
최유표
• Simple Flow
VertexBuffer미리 생성
Texture(128*128, ARGB16)에 위치 기록
1에서 만들어진 Buffer가 VS In으로 들어옴
2에서 만들어진 Texture 접근하여 빌보드
섭동과 Splash
• VertexBuffer
VertexFormat
Short : Texture Index (0000, 1111, 2222, …)
Short : Vertex Index (0123, 0123, …)
# of Particle = 128 * 128 = 16384
# of Vertices = Particle * 4 = 65536
# of Indices = Particle * 6 = 98304
float4 RainPS( OUTPUT_VS In) : COLOR
{
float4 position = tex2D(Position_Sampler, In.tex); // 비의 Position
float3 seed = tex2D(Seed_Brightness_Sampler, In.tex).xyz; // 비가 새로 내리기 시작하는 위치
float3 speed = tex2D(Speed_Type_Sampler, In.tex).xyz; // 비가 내리는 속도
float3 move = Wind; move.y -= 1; // 아래 방향으로 내리도록
float3 totalMove = (speed + move * 20) * elapsedTime;
position.xyz += totalMove;
if (position.y <= eyePos.y - 40 )
{
float x = seed.x + eyePos.x;
float z = seed.z + eyePos.z;
float y = seed.y + eyePos.y;
position.xyz = float3(x,y,z);
}
return float4(position.xyz, 1);
}
OUTPUT_VS RainVs(INPUT_VS In)
{
int texIndex = In.index[0];
int vertIndex = In.index[1];
int y =texIndex/128;
int x = texIndex - y*128;
float4 positionUV = float4(float2(x,y)/128.0f, 0, 0);
float4 position = tex2Dlod(Position_Sampler, positionUV);
float3 speed = tex2Dlod(Speed_Type_Sampler, positionUV).xyz;
float3 move = Wind; move.y -= 1;
float3 totalMove = (speed + move * 20) * elapsedTime;
float3 pos[4];
GenRainSpriteVertices(position.xyz, totalMove, relativeEyePos, pos); // 빌보드 만드는 함수
OUTPUT_VS output;
output.pos = mul(float4(pos[vertIndex], 1.0f), WorldViewProjMatrix);
output.tex = g_texcoords[vertIndex]; // (0, 0), (0, 1), (1, 0), (1, 1)
return output;
}
float4 DeferredShadePS( OUTPUT_VS In, uniform bool usedSSAO, uniform bool usedSpecular,
uniform bool usedShadow, uniform bool usedRain) : COLOR
{
// 비
float3 splashDiffuse = 0;
if (usedRain)
{
float4 baseGeometry = tex2D(MRTSampler1, In.tex);
float3 baseViewNormal = baseGeometry.xyz;
float baseDepth = baseGeometry.a; // ViewZ
float4 baseViewPosition = GetViewPosition4(In.tex, baseDepth, InvProjectionM11M22);
float2 positionXZ = float2(dot(baseViewPosition, transposeInvViewMat[0]),
dot(baseViewPosition, transposeInvViewMat[2]));
float normalY = dot(baseViewNormal, transposeInvViewMat[1]);
float wetSurf = saturate(normalY - baseDepth * 0.05f); // 기울기, 멀어지면 감쇠
In.tex += wetSurf * tex3D(rainSampler, float3(positionXZ*0.5f, g_timeCycle*2)).r * 0.05f; // 섭동
splashDiffuse = wetSurf * tex3D(rainSampler, float3(positionXZ, g_timeCycle*2)); // Splash
}
… 생략…
• Performance
• No Rain 107FPS
vs Instancing 98FPS