Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 21 Dec 2012
Offline Last Active Mar 10 2013 08:58 AM

Posts I've Made

In Topic: BlendState during Lighting Pass

12 January 2013 - 09:53 AM

Can't believe it, sorry for the troubles.

Basically I was executing the wrong shader still the pointlight shader... Totally stressed because of coursework... thanks for the advice :)

In Topic: Texture2D Load only returns red channel

11 January 2013 - 04:13 AM

Oh god can't believe I didn't notice that! Thank you so much!

In Topic: Texture2D Load only returns red channel

11 January 2013 - 04:09 AM

I am totally confused right now when I use sample the screen is simply red, but the general problem persists.


Why is Load only returning the red value?


the color variable always just receives the red value and the rest are underscores in pix...


The shader with vertex shader

float4 VSMain(in float3 Position : POSITION) : SV_Position 
	return float4(Position, 1.0f); 

float PSDisabledMain(in float4 screenPos : SV_Position) : SV_Target0 
	//BackBufferMap.Sample(TexureSampler, screenPos.xy);
	int3 sampleIndices = int3(screenPos.xy, 0);
	float4 color = BackBufferMap.Load(sampleIndices);
	return color;



The vertices used:


glm::vec3 vertices[] =
	glm::vec3(-1.0f, -1.0f,  0.0f),
	glm::vec3(-1.0f,  1.0f,  0.0f),
	glm::vec3( 1.0f, -1.0f,  0.0f),
	glm::vec3( 1.0f,  1.0f,  0.0f),


The vertices and Load function is simply the same I am using in my deferred rendering shaders...


And here's how I create the backbuffer:


	D3D11_TEXTURE2D_DESC backTextureDesc;
	D3D11_RENDER_TARGET_VIEW_DESC backTargetViewDesc;
	D3D11_SHADER_RESOURCE_VIEW_DESC backResourceViewDesc;

	ZeroMemory(&backTextureDesc, sizeof(backTextureDesc));
	backTextureDesc.Width = width;
	backTextureDesc.Height = height;
	backTextureDesc.MipLevels = 1;
	backTextureDesc.ArraySize = 1;
	backTextureDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
	backTextureDesc.SampleDesc.Count = 1;
	backTextureDesc.Usage = D3D11_USAGE_DEFAULT;
	backTextureDesc.CPUAccessFlags = 0;
	backTextureDesc.MiscFlags = 0;

	HR(m_d3dDevice->CreateTexture2D(&backTextureDesc, NULL, &m_BackTargetTexture));
	backTargetViewDesc.Format = backTextureDesc.Format;
	backTargetViewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
	backTargetViewDesc.Texture2D.MipSlice = 0;

	HR(m_d3dDevice->CreateRenderTargetView(m_BackTargetTexture, &backTargetViewDesc, &m_BackTargetView));

	backResourceViewDesc.Format = backTextureDesc.Format;
	backResourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
	backResourceViewDesc.Texture2D.MostDetailedMip = 0;
	backResourceViewDesc.Texture2D.MipLevels = 1;

	HR(m_d3dDevice->CreateShaderResourceView(m_BackTargetTexture, &backResourceViewDesc, &m_BackResourceView));

In Topic: Deferred Rendering Problem

24 December 2012 - 11:43 AM

You are right, thanks alot for all the help, I am successfully rendering loads of pointlight, spotlight etc. now... Best christmas present so far :)

In Topic: Deferred Rendering Problem

24 December 2012 - 03:41 AM

Thanks alot indeed I forgot to set the VertexBuffer and since the vertices of my cube are quite similar, I didn't notice that. Can't believe I haven't noticed that...

The only thing left now is a bug in my lighting code, some surfaces stay black... The scene currently uses a single directional light for testing!
float3 CalcLighting(in float3 normal, in float3 position, in float3 diffuseAlbedo, in float3 specularAlbedo, in float specularPower, uniform int gLightingMode) 
float3 L = 0; 
float attenuation = 1.0f; 
if (gLightingMode == POINTLIGHT || gLightingMode == SPOTLIGHT)
L = LightPos - position; 
float dist = length(L); 
attenuation = max(0, 1.0f - (dist / LightRange.x)); 
L /= dist;
else if (gLightingMode == DIRECTIONALLIGHT)
L = -LightDirection; }if (gLightingMode == SPOTLIGHT)
float3 L2 = LightDirection; 
float rho = dot(-L, L2); 
attenuation *= saturate((rho - SpotlightAngles.y) / (SpotlightAngles.x - SpotlightAngles.y)); 
float nDotL = saturate(dot(normal, L)); 
float3 diffuse = nDotL * LightColor * diffuseAlbedo;
float3 V = CameraPos - position; 
float3 H = normalize(L + V);
float3 specular = pow(saturate(dot(normal, H)), specularPower) * LightColor * specularAlbedo.xyz * nDotL; 
return (diffuse + specular) * attenuation;
The basic algorithm is basically out of a book so I assumed there would be nothing wrong the only thing I changed is using if and a uniform to embed it in an effects file.

The Buffers are filled with informations and there is nothing missing, these are values of a black pixel that is supposed to have some color:


Lighting Shader Code on pastebin http://pastebin.com/8gbYBLCX, because the code tags seem to be buggy currently either escaping html as well or completly breaking formating