I am back to this small project of doing exercises from the dx11 book. This time chapter 12 The Compute Shader. First three exercises asked to count length of 3d vectors from a structured buffers and from buffers of data etc.
Exercise 4 asked to study Bilateral blur and redo the blur demo with it.
I am not sure if I got it right but here is a screen shot:
ex 5 was about implementing previous wave simulation on gpu. Hints where given about textures to store solutions and about two computations first to update the wave and second to disturb the waves. Also the code to render the wave was given.
It was easy to create two shaders to update and disturb wave by looking the original cpu code
wave updated on cpu:
for(UINT i = 1; i < mNumRows-1; ++i) { for(UINT j = 1; j < mNumCols-1; ++j) { mPrevSolution[i*mNumCols+j].y = mK1*mPrevSolution[i*mNumCols+j].y + mK2*mCurrSolution[i*mNumCols+j].y + mK3*(mCurrSolution[(i+1)*mNumCols+j].y + mCurrSolution[(i-1)*mNumCols+j].y + mCurrSolution[i*mNumCols+j+1].y + mCurrSolution[i*mNumCols+j-1].y); } }This on GPU:
// mK1,2,3 in waveConst int x = dispatchThreadID.x; int y = dispatchThreadID.y; gNextSolOutput[int2(x,y)] = gWaveConst[0]* gPrevSolInput[int2(x,y)].r + gWaveConst[1]* gCurrSolInput[int2(x,y)].r + gWaveConst[2]*( gCurrSolInput[int2(x,y+1)].r + gCurrSolInput[int2(x,y-1)].r + gCurrSolInput[int2(x+1,y)].r + gCurrSolInput[int2(x-1,y)].r);disturb the wave from cpu solution:
float halfMag = 0.5f*magnitude; // Disturb the ijth vertex height and its neighbors. mCurrSolution[i*mNumCols+j].y += magnitude; mCurrSolution[i*mNumCols+j+1].y += halfMag; mCurrSolution[i*mNumCols+j-1].y += halfMag; mCurrSolution[(i+1)*mNumCols+j].y += halfMag; mCurrSolution[(i-1)*mNumCols+j].y += halfMag;On GPU:
int x = gIndex.x; int y = gIndex.y; float halfMag = 0.5f*gMagnitude; gCurrSolOutput[int2(x,y)] += gMagnitude; gCurrSolOutput[int2(x+1,y)] += halfMag; gCurrSolOutput[int2(x-1,y)] += halfMag; gCurrSolOutput[int2(x,y+1)] += halfMag; gCurrSolOutput[int2(x,y-1)] += halfMag;FPS with gpu solution went from 70 to ~700fps .