forked from walbourn/directx-sdk-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOIT_PS.hlsl
54 lines (46 loc) · 1.59 KB
/
OIT_PS.hlsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//-----------------------------------------------------------------------------
// File: OITPS.hlsl
//
// Desc: Pixel shaders used in the Order Independent Transparency sample.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
//TODO: Use structured buffers
RWTexture2D<uint> fragmentCount : register( u1 );
RWBuffer<float> deepBufferDepth : register( u2 );
RWBuffer<uint4> deepBufferColor : register( u3 );
RWBuffer<uint> prefixSum : register( u4 );
cbuffer CB : register( b0 )
{
uint g_nFrameWidth : packoffset( c0.x );
uint g_nFrameHeight : packoffset( c0.y );
uint g_nReserved0 : packoffset( c0.z );
uint g_nReserved1 : packoffset( c0.w );
}
struct SceneVS_Output
{
float4 pos : SV_POSITION;
float4 color : COLOR0;
};
void FragmentCountPS( SceneVS_Output input)
{
// Increments need to be done atomically
InterlockedAdd(fragmentCount[input.pos.xy], 1);
}
void FillDeepBufferPS( SceneVS_Output input )
{
uint x = input.pos.x;
uint y = input.pos.y;
// Atomically allocate space in the deep buffer
uint fc;
InterlockedAdd(fragmentCount[input.pos.xy], 1, fc);
uint nPrefixSumPos = y*g_nFrameWidth + x;
uint nDeepBufferPos;
if( nPrefixSumPos == 0 )
nDeepBufferPos = fc;
else
nDeepBufferPos = prefixSum[nPrefixSumPos-1] + fc;
// Store fragment data into the allocated space
deepBufferDepth[nDeepBufferPos] = input.pos.z;
deepBufferColor[nDeepBufferPos] = clamp(input.color, 0, 1)*255;
}