boberfly / GafferCycles

Cycles for Gaffer
BSD 3-Clause "New" or "Revised" License
84 stars 10 forks source link

Incorrect render result. Maybe because of FaceVarying normals? #48

Open evantryan opened 4 years ago

evantryan commented 4 years ago

I'm not entirely sure if this should be an issue. I'm getting a warning...

WARNING : MeshAlgo : Variable "N" has unsupported interpolation type - not generating normals.

when rendering with cycles. Unfortunately, the render result is also incorrect.

I've seen in other threads that this is because cycles doesn't support FaceVarying Normals. I've also seen a mention of using a MeshType node to get the correct results. I have been unable to find a combination of options in that node to get correct sharp normals.

I've included a simplified gaffer file along with some cache files (just a cube) from blender, maya and gaffer (in case it had to do with where the alembic came from). The gaffer file has a cycles set up and an appleseed set up for comparison. I've also included a cycles render from blender to show what the expected render would look like.

Is this a bug? If not, is there a way to get the cycles result in gaffer to look like the result from blender?

Thank you so much for working on GafferCycles!

example of the issue from gaffer cycles... test_cycles

example of expected result from blender cycles... test_cycles_blender

gaffer appleseed render for comparison... test_appleseed

example gaffer scene and supporting alembic caches... example_files.zip

boberfly commented 4 years ago

Hi @evantryan Yep Cycles doesn't support FaceVarying out of the box and Blender/Cycles is really tagging at a per-face level whether or not to 'smooth' it which doesn't convert very well to how Cortex/Gaffer conveys the data. It's a fairly non-trivial thing to solve other than patching Cycles itself to support 'Corner' normals ('FaceVarying' is 'Corner' in Cycles-speak) or splitting the vertices so that they can have unique normals, but this would require some complex conversion code.

One thing I could support is either a constant or uniform (whole object or per-face) smooth/hard boolean primvar which could at least set hard/smooth this way, but that would require setting this manually.

boberfly commented 4 years ago

Semi-fixed here: https://github.com/boberfly/GafferCycles/commit/891da2438ad5626933588b27d08e134b2713ad2b

This should match the Blender way of setting hard/smooth normals. What you'll need to do is create a PrimitiveVariables node and make a constant boolean named "_smooth" to set what you want.

Next build should have this. Cheers!

evantryan commented 4 years ago

@boberfly That is awesome! Thank you! Should this be a checkbox in the CyclesAttribute node? Thanks again!

boberfly commented 4 years ago

Due to how it could be constant or uniform it is a primitive variable rather than an attribute, but perhaps for the constant case it could also be set as an attribute as an alternative way...