• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Killerregenwurm

Summed Area Table for variance Shadow Mapping, again...

1 post in this topic

Hello guys,

I'm trying do implement a summed area table for my shadowmap since a couple of weeks like it is in GPU Gems3. I found a lot of article an disscussions about it here and with google but I can't finde an answer for my Problem.
Im using DirectX11 with the DXUT and worked on a HLSL shader wich generate from the shadowmap a SAT-image.

c++:
[source lang="cpp"]RenderableTexture* renderSAT::createSAT(ID3D11DeviceContext* pd3dContext, RenderableTexture* Input)
{

shaderEffect->GetVariableByName("Samples")->AsScalar()->SetInt(SATRenderSamples);
pd3dContext->RSSetViewports(1, &m_Viewport);
m_original = Input;
//HorizontalPass
for(int i = 1; i < imgWidth; i *= SATRenderSamples)
{
int PassOffset[2] = { i, 0};

int done = i/SATRenderSamples;
D3D11_RECT region = { done, 0, imgWidth, imgHeight};
//only first pass
m_sourceEV->SetResource(i == 1 ? m_original->GetShaderResource() : m_src->GetShaderResource());
shaderEffect->GetVariableByName("PassOffset")->AsVector()->SetIntVector(PassOffset);
//avoids warning
pd3dContext->OMSetRenderTargets(0, NULL, NULL);
SATRenderTechnique->GetPassByIndex(0)->Apply(0, pd3dContext);

ID3D11RenderTargetView* pRTV = m_dest->GetRenderTarget();
pd3dContext->OMSetRenderTargets(1, &pRTV, NULL);
pd3dContext->RSSetScissorRects(1, &region);
pd3dContext->IASetInputLayout(NULL);
pd3dContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
SATRenderTechnique->GetPassByIndex(0)->Apply(0, pd3dContext);
pd3dContext->Draw(1,0);
// Swap pointers (ping pong)
std::swap(m_dest, m_src);
}
//vertical Pass
for(int i = 1; i < imgHeight; i *= SATRenderPasses)
{
int PassOffset[2] = { 0,i};

int done = i/SATRenderSamples;
D3D11_RECT region = { 0, done, imgWidth, imgHeight};
ID3D11ShaderResourceView* source = m_src->GetShaderResource();
m_sourceEV->SetResource(source);
shaderEffect->GetVariableByName("PassOffset")->AsVector()->SetIntVector(PassOffset);
//avoids warning
pd3dContext->OMSetRenderTargets(0, NULL, NULL);
SATRenderTechnique->GetPassByIndex(0)->Apply(0, pd3dContext);

ID3D11RenderTargetView* pRTV = m_dest->GetRenderTarget();
pd3dContext->OMSetRenderTargets(1, &pRTV, NULL);
pd3dContext->RSSetScissorRects(1, &region);
pd3dContext->IASetInputLayout(NULL);
pd3dContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
SATRenderTechnique->GetPassByIndex(0)->Apply(0, pd3dContext);
pd3dContext->Draw(1,0);
// Swap pointers (ping pong)
std::swap(m_dest, m_src);
}
return m_dest;
}
[/source]
and the pixelshader (works on a fullscreenquad)
[source lang="cpp"]float4 generateSAT(Vertex In) : SV_Target0
{
float2 dimension;
Source.GetDimensions(dimension.x, dimension.y);
float2 currentOffset = float2(PassOffset)/dimension;// (1, 0)/dimension or (0, 1)/dimension
float4 result;
for(int i = 0; i < Samples; i++)
{
result += Source.SampleLevel(samBorderPoint, In.Tex - i*currentOffset, 0);
}
return result;
}
[/source]

but if I sample the SAT-image with a 1x1 filter, I get this beautyful image, the image in use for the generation is displayed correctly.
[attachment=11469:Unbenannt.PNG]
left: SAT with 1x1 filter right: original ShadowMap
for the drawing on screen I use a bordercolor float4(0,0,0,1).

i think it looks like that the scissorRect don't fit, but i can't imagine why.
Did someone know what could I do to solve this Problem?
0

Share this post


Link to post
Share on other sites
Hi,

The way you compute your scan is quite expensive. I don't see the bug in your code, but I would approach it differently anyway. You could compute the complete SAT with only two compute shaders by using one vertical and one horizontal scan pass, as described by [url="http://http.developer.nvidia.com/GPUGems3/gpugems3_ch39.html"]Harris et al[/url].

Perhaps, have a look into the GPU Computing SDK of Nvidia. It contains a [url="http://developer.nvidia.com/cuda/cuda-cc-sdk-code-samples#scan"]sample[/url] for the parallel scan (from Harris) in Cuda and OpenCL. Translating to DirectCompute should be straight-forward.

Here is some naïve scan implementation I used in Cuda to implement a SAT filter. I'm sure you can translate it to DirectCompute. (It's also a good practice, since a lot of useful code is currently only written in Cuda.)

Naive parallel scan (no up and down sweep):
[CODE]
__global__ void scan_naive(float *g_odata, float *g_idata)
{
// Allocated shared memory for scan kernels
__shared__ float temp[2*N];
int thid = threadIdx.x;
int bid = blockIdx.x;
int pout = 0;
int pin = 1;
// Cache the computational window in shared memory
temp[pout*N + thid] = (thid > 0) ? g_idata[bid * N + thid-1] : 0;
for (int offset = 1; offset < N; offset *= 2)
{
pout = 1 - pout;
pin = 1 - pout;
__syncthreads();
temp[pout*N+thid] = temp[pin*N+thid];
if (thid >= offset)
temp[pout*N+thid] += temp[pin*N+thid - offset];
}
__syncthreads();
g_odata[bid * N + thid] = temp[pout*N+thid];
}
[/CODE]
N is the image width.

And here a simple function that transposes an image, so that we can apply the same scan code for the vertical and horizontal pass (in case width == height).
[CODE]
__global__ void transpose(float *g_odata, float *g_idata)
{
int thid = threadIdx.x;
int bid = blockIdx.x;
g_odata[bid * N + thid] = g_idata[thid * N + bid];
}
[/CODE]

Also, consider using the [url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb509694%28v=vs.85%29.aspx"]Load[/url] intrinsic if you read exactly from pixels. It by-passes the texture filtering and is therefore a bit faster.

Best regards! Edited by Tsus
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0