solvespace / solvespace

Parametric 2d/3d CAD
http://solvespace.com/
GNU General Public License v3.0
3.21k stars 483 forks source link

Update shader to PBR - "Black" color always shown flat #1217

Open ghost opened 2 years ago

ghost commented 2 years ago

System information

Expected behavior

Redesign color implementation and diffuse shading in rendering (OpenGL shader).

Solids with "Black" color (0, 0, 0) should NOT look 'flat' if "ambient lightning" < 1.0.

Actual behavior

Actually "Black" color (0, 0, 0) always looks fully 'flat', even "ambient lightning" = 0.1:

Additional information

REFERENCE:

phkahler commented 2 years ago

All shading in Solvespace is done using nothing more than Snell's law (diffuse) with 2 lights and ambient. Black will just be black because the lighting model is so simple. I did some experiments on one of my branches to implement a more realistic lighting model including the Fresnel term which tends to highlight silhouette edges better and it looked a little better. It's hard to validate that the math is right so I've been tagging (so I can remember) projects which include a PBR based lighting model and GPLv3 compatible license (please don't offer suggestions). My internal list of stuff includes adding one of these better material/lighting models. I also want to add the ability to overlay a heatmap type coloring for FEA results. So I figure all of that can happen with one deep dive into the shader stuff.

We will not be adding shadows or any other global illumination features. This is a CAD program that does not warrant photo-realistic rendering. There are much more important things to work on for the foreseeable future.

phkahler commented 2 years ago

One option might be this shader.

ghost commented 2 years ago

One option might be this shader.

Good suggestion, but what about OpenGL compatibility for this shader?

We will not be adding shadows or any other global illumination features. This is a CAD program that does not warrant photo-realistic rendering.

Of course, in this "feature request" thread I'm NOT asking for adding photo "realistic shaders" or "shadow" — instead I'm asking for just a little bit better render/shader than actual SolveSpace shader.

It's hard to validate that the math is right so I've been tagging (so I can remember) projects which include a PBR based lighting model and GPLv3 compatible license (please don't offer suggestions).

Only one suggestion (sorry me, please) here is to look on LeoCAD's shaders, which are good enough for CAD & also are GPLv3 compatible:

There are much more important things to work on for the foreseeable future.

Yes, I'm aware of this, but actual "feature request" is long term request, which is not on first priority, BUT is not a last too.

N.B. Also, it still unclear in SolveSpace "Property Browser" and SolveSpace docs what values used for color input: is it RGB, HSV or HSL?

FTR, Only for "background color" in "Property Browser" there is extra note (r, g, b) that is saying that this is RGB input field, BUT user can't input RGB values in form of 0...255:

Evil-Spirit commented 2 years ago

The lighting shader I made is a little bit strange. I can't recall all the details, but it is not regular diffuse. For good-looking black there is needed to introduce reflection component in a lighting model.

Evil-Spirit commented 2 years ago

You can look at shader here https://github.com/solvespace/solvespace/blob/master/res/shaders/mesh.frag

phkahler commented 2 years ago

@Evil-Spirit I looked at the shader to make the ambient term configurable. It's just Snells law plus ambient. By increasing ambient and turning off directional lights we can do flat shading as requested by he who shall not be named.

I also have a branch where I added the fresnel term with some back lighting. It reduces the need to explicitly draw silhouette edges.

A good PBR shader would be great. I've got a repo starred that has a decent shader.

Evil-Spirit commented 2 years ago

as requested by he who shall not be named.

Intoduce me please into this kind of things. Last time I made a mistake and another person waged a twitterwar against me (I was believing this person is "HE", but now is "SHE")