Advertisement

Defered Render output, repeated.

Started by October 29, 2013 08:30 PM
1 comment, last by korvax 11 years, 3 months ago

Hi,

I have the basic for a simple defered render up and running. I render the end result on a "full screen quad" with the output as a ShaderView not sure if this is the best way to do it, if not what is? My problem thought as you can see in the picture, that the result it repeated and not "stretched out". I think this has to do something with the texture or ShaderView.. but I cant find the problem.

This is my Quad.


UINT uFullWidth = 1024;
UINT uFullHeight = 768;
Vertex vertices_fullquad[] = {
{ XMFLOAT3(-1.0f*uFullWidth, 1.0f*uFullHeight, 0.0f), XMFLOAT2(0.0f, 0.0f), XMFLOAT3(0.0f, 1.0f, 0.0f) },
{ XMFLOAT3(1.0f*uFullWidth, 1.0f*uFullHeight, 0.0f), XMFLOAT2(1.0f*uFullWidth, 0.0f), XMFLOAT3(0.0f, 1.0f, 0.0f) },
{ XMFLOAT3(-1.0f*uFullWidth, -1.0f*uFullHeight, 0.0f), XMFLOAT2(0.0f, 1.0f*uFullHeight), XMFLOAT3(0.0f, 1.0f, 0.0f) },
{ XMFLOAT3(1.0f*uFullWidth, -1.0f*uFullHeight, 0.0f), XMFLOAT2(1.0f*uFullWidth, 1.0f*uFullHeight), XMFLOAT3(0.0f, 1.0f, 0.0f) },
};

TArray<WORD> waLightIndices;
quad_indices.add(0); quad_indices.add(1); quad_indices.add(3); quad_indices.add(0); quad_indices.add(2); quad_indices.add(3);

RenderTarget Texture


	ID3D11Texture2D* pTexture = nullptr;
	// Create a render target view
	D3D11_TEXTURE2D_DESC descTarget;
	ZeroMemory(&descTarget, sizeof(descTarget));
	descTarget.Width = uWidth;
	descTarget.Height = uHeight;
	descTarget.MipLevels = 1;
	descTarget.ArraySize = 1;
	descTarget.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
	descTarget.SampleDesc.Count = 1;
	descTarget.Usage = D3D11_USAGE_DEFAULT;
	descTarget.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
	descTarget.CPUAccessFlags = 0;
	descTarget.MiscFlags = 0;
	HRESULT hr = m_pDevice->CreateTexture2D(&descTarget, nullptr, &pTexture);

ShaderView


	pTexture->GetDesc(&descTarget);
	D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
	srvDesc.Format = descTarget.Format;
	srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
	srvDesc.Texture2D.MostDetailedMip = 0;
	srvDesc.Texture2D.MipLevels = 1;

Light-Shader


//----------------------------------------------------------------------------------------------
Texture2D txDiffuse : register(t0);
Texture2D txNormal : register(t1);
Texture2D txDepth : register(t2);
Texture2D txSpecular : register(t3);
//----------------------------------------------------------------------------------------------
SamplerState samLinear0 : register( s0 );
SamplerState samLinear1 : register( s1 );
SamplerState samLinear2 : register( s2 );
SamplerState samLinear3 : register( s3 );
//----------------------------------------------------------------------------------------------
cbuffer cbLight : register(b0)
{
	float4 lightDirection;
	float4 lightColor;
	float4 lightRange;	
}
//---------------------------------------------------------------------------------------------------------------------
struct PS_INPUT
{
  float4 position	 : SV_POSITION;
  float2 texcoord	 : TEXCOORD0;	
	};
//---------------------------------------------------------------------------------------------------------------------
float4 main(PS_INPUT input) : SV_Target
{
	float4 diffuse = txDiffuse.Sample(samLinear0, input.texcoord);
	float4 normal = txNormal.Sample(samLinear1, input.texcoord);
	float4 depth = txDepth.Sample(samLinear2, input.texcoord);   //Not used currently
	float4 specular = txDepth.Sample(samLinear3, input.texcoord); //Not used currently
	float irradiance = saturate(dot(normal, -lightDirection));
	return lightColor*irradiance*diffuse;
}

G-Buffer


Texture2D txDiffuse : register( t0 );
SamplerState samLinear : register( s0 );
cbuffer cbPerObject : register(b0)
{
	float4 diffuse;
	float4 specular;
	bool isTextured;	
}

//--------------------------------------------------------------------------------------
struct PS_INPUT
{
  float4 position	 : SV_POSITION;
  float2 texcoord	 : TEXCOORD0;	
  float4 normal          : NORMAL;
};
//--------------------------------------------------------------------------------------
struct PSOutput
{
  float4 Color    : SV_Target0;
  float4 Normal   : SV_Target1;	
  float4 Depth    : SV_Target2;
  float4 Specular : SV_Target3;
	
};
//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------
PSOutput main(PS_INPUT input)  
{
	PSOutput output;
	output.Color = diffuse*txDiffuse.Sample(samLinear, input.texcoord);
	output.Normal = normalize(input.normal);
	output.Specular = specular;
	output.Depth =  input.position.z / input.position.w;
	return output;
}

Hello,

I am a beginner, but look like you got your quad's UV wrong?


Vertex vertices_fullquad[] = {
{ XMFLOAT3(-1.0f*uFullWidth, 1.0f*uFullHeight, 0.0f), XMFLOAT2(0.0f, 0.0f), XMFLOAT3(0.0f, 1.0f, 0.0f) },
{ XMFLOAT3(1.0f*uFullWidth, 1.0f*uFullHeight, 0.0f), XMFLOAT2(1.0f*uFullWidth, 0.0f), XMFLOAT3(0.0f, 1.0f, 0.0f) },
{ XMFLOAT3(-1.0f*uFullWidth, -1.0f*uFullHeight, 0.0f), XMFLOAT2(0.0f, 1.0f*uFullHeight), XMFLOAT3(0.0f, 1.0f, 0.0f) },
{ XMFLOAT3(1.0f*uFullWidth, -1.0f*uFullHeight, 0.0f), XMFLOAT2(1.0f*uFullWidth, 1.0f*uFullHeight), XMFLOAT3(0.0f, 1.0f, 0.0f) },
};

Shouldn't it be like this?


Vertex vertices_fullquad[] = {
{ XMFLOAT3(-1.0f*uFullWidth, 1.0f*uFullHeight, 0.0f), XMFLOAT2(0.0f, 0.0f), XMFLOAT3(0.0f, 1.0f, 0.0f) },
{ XMFLOAT3(1.0f*uFullWidth, 1.0f*uFullHeight, 0.0f), XMFLOAT2(1.0f, 0.0f), XMFLOAT3(0.0f, 1.0f, 0.0f) },
{ XMFLOAT3(-1.0f*uFullWidth, -1.0f*uFullHeight, 0.0f), XMFLOAT2(0.0f, 1.0f), XMFLOAT3(0.0f, 1.0f, 0.0f) },
{ XMFLOAT3(1.0f*uFullWidth, -1.0f*uFullHeight, 0.0f), XMFLOAT2(1.0f, 1.0f), XMFLOAT3(0.0f, 1.0f, 0.0f) },
};
Advertisement

Hi,

yes i think so.. long night yesterday. Thx for you help NMPTH

This topic is closed to new replies.

Advertisement