Volumes Of Fun
http://www.volumesoffun.com/phpBB3/

Generate Normals in shader
http://www.volumesoffun.com/phpBB3/viewtopic.php?f=2&t=292
Page 1 of 1

Author:  Will Smith [ Thu Dec 01, 2011 9:22 am ]
Post subject:  Generate Normals in shader

Since switching to the CubicSurfaceExtractor from CubicSurfaceExtractorWithNormals
I have been having a lot of issues getting normals calculated through shaders.

I have searched every post in this forum and googled many variations of questions relating to this. No matter what I try shader wise I can't seem to get normals to calculate.

I am using vertex colouring instead of texturing each voxel and I need normals strictly for lighting.

So I should calculate the shaders like shown below in the _FP and then generate lighting before exiting the _FP?
Code:
float3 worldNormal = cross(ddy(inWorldPosition.xyz), ddx(inWorldPosition.xyz));
worldNormal = normalize(worldNormal);


Going to keep plugging away at it but I would appreciate any insight on what my pitfalls might be :)

Author:  beyzend [ Sat Dec 03, 2011 12:15 am ]
Post subject:  Re: Generate Normals in shader

Hard to say, your snippet looks correct tho. You may want to post the entire shader code if it's not too large.

Also, I suggest coloring your blocks with the normal to visually debug it.

Author:  Will Smith [ Sat Dec 03, 2011 4:40 am ]
Post subject:  Re: Generate Normals in shader

I can get the normals working to project textures through a shader.
But I think I'm using the wrong semantics for what I want to achieve.

I'll keep playing around with it and post what I have soon if I can't figure it out.

Author:  David Williams [ Sat Dec 03, 2011 7:16 pm ]
Post subject:  Re: Generate Normals in shader

[quote="Will Smith"]I can get the normals working to project textures through a shader.[quote]

Can you elaborate on the problem? You mean the normals work for projective texturing but not for lighting?

At any rate, as beyzend says you should debug it by mapping the normals to colours. So take off any texturing, etc and set the RGB value of each fragment to the XYZ value of the normal. Note that negative normals will then be black, so you might want to do some scaling/shifting to adjust this. Then you can 'see' the normal to each surface.

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/