Thank You for replies!
The point is that currently there are lots of systems with dual-gpu configuration, thanks to Intel/AMD and their integrated GPU cores in processors. I want to exploit dual-GPU config for shadow mapping, where one GPU would render the scene itself, and the other one would be responsible for shadows, e.g. creating the shadow map and transfering the map to the primary GPU. I will try to see into it a bit more...
- Viewing Profile: Posts: stgFX
14 years ago on June 15th Gamedev.net was first launched! We want to thank all of you for being part of our community and hope the best years are ahead of us. Happy birthday Gamedev.net!
Community Stats
- Group Members
- Active Posts 5
- Profile Views 492
- Member Title Member
- Age Age Unknown
- Birthday Birthday Unknown
-
Gender
Not Telling
116
Neutral
User Tools
Contacts
stgFX hasn't added any contacts yet.
Posts I've Made
In Topic: Texture transfer between two GPUs
06 June 2012 - 11:21 AM
In Topic: How to setup paraboloid's view matrix in dual paraboloid shadow map?
04 February 2012 - 04:04 PM
This setup produces result like this:
http://s7.directuplo...04/ytgev879.png
the dog is located at x = 0 and z=0, his head pointing towards positive z. Light is at (0, 10, 0) - above the dog. When I debugged my code in AMD GPU PerfStudio, the applied map is actually stored in back texture and not in front (despite containing front map).
If I set front view matrix for back map generation, I can get correct back map:
http://s7.directuplo...04/jcmytkzt.png
But front map is always empty, that means initialized to 1s, so everything is lighted.
http://s7.directuplo...04/ytgev879.png
the dog is located at x = 0 and z=0, his head pointing towards positive z. Light is at (0, 10, 0) - above the dog. When I debugged my code in AMD GPU PerfStudio, the applied map is actually stored in back texture and not in front (despite containing front map).
If I set front view matrix for back map generation, I can get correct back map:
http://s7.directuplo...04/jcmytkzt.png
But front map is always empty, that means initialized to 1s, so everything is lighted.
In Topic: How to setup paraboloid's view matrix in dual paraboloid shadow map?
04 February 2012 - 03:43 PM
I have simmilar problem as minhpu, I'm implementing DPSM in DirectX 11 and the problem is that I can't make front map work, and back map works only with some "crazy" parameters (setting front view matrix for light). I spent week trying to find what's wrong, but I can't find it. Please help. I followed code from THIS website.
Here is initialization code (SRVs, RenderTargets, Textures,...):
Here is the rendering code:
..and shader code:
I'm a DX beginner, so if You see something "stupid" in my code, just let me know. Thanks a lot ;)
Here is initialization code (SRVs, RenderTargets, Textures,...):
lightViewPort.Width = SM_DP_SIZE;
lightViewPort.Height = SM_DP_SIZE;
lightViewPort.MinDepth = 0.0f;
lightViewPort.MaxDepth = 1.0f;
lightViewPort.TopLeftX = 0.0f;
lightViewPort.TopLeftY = 0.0f;
//Sampler
D3D11_SAMPLER_DESC shadowMapDesc;
ZeroMemory( &shadowMapDesc, sizeof( shadowMapDesc ) );
shadowMapDesc.AddressU = D3D11_TEXTURE_ADDRESS_BORDER;
shadowMapDesc.AddressV = D3D11_TEXTURE_ADDRESS_BORDER;
shadowMapDesc.AddressW = D3D11_TEXTURE_ADDRESS_BORDER;
shadowMapDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
shadowMapDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
shadowMapDesc.MaxLOD = D3D11_FLOAT32_MAX;
//shadowMapDesc.BorderColor[3] = 1.0f;
result = device->CreateSamplerState( &shadowMapDesc, &samplerF );
if( FAILED( result ) )
{
...
}
result = device->CreateSamplerState( &shadowMapDesc, &samplerB );
if( FAILED( result ) )
{
...
}
//Depth-stencil
D3D11_TEXTURE2D_DESC texDesc;
ZeroMemory(&texDesc,sizeof(texDesc));
texDesc.Width = SM_DP_SIZE;
texDesc.Height = SM_DP_SIZE;
texDesc.MipLevels = 1;
texDesc.ArraySize = 1;
texDesc.Format = DXGI_FORMAT_D32_FLOAT;
texDesc.SampleDesc.Count = 1;
texDesc.SampleDesc.Quality = 0;
texDesc.Usage = D3D11_USAGE_DEFAULT;
texDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
texDesc.CPUAccessFlags = 0;
texDesc.MiscFlags = 0;
//depth-stencil texture
result = device->CreateTexture2D( &texDesc, NULL, &tDepthTexture );
if( FAILED( result ) )
{
...
}
D3D11_DEPTH_STENCIL_VIEW_DESC dDSV;
ZeroMemory(&dDSV,sizeof(dDSV));
dDSV.Format = DXGI_FORMAT_D32_FLOAT;
dDSV.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
dDSV.Texture2D.MipSlice = 0;
result = device->CreateDepthStencilView( tDepthTexture, &dDSV, &DSVShadowMap );
if( FAILED( result) )
{
...
}
//Both depth textures
texDesc.Format = DXGI_FORMAT_R32_FLOAT;
texDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
result = device->CreateTexture2D( &texDesc, NULL, &tShadowTextureF);
if( FAILED( result ) )
{
...
}
result = device->CreateTexture2D( &texDesc, NULL, &tShadowTextureB);
if( FAILED( result ) )
{
...
}
//Shader Resource View
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
ZeroMemory( &srvDesc, sizeof( srvDesc ) );
srvDesc.Format = DXGI_FORMAT_R32_FLOAT;
srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
srvDesc.TextureCube.MipLevels = 1;
srvDesc.TextureCube.MostDetailedMip = 0;
//Shadow maps as shader resources
result = device->CreateShaderResourceView( tShadowTextureF, &srvDesc, &SRVShadowMapF);
if( FAILED( result ) )
{
...
}
result = device->CreateShaderResourceView( tShadowTextureB, &srvDesc, &SRVShadowMapB);
if( FAILED( result ) )
{
...
}
//Render target
D3D11_RENDER_TARGET_VIEW_DESC DescRT;
DescRT.Format = DXGI_FORMAT_R32_FLOAT;
DescRT.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
DescRT.Texture2D.MipSlice = 0;
result = device->CreateRenderTargetView(tShadowTextureF,&DescRT,&RTVShadowMapF);
if( FAILED( result ) )
{
...
}
result = device->CreateRenderTargetView(tShadowTextureB,&DescRT,&RTVShadowMapB);
if( FAILED( result ) )
{
...
}
//const. buffer with light stuff
D3D11_BUFFER_DESC constDesc;
ZeroMemory( &constDesc, sizeof( constDesc ) );
constDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
constDesc.ByteWidth = sizeof( ConstBuff );
constDesc.Usage = D3D11_USAGE_DEFAULT;
constDesc.CPUAccessFlags = 0;
result = device->CreateBuffer( &constDesc, 0, ¶mCB );
if( FAILED( result ) )
{
...
}
//Rasterizer
D3D11_RASTERIZER_DESC rDesc;
ZeroMemory(&rDesc, sizeof(rDesc));
rDesc.FillMode = D3D11_FILL_SOLID;
rDesc.CullMode = D3D11_CULL_BACK;
rDesc.FrontCounterClockwise = FALSE;
rDesc.DepthClipEnable = TRUE;
rDesc.ScissorEnable = FALSE;
rDesc.MultisampleEnable = FALSE;
rDesc.AntialiasedLineEnable = FALSE;
result = device->CreateRasterizerState(&rDesc,&rasterizerB);
if( FAILED( result ) )
{
...
}
rDesc.CullMode = D3D11_CULL_NONE;
result = device->CreateRasterizerState(&rDesc,&rasterizerN);
if( FAILED( result ) )
{
...
}
lightPos = XMFLOAT3(0.0f,10.0f,0.0f);
return true;
Here is the rendering code:
float clearColor[4] = { 0.0f, 0.0f, 0.25f, 1.0f };
float clearColorSM[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
context->ClearRenderTargetView( defaultRenderTarget, clearColor );
context->ClearDepthStencilView( defaultDSV, D3D11_CLEAR_DEPTH, 1.0f, 0 );
context->IASetInputLayout( inputLayout );
context->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST );
context->VSSetShader( sVShader, NULL, 0 );
context->PSSetShader( sPShader, NULL, 0 );
context->RSSetViewports(1,&lightViewPort);
MatrixBuffer cb1;
cb1.mView = XMMatrixTranspose(XMLoadFloat4x4(&view)); //passed via func. argument
cb1.mProj = XMLoadFloat4x4(&mProjection);
//second buffer with light params
struct ConstBuff cb2;
cb2.nearClip = 0.1f;
cb2.farClip = 50.0f;
cb2.parDirection = 1.0f;
cb2.lightPos = lightPos;
cb2.mSMWorldView = XMMatrixTranspose( XMMatrixLookAtLH(XMLoadFloat3(&lightPos), XMLoadFloat3(&XMFLOAT3(lightPos.x,lightPos.y,lightPos.z+1.0f)), XMLoadFloat3( &XMFLOAT3(0.0f, 1.0f, 0.0f )) ));
//-------------------RENDERING------------------
//-------FIRST PASS - FRONT MAP---------------------------
context->OMSetRenderTargets(1,&RTVShadowMapF, DSVShadowMap);
context->ClearRenderTargetView(RTVShadowMapF, clearColorSM);
context->ClearDepthStencilView( DSVShadowMap, D3D11_CLEAR_DEPTH, 1.0f, 0 );
context->RSSetState(rasterizerB);
for(unsigned int i=0;i<renderMeshes.size();++i)
{
context->UpdateSubresource( paramCB, 0, NULL, &cb2, 0, 0 );
context->UpdateSubresource( matrixCB, 0, NULL, &cb1, 0, 0 );
context->VSSetConstantBuffers(0, 1, &matrixCB );
context->VSSetConstantBuffers(1, 1, ¶mCB );
context->IASetVertexBuffers( 0, 1, &meshes[renderMeshes[i].meshIndex].pVertexBuffer, &meshes[renderMeshes[i].meshIndex].stride, &meshes[renderMeshes[i].meshIndex].offset );
context->IASetIndexBuffer( meshes[renderMeshes[i].meshIndex].pIndexBuffer, DXGI_FORMAT_R32_UINT, 0 );
context->DrawIndexed(meshes[renderMeshes[i].meshIndex].numIndices,0, 0);
}
//------------SECOND PASS - Backmap------------------------
context->OMSetRenderTargets(1, &RTVShadowMapB, DSVShadowMap);
context->ClearRenderTargetView(RTVShadowMapB,clearColorSM);
context->ClearDepthStencilView( DSVShadowMap, D3D11_CLEAR_DEPTH, 1.0f, 0 );
context->RSSetState(rasterizerN); //Vypnutie orezavania
cb2.parDirection = -1.0f;
cb2.mSMWorldView = XMMatrixTranspose( XMMatrixLookAtLH(XMLoadFloat3(&lightPos), XMLoadFloat3(&XMFLOAT3(lightPos.x,lightPos.y,lightPos.z-1.0f)), XMLoadFloat3( &XMFLOAT3(0.0f, 1.0f, 0.0f )) ));
for(unsigned int i=0;i<renderMeshes.size();++i)
{
cb1.mWorld = XMLoadFloat4x4(&renderMeshes[i].worldMat);
context->UpdateSubresource( paramCB, 0, NULL, &cb2, 0, 0 );
context->UpdateSubresource( matrixCB, 0, NULL, &cb1, 0, 0 );
context->VSSetConstantBuffers(0, 1, &matrixCB );
context->VSSetConstantBuffers(1, 1, ¶mCB );
context->IASetVertexBuffers( 0, 1, &meshes[renderMeshes[i].meshIndex].pVertexBuffer, &meshes[renderMeshes[i].meshIndex].stride, &meshes[renderMeshes[i].meshIndex].offset );
context->IASetIndexBuffer( meshes[renderMeshes[i].meshIndex].pIndexBuffer, DXGI_FORMAT_R32_UINT, 0 );
context->DrawIndexed(meshes[renderMeshes[i].meshIndex].numIndices,0, 0);
}
//---------FINAL SCENE------------
context->OMSetRenderTargets(1, &defaultRenderTarget, defaultDSV);
context->ClearDepthStencilView( defaultDSV, D3D11_CLEAR_DEPTH, 1.0f, 0 );
context->RSSetViewports(1,&viewPort);
context->VSSetShader( rVShader, NULL, 0 );
context->PSSetShader( rPShader, NULL, 0 );
//Samplers
context->PSSetSamplers( 0, 1, &samplerF);
context->PSSetSamplers( 1, 1, &samplerB);
//Textures
context->PSSetShaderResources( 0, 1, &SRVShadowMapF );
context->PSSetShaderResources( 1, 1, &SRVShadowMapB );
context->RSSetState(rasterizerB);
//Setting the front view light matrix
cb2.mSMWorldView = XMMatrixTranspose( XMMatrixLookAtLH(XMLoadFloat3(&lightPos), XMLoadFloat3(&XMFLOAT3(lightPos.x,lightPos.y,lightPos.z+1.0f)), XMLoadFloat3( &XMFLOAT3(0.0f, 1.0f, 0.0f )) ));
for(unsigned int i=0;i<renderMeshes.size();++i)
{
cb1.mWorld = XMLoadFloat4x4(&renderMeshes[i].worldMat);
context->UpdateSubresource( matrixCB, 0, NULL, &cb1, 0, 0 );
context->UpdateSubresource( paramCB, 0, NULL, &cb2, 0, 0);
context->VSSetConstantBuffers( 0, 1, &matrixCB );
context->VSSetConstantBuffers( 1, 1, ¶mCB );
context->PSSetConstantBuffers( 1, 1, ¶mCB );
context->IASetVertexBuffers( 0, 1, &meshes[renderMeshes[i].meshIndex].pVertexBuffer, &meshes[renderMeshes[i].meshIndex].stride, &meshes[renderMeshes[i].meshIndex].offset );
context->IASetIndexBuffer( meshes[renderMeshes[i].meshIndex].pIndexBuffer, DXGI_FORMAT_R32_UINT, 0 );
context->DrawIndexed(meshes[renderMeshes[i].meshIndex].numIndices,0, 0);
}
//disconnect render target
context->OMSetRenderTargets(0,NULL,NULL);
//disconnect resources
ID3D11ShaderResourceView* nullViews[2] = {0};//, 0, 0, 0, 0, 0, 0, 0};
context->PSSetShaderResources(0, 2, nullViews);
..and shader code:
cbuffer MatrixBuffer : register(b0)
{
matrix mWorld;
matrix mView;
matrix mProj;
};
//Parametrization buffer
cbuffer ParamBuffer : register(b1)
{
matrix mSMView; //light view matrix
float3 lightPos; //light position
float parDirection; //Shadow map direction
float nearClip; //near clipping plane
float farClip; //far clipping plane
};
//-----------------------Samplers and textures--------------------------
SamplerState shadowSamplerF : register(s0);
SamplerState shadowSamplerB : register(s1);
Texture2D SMFront : register(t0);
Texture2D SMBack : register(t1);
//----------------------------Structs------------------------------
struct VS_INPUT
{
float4 pos : POSITION;
float2 uv : TEXCOORD;
float3 normal : NORMAL;
};
struct PS_INPUT_SHADOW
{
float4 pos : SV_POSITION;
float clipDepth : TEXCOORD1;
float depth : TEXCOORD2;
};
struct PS_INPUT
{
float4 pos : SV_POSITION;
float3 worldPos : TEXCOORD0;
float2 uv : TEXCOORD1;
float3 normal : NORMAL;
};
//---------------------Shadow map generation shaders-----------------------
PS_INPUT_SHADOW VS_S(VS_INPUT input)
{
PS_INPUT_SHADOW Out = (PS_INPUT_SHADOW) 0;
Out.pos = mul(input.pos, mWorld);
Out.pos = mul(Out.pos, mSMView);
Out.pos /= Out.pos.w;
Out.pos.z *= parDirection;
float vecLength = length(Out.pos.xyz);
// normalize
Out.pos /= vecLength;
// save for clipping
Out.clipDepth = Out.pos.z;
//calc "normal" on intersection, by adding the
// reflection-vector(0,0,1) and divide through
// his z to get the texture coords
Out.pos.x /= Out.pos.z + 1.0f;
Out.pos.y /= Out.pos.z + 1.0f;
// set z for z-buffering and neutralize w
Out.pos.z = (vecLength - nearClip) / (farClip - nearClip);
Out.pos.w = 1.0f;
// DP-depth
Out.depth = Out.pos.z;
return Out;
}
float PS_S(PS_INPUT_SHADOW input) : SV_Target
{
clip(input.clipDepth);
return input.depth;
}
//-----------------OUTPUT RENDER--------------------
PS_INPUT VS_R (VS_INPUT input)
{
PS_INPUT Out = (PS_INPUT) 0;
Out.pos = mul(input.pos, mWorld);
Out.worldPos = Out.pos.xyz;
Out.pos = mul(Out.pos, mView);
Out.pos = mul(Out.pos, mProj);
Out.normal = mul(input.normal, mWorld);
Out.uv = input.uv;
return Out;
}
float4 PS_R (PS_INPUT input) :SV_Target
{
float4 viewPos = mul(float4(input.worldPos.xyz,1.0f), mSMView);
float viewLen = length(viewPos);
// normalize
viewPos /= viewLen;
// compute and read according depth
float fSceneDepth = (viewLen - nearClip) / (farClip - nearClip);
float fDPDepth = 0.0f;
if(viewPos.z >= 0.0f)
{
float2 vTexFront;
vTexFront.x = (viewPos.x / (1.0f + viewPos.z)) * 0.5f + 0.5f;
vTexFront.y = 1.0f - ((viewPos.y / (1.0f + viewPos.z)) * 0.5f + 0.5f);
fDPDepth = SMFront.Sample(shadowSamplerF, vTexFront).r;
}
else
{
// for the back the z has to be inverted
float2 vTexBack;
vTexBack.x = (viewPos.x / (1.0f - viewPos.z)) * 0.5f + 0.5f;
vTexBack.y = 1.0f - ((viewPos.y / (1.0f - viewPos.z)) * 0.5f + 0.5f);
fDPDepth = SMBack.Sample(shadowSamplerB, vTexBack).r;
}
// lighting and shadowing
float shadowBias = 0.005f;
float4 ambientColor = float4(0.05f, 0.05f, 0.05f, 1.0f);
float4 diffuseColor = float4(0.7f, 0.7f, 0.7f, 1.0f);
float3 lVec = input.worldPos.xyz - lightPos;
float shadowFactor = (fDPDepth + shadowBias) >= fSceneDepth;
float L = saturate(dot(normalize(input.normal),normalize(-lVec)));
return saturate(ambientColor + shadowFactor*L*diffuseColor);
}
I'm a DX beginner, so if You see something "stupid" in my code, just let me know. Thanks a lot ;)
- Home
- » Viewing Profile: Posts: stgFX

Find content