Game Development Reference
In-Depth Information
for details). As we only consider triangles, we can conveniently implement this
functionality in a geometry shader.
Listing 3.1 i s an extract from the geometry shader code that assigns a shading
grid for each rasterized triangle. In our implementation, the geometry shader
might also set up conservative bounds for stochastically rasterized triangles.
Listing 3.2 shows the pseudocode of the fragment shader, implementing the
remainder of our pipeline. As we described before, the output of this shader
is only a pointer to the corresponding shader data. Note that due to driver
limitations on integer multisampling, we need to store the references in floating
point, using the intBitsToFloat GLSL function. The shading samples are stored
using image buffers.
We omit the details of visibility testing, which might be standard multi-
sampled rasterization, or the implementation of stochastic rasterization, which
casts randomly distributed rays inside the conservative screen space bounds of the
triangles. We only assume that the visibility method returned the barycentrics of
the intersection point. The visibility sample is then assigned to a shading sample,
using the grid provided by the geometry shader.
layout(location = 0, index = 0) out float FragPtr;
// shader inputs: position, normal, texcoords
flat in vec3 vpos0...
// packed CG-buffer data
layout(rg32ui) uniform uimageBuffer uColorNormalBuffer;
layout(rgba32f) uniform uimageBuffer uViewPosBuffer;
void main(){
// hw-interpolation or stochastic ray casting...
vec3 baryCoords = getViewSamplePos();
// get nearest shading sample
uint localID = projectToGrid(baryCoords, shadingRate);
uint globalID = startID + localID;
bool needStore = false;
int address = getCachedAddress(globalID, needStore);
FragPtr = intBitsToFloat(address);
if (needStore){
// for each texture...
textureGradsInShadingSpace(localID, dx, dy);
vec4 diffuse = textureGrad(texDiffuse, texCoord, dx, dy);
[...]
// pack color , normal, view positions into the CGbuffer
imageStore(uColorNormalBuffer, address, ...);
}
}
Listing 3.2. The fragment shader implements the decoupling map and the chaching
mechanism for shading samples.
 
 
Search Nedrilad ::




Custom Search