[solved] PointLight renders as HalfSphere

Started by
14 comments, last by majorbrot 11 years, 9 months ago
You're missing that you're calling normalize() on these encoded [0-1] vectors, and that's not doing what you want.

Keep everything in its natural [-1,1] form until just before you write it to the render target, then deencode it on the other end when you read it from the texture
Advertisement

I can't store values in [-1,1] range in a Texture, so i transform it and bring it back in [-1,1] in the other effect. Or am i missing something?
The part where you decode your normal maps back to the [-1,1] range is the "[font=courier new,courier,monospace]// * 2.0 - 1.0;[/font]" part of your code, which you've commented out for some reason? As above, when you call normalize on these [0,1] range (packed) normals, you're destroying them. You should be doing all your normal math with values in the [-1,1] range, not the compressed [0,1] range.

Also, you're not performing a tangent-space rotation on your normal-map values and are just averaging them with the vertex normal, this means that you're not using tangent-space normal map textures (where blue points out of a flat surface), and are actually using object-space normal maps (where blue is +Z, regardless of surface orientation).

If the Y-axis is up in your engine, and you're using blue-ish normal maps, then your code is going to produce a normal that's facing sideways (tangential to your plane) instead of sticking up out of the plane, which explains your image.

Also, you're not performing a tangent-space rotation on your normal-map values


Indeed. I would eliminate sampling from normal map textures for now and get your lighting working with vertex normals first. You have a bit more work to do before you can use normal maps (assuming you're using tangent-space normal maps).
I think so too... I just commented out the stuff with normalmaps, for now it's working, although it seems to be a bit hacky, because i have to take the negative normal from the vertex. So i try figuring out, what that is, then i can go a step further and try the normal mapping. For now all NormalCalculations are done on the CPU, but is there an easy way of doing it on the GPU? I'm relatively new to this, so theres a lot to learn ;)

Thanks a lot, you really helped me out.

because i have to take the negative normal from the vertex.



I'm going to guess that your normals are in one space, and your lighting is being done in another space. Are you doing your light calculation in world space? If so, did you transform your normal into world space from (presumably) object space? Or maybe you have an up-axis wrong in some context. Or maybe your light direction vector is pointing in the wrong direction (if you're trying to calculate "N dot L", L should point from the surface to the light)



For now all NormalCalculations are done on the CPU, but is there an easy way of doing it on the GPU? I'm relatively new to this, so theres a lot to learn ;)



Depends. What do you mean by "NormalCalculations" ?
the light calculations are all done in worldspace, so i have a vector for the directional light, that is not transformed in any way and the normals from the terrain arent either, they're just passed from vertex to pixelshader.

With the NdotL thing you mean that technically the sunlight points up? than that seems to be wrong, i thought it would be just the "right direction".

With normalCalculation i mean calculating the vertexNormals from the terrain. now they are calculated when the terrain is created and recalculated when it changes, and are then passed as vertexData. my question was, if it is possible to calculate them in the vertexshader. if i remember correct, i read somewhere that this could be done, but i dont know how, because you dont have access to the neighboring vertices.

thanks, all this stuff makes me feel so newbish again...

Edit: i think the calculation in the vertexShader could be done if i had a heightmap. But thats missing, so i see no chance beside generating one.

EditEdit: Got the NormalMapping working, looks good to me:
dsnobug.png

thank you again, it helped me so much.

This topic is closed to new replies.

Advertisement