Jump to content

  • Log In with Google      Sign In   
  • Create Account


Lemmi

Member Since 06 Mar 2010
Offline Last Active Jun 22 2013 07:31 AM

Posts I've Made

In Topic: Deferred rendering - Point light attenuation problem

09 December 2012 - 11:27 AM

I don't have answer to your problem but your code seems complicated at some parts:

output.Position = mul(float4(input.Position, 1.0f), World);

could be written as:

output.Position = mul(input.Position, World);

If you define your input.Position as float4. It isn't necessary to provide the 4th component from the program.


float2 texCoord = postProjToScreen(input.LightPosition);
float4 baseColor = textures[0].Sample(pointSampler, texCoord);

Since you are using D3D 10 or 11 that part of the code could be replaced with

int3 Index = int3(input.Position.x,input.Position.,0);
float4 baseColor = textures[0].Load(Index);
float4 normalData = textures[1].Load(Index);


Cheers!


Hi! The input position needs to be casted to a float4 and have an added 1.0f to the last channel, else you get some really weird undefined behaviour unless you re-write the model class vertex struct, which I see no reason to do.

The .Load function thing was neat! Fun to learn about new things. Question: Do you know if this is faster than using the sampler, or if it brings any other advantage?


If I'm going back on the subject, I'm starting to suspect that it actually isn't the attenuation that is the problem, because I've scoured the entire net and tried so many different attenuation methods, and they all have the same problem. It's as if the depth value gets screwed up by my InvertedViewProjection.

This is what I do:

viewProjection = viewMatrix*projectionMatrix;
D3DXMatrixInverse(&invertedViewProjection, NULL, &viewProjection);

Then when I send it into the shader I transpose it. I'm honestly not sure what transposition does, so I'm not sure if it can cause this kind of problem where it screws up my position Z axis when multiplied with it.

Another oddity I found was that when I looked through the code in pix I'd get depth values that were negative, so I'd get -1.001f and other values. This doesn't seem right?

The depth is stored the normal way in the gbuffer pixel shader:
output.Depth = input.Position.z / input.Position.w;

In Topic: Deferred rendering - Point light attenuation problem

08 December 2012 - 08:15 PM

Yeah, I changed it to

position.xy = texCoord.xy;

a while back. It didn't change anything. The reason I had it that way was because I had seen it done like that in some other samples. Pretty much just changing values around and crossing my fingers at this point.

In Topic: Deferred rendering - Point light attenuation problem

08 December 2012 - 07:01 PM

I have to admit, I don't really understand all of the math behind this, so please do assume that the math is wrong, I think that's for the best. I tried what you suggested and it resulted in virtually nothing being rendered whatsoever, but hey, that solved my first problem! ;)

It's uh, hard to explain, but it did render if I had my camera in a very special angle and was looking at it with the edge of my screen.



You are of course right about the division by zero thing, that was silly of me.

In Topic: error C4430: missing type specifier

14 March 2010 - 05:06 AM

fixed it, thank you very much! Was fully expecting it to be something complicated. =)

EDIT: I found a new error, this is really baffling me because I can't see what's wrong.


// loop through all objects in list
for (UINT i=0; i<(*pC); i++)
if (ppLob[i] == pLob) break;

// did we find the one we came for?
if (i>=(*pC)) return; <--- Error appears here.

SAFE_DELETE(ppLob[i]);


and I keep on getting "error C2065: 'i' : undeclared identifier"

I tried putting an int i but it doesn't help. Tried about 5 different combinations but it just doesn't want to compile without errors.

[Edited by - Lemmi on March 14, 2010 11:06:13 AM]

PARTNERS