Vertex colours without phong lighting
Vertex colours without phong lighting
Is there a way to just display vertex colour without having the phong lighting applied to it on polygons. I can switch off the specular component by seting the coefficient to zero. But even when I switch the diffuse coefficient to zero I still get lighting. I assume that this has no effect as soon as you have vertex colours set on your geometry. What I would like is that the vertex colours act just as an ambient colour.
It is possible to disable lighting calculations using the rendering hint "lightingEnabled". (Currently only the JOGL backend implements this directive.)
The simplest way to set this for the scene graph rooted at the SceneGraphComponent sgc is:
To use shader interfaces for the same effect:
For an introduction to appearance attributes and shader interfaces, see the
jReality Developer Tutorial specifically the introductory tutorial. Also in the current jReality svn repository look under src-tutorial folder, package de.jreality.tutorial.app examples.
The simplest way to set this for the scene graph rooted at the SceneGraphComponent sgc is:
Code: Select all
Appearance ap = sgc.getAppearance();
ap.setAttribute(CommonAttributes.LIGHTING_ENABLED, false);
Code: Select all
Appearance ap = sgc.getAppearance();
RenderingHintsShader rhs = ShaderUtility.createDefaultRenderingHintsShader(ap, true);
rhs.setLightingEnabled(false);
jReality Developer Tutorial specifically the introductory tutorial. Also in the current jReality svn repository look under src-tutorial folder, package de.jreality.tutorial.app examples.
jReality core developer
So if I understood you correctly, the JOGL backend is the only backend where this setting will have an effect on?
Hmm that's not good I run in a heterogeneous environment some machines will have JOGL/OpenGL/hardware some unfortunately will not have.
In this case I might have to do some modification to the software backend if there is no other way!
Hmm that's not good I run in a heterogeneous environment some machines will have JOGL/OpenGL/hardware some unfortunately will not have.
In this case I might have to do some modification to the software backend if there is no other way!
Hi gunn,
I made some modifications to the software backend and it now acknowledges the lightingEnabled attribute. To do this I just had to do some minor changes:
in de.jreality.shader.DefaultPolygonShader (trunk/src-core/de/jreality/shader) I added this field
final static boolean LIGHTING_ENABLED_DEFAULT = true;
and these two methods
void setLightingEnabled(Boolean light);
Boolean getLightingEnabled();
and in DefaultVertexShader.java (trunk/soft-new/de/jreality/softviewer/shader)
I changed the constructor from:
public DefaultVertexShader(Color c, double phong, double phongSize, double transparency) {
to
public DefaultVertexShader(Color c, double phong,
double phongSize,
double transparency,
boolean lighting)
added a new field
private boolean useLighting = true;
and set that in the new constructor above
then in its shadeVertex method I check on the state of the field and jump over the whole lighting calculation if useLighting is false. Better would be to refactor that function into several functional blocks.
And finally I changed the call to the constructor of DefaultVertexShader in DefaultPolygonShader (trunk\src-soft-new\de\jreality\softviewer\shader) from
vertexShader = new DefaultVertexShader(ps.getDiffuseColor()(),ps.getSpecularColor(),ps.getSpecularCoefficient(),ps.getSpecularExponent(),ps.getTransparency()) to
vertexShader = new DefaultVertexShader(ps.getDiffuseColor()(),ps.getSpecularColor(),ps.getSpecularCoefficient(),ps.getSpecularExponent(),ps.getTransparency(),ps.getLightingEnabled())
and that's all. It works! :D
Btw I noticed that the line intending on a lot of the source files is totally inconsistent which makes it a very awkward to read the code.
I made some modifications to the software backend and it now acknowledges the lightingEnabled attribute. To do this I just had to do some minor changes:
in de.jreality.shader.DefaultPolygonShader (trunk/src-core/de/jreality/shader) I added this field
final static boolean LIGHTING_ENABLED_DEFAULT = true;
and these two methods
void setLightingEnabled(Boolean light);
Boolean getLightingEnabled();
and in DefaultVertexShader.java (trunk/soft-new/de/jreality/softviewer/shader)
I changed the constructor from:
public DefaultVertexShader(Color c, double phong, double phongSize, double transparency) {
to
public DefaultVertexShader(Color c, double phong,
double phongSize,
double transparency,
boolean lighting)
added a new field
private boolean useLighting = true;
and set that in the new constructor above
then in its shadeVertex method I check on the state of the field and jump over the whole lighting calculation if useLighting is false. Better would be to refactor that function into several functional blocks.
And finally I changed the call to the constructor of DefaultVertexShader in DefaultPolygonShader (trunk\src-soft-new\de\jreality\softviewer\shader) from
vertexShader = new DefaultVertexShader(ps.getDiffuseColor()(),ps.getSpecularColor(),ps.getSpecularCoefficient(),ps.getSpecularExponent(),ps.getTransparency()) to
vertexShader = new DefaultVertexShader(ps.getDiffuseColor()(),ps.getSpecularColor(),ps.getSpecularCoefficient(),ps.getSpecularExponent(),ps.getTransparency(),ps.getLightingEnabled())
and that's all. It works! :D
Btw I noticed that the line intending on a lot of the source files is totally inconsistent which makes it a very awkward to read the code.
It sounds like you found the right place to enable this feature. The author of the software backend is living in Munich so it's sometimes difficult to contact him.
Can you clarify this? I'm not sure what "line intending" means.Btw I noticed that the line intending on a lot of the source files is totally inconsistent which makes it a very awkward to read the code.
jReality core developer
It just hit me: "line intending" = "line indenting". Yes, you are right. That's probably been the ruin of many software projects. Everyone has their favorite indenting style which is synchronized with their private settings for the IDE they use (I think we all use Eclipse here) and so reading or editing code written by others can be a difficult task.
jReality core developer
Yes sorry for the typo. I am not so extremly familair with Eclipse so far the exposures I had with it haven't left the best impression on me. But I think sometimes they seem to be tabs and sometimes they are whitespaces. It would be helpful to stick to either so at least it will stay sort of consistent even when you use other text editors or IDEs. Not sure if you can set that in Eclipse. Otherwise I think remember seeing that Eclipse has an auto formatter in it to make formating consistent.gunn wrote:It just hit me: "line intending" = "line indenting". Yes, you are right. That's probably been the ruin of many software projects.
These are minor things but they can help a lot.so reading or editing code written by others can be a difficult task.
O.K. finally I manage to say something.
I checked in some changes to the software backend that enable support for the lighting Enabled rendering hint.
There was a ConstantvertexShader in the soft backend which does the job in principle, but to optimize a little more the software backend now has a ConstantPolygonShader again that will be used if lighting is disabled. It should also work with textures and reflection maps.
Please let me know if there are any problems with it.
The advantage with this solution compared to an extra flag in the DefaultVertexShader as described by STRESS above, is that the Shader can tell the rasterizer, that it does not need to interpolate the color in the triangles and that the (trivial) lighting needs only be done once in a polygon.
On a sidenote I find it a little unfortunate that the three principal lighting choices smooth/flat/constant (=no lightling) are set at two different places at the moment. A while a go it used to be setting the corresponding shader. Now one chooses smooth/flat in the DefaultPolygonShader but the constant shading via a rendering hint. Having it in the rendering hints does make it impossible to set lighting to false for the tubes of the LineShader only for example - I think.
best
Tim
I checked in some changes to the software backend that enable support for the lighting Enabled rendering hint.
There was a ConstantvertexShader in the soft backend which does the job in principle, but to optimize a little more the software backend now has a ConstantPolygonShader again that will be used if lighting is disabled. It should also work with textures and reflection maps.
Please let me know if there are any problems with it.
The advantage with this solution compared to an extra flag in the DefaultVertexShader as described by STRESS above, is that the Shader can tell the rasterizer, that it does not need to interpolate the color in the triangles and that the (trivial) lighting needs only be done once in a polygon.
On a sidenote I find it a little unfortunate that the three principal lighting choices smooth/flat/constant (=no lightling) are set at two different places at the moment. A while a go it used to be setting the corresponding shader. Now one chooses smooth/flat in the DefaultPolygonShader but the constant shading via a rendering hint. Having it in the rendering hints does make it impossible to set lighting to false for the tubes of the LineShader only for example - I think.
best
Tim
I agree with the sentiment and would favor adding "lightingEnabled" as an attribute to the default polygon shader. It could also be added to the default line shader (see this tutorial, at bottom.)
The original reason it was put into the rendering hints shader, if I remember correctly, was that putting it into the default polygon shader would overlap with the "constant" polygon shader. I prefer having a single multi-purpose polygon shader that can handle the features once relegated separately to the default, flat and constant shaders.
The original reason it was put into the rendering hints shader, if I remember correctly, was that putting it into the default polygon shader would overlap with the "constant" polygon shader. I prefer having a single multi-purpose polygon shader that can handle the features once relegated separately to the default, flat and constant shaders.
jReality core developer