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

Shader wants normals but mesh doesn't have them
http://www.volumesoffun.com/phpBB3/viewtopic.php?f=23&t=548
Page 1 of 1

Author:  Dynasty [ Sun Nov 10, 2013 6:28 am ]
Post subject:  Shader wants normals but mesh doesn't have them

I imported a colored cubes volume from images and attempted to add the SSAO effect to the camera. This error message appears at the bottom of the Unity window:

"Shader wants normals but mesh doesn't have them"

I'm currently evaluating a switch to Unity for my game. I'm using the 30 day trial to check out some of the image effects like SSAO.

Author:  David Williams [ Sun Nov 10, 2013 8:23 am ]
Post subject:  Re: Shader wants normals but mesh doesn't have them

Hmmm... that's interesting. Basically it's correct - we don't generate per-vertex normals for the mesh data because we instead compute them in the fragment shader. But this has only been tested with basic lighting and not with deferred shading or post-processing effects. So perhaps there is a problem here.

As a fallback we could provide the per-vertex normals but it requires duplicating a lot of vertex data, for example a single cube then requires 24 vertices rather than eight.

This will need some investigation and unfortunatly I don't have Unity Pro. I'll probably use my 30-day trial at some point soon so I'll try to look at it then. Until then the bug has been logged here: https://bitbucket.org/volumesoffun/cubi ... oesnt-have

Author:  Dynasty [ Mon Nov 11, 2013 3:41 am ]
Post subject:  Re: Shader wants normals but mesh doesn't have them

David Williams wrote:
Hmmm... that's interesting. Basically it's correct - we don't generate per-vertex normals for the mesh data because we instead compute them in the fragment shader. But this has only been tested with basic lighting and not with deferred shading or post-processing effects. So perhaps there is a problem here.

As a fallback we could provide the per-vertex normals but it requires duplicating a lot of vertex data, for example a single cube then requires 24 vertices rather than eight.

This will need some investigation and unfortunatly I don't have Unity Pro. I'll probably use my 30-day trial at some point soon so I'll try to look at it then. Until then the bug has been logged here: https://bitbucket.org/volumesoffun/cubi ... oesnt-have


Might it be possible to modify the SSAO shader just for testing purposes? Any tips?

I'd like to see if a switch to Unity is viable before my 30 day trial is over :?

Author:  David Williams [ Mon Nov 11, 2013 12:25 pm ]
Post subject:  Re: Shader wants normals but mesh doesn't have them

I have a couple of ideas. Firstly, you might find that it actually works despite the error message. Unity assumes that there are no surface normals because they are not contained in the vertex data, but it has no way of knowing that they are actually being generated in the fragment shader. They are still being written to the 'Normal' attribute of the 'SurfaceOutput' structure.

Have a look at our shader here. Note that the vertex shader creates dummy values for the normal and tangents. We had a similar error with 'Shader wants tangents but the mesh doesn't have them' and this fixed it. The actual normal is computed in the first line of the fragment shader, and we never compute or use the tangents.

I don't know how the SSAO system in Unity works, but maybe you can tweak the shader code with something similar. Or maybe it needs to know about the Cubiquity custom vertex shader?

Lastly, you can probably create real vertex normals with Mesh.RecalculateNormals(). However, they will be smoothed normals and won't match the ones which our shader computes. Not sure how much that matters for SSAO. This function call could be added to the 'BuildMeshFromNodeHandle' function in the ColoredCubesVolume (be aware that the TerrainVolume has this function too, so get the right one).

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