Specular effects on textures?

When I have non textured object, I get good specular effect that disappears when I add a texture to the object. Can someone help me how to create high gloss texture objects or point me to sampel code that does that.


I think this is the problem that I have, can someone address how is (or it is not) this implemented in jME?





21.040 Lighting and texture mapping work pretty well, but why don't I see specular highlighting?



Your geometry may have a nice white specular highlight when it's not texture mapped, but when you apply a non-white texture suddenly the highlight goes away even though the geometry is still lit. This is because GL_MODULATE multiplies the primitive's lighting color components with the texture color components. For example, assume a white specular highlight is being multiplied by a red texture map. The final color is then (1.01.0, 1.00.0, 1.0*0.0) or (1.0, 0.0, 0.0), which is red. The white specular highlight isn't visible.



OpenGL 1.2 solves this problem by applying specular highlights after texture mapping. This separate specular lighting mode is turned on by:



glLightModel (GL_LIGHT_MODEL_COLOR_CONTROL,GL_SEPARATE_SPECULAR_COLOR);

By default, it's set to GL_SINGLE_COLOR, which maintains backwards compatibility with OpenGL 1.1 and earlier.



If you're not using OpenGL 1.2, other solutions are available. Many vendors provide proprietary extensions for allowing you to apply the specular highlight after the texture map. See this example code for how to do this on HP systems. Many OpenGL vendors have settled on an the EXT_separate_specular_color extension.



Another method works on any OpenGL implementation, because it only uses regular OpenGL 1.0 functionality and doesn't depend on extensions. You need to render your geometry in two passes: first with normal lighting and texture mapping enabled, then the second pass will render the specular highlight. See this example code for a demonstration of how to do it.



The text above is from here:

http://www.opengl.org/resources/faq/technical/texture.htm




Well, I am responding to my own question (isn't that stupid) :



Separate specular is implemented in jME. To enable separate specular on textured objects, set setSeparateSpecular(true) on the light state.


Did that also solve your problem?

thanks for the tip, my models are shiny now :smiley:

Hmm, I'm still keep missing something… setSecparateSpecular() alone

doesn't do anything here for me… Still no hightlighting (while otherwise lit correctly)… Any ideas?

oliver1974 said:

Hmm, I'm still keep missing something... setSecparateSpecular() alone
doesn't do anything here for me... Still no hightlighting (while otherwise lit correctly)... Any ideas?



You need to create a light, light state and attach the light state to the main node. This code will make speculars show up.

LightState ls= DisplaySystem.getDisplaySystem().getRenderer().createLightState();
              ls.setSeparateSpecular(true);
              ls.attach( light );
              rootNode.setRenderState(ls);


Stefan

Hmm, I'm sure that i use LightState already… but the inherited instance of one

of the SimpleGame classes…



I will double check that! Thanks!

Hmm, I still can't see a difference…



I added a copper texture to a teapot… if i take screenshotes with and without

SeperateSpecular set, it looks the same to me…



Hmmm, is this graphics-driver dependant?  :?

Hmm, I still can't see a difference...


what model format are you using? I am using .obj models. I just noticed not only am I getting specular lighting I am also getting a huge fps increase with setSeperateSpecular set to true. I get 70+ compared to only 27+ with it set to false. seems strange that adding specular lighting would increase the fps I would think it would decrease. shows how much I know  :P Maybe testObjJmeWrite could be extended to load textured .obj model with specular lighting next to the maggie model to show people this? Im thinking about writing a wiki tut for exporting a simple textured .obj model from wings3d as I dont think there is such a tut yet in the wiki.

edit: I just tested without shadows and am getting 100+ fps with setSeperateSpecular(true) and 30+ fps otherwise.

Well, I'm using the standard "teapot" spatial…



(com.jme.scene.shape.Teapot)



Maybe that's the problem? (Yes, I'm a total JME noob…

I guess that this is a predefined object which therefore cannot get specular lighting?)

It's not that hard to get specular highlights on the teapot.  Edit TestTeapot and add the following to the end of method simpleInitGame():

   

    MaterialState ms = display.getRenderer().createMaterialState();
    ms.setShininess(90);
    ms.setSpecular(ColorRGBA.white);
    rootNode.setRenderState(ms);

    lightState.setSeparateSpecular(true);



(you'll also need to add an import com.jme.scene.state.MaterialState;)

The teapot is not very tessellated, so the specular highlighting will be a bit jaggy, but I think you get the picture.

Yes, multiple renderstates are used to give you a shiny textured material. :)  (Thus my adding material to an already textured teapot in that test code.)



The range of setShininess is 0.0f - 128.0f

hehe jme would be somewhat lacking in usefulness if you had to choose between using a shader, or a texture, or a material, or lighting :slight_smile:

Is there an easy way to set specular on only for some nodes, to get the specular setting on their lighting without having to have a whole new light state? Or should I duplicate the LightState I have on my root Node (without specular) so I can add specular on some of the child nodes?

Well, this would be a teapot without textures, wouldn't it?



We were talking about objects WITH textures and specular highlights…



…oh wait…



What i just realized is, that you can set MULTIPLE renderstates for an object!

So if i set a texture state AND a material state with the right paramters, it works!!



Pure luck i discovered this…:



So this is valid (?):



URL textureLOC = MySpecularLIghtsAnimation.class.getClassLoader().getResource ("helloworld/goblinmetal2.jpg");
Teapot big_teapot = new Teapot("big_teapot");

TextureState ts = display.getRenderer ().createTextureState();
Texture texture = TextureManager.loadTexture(textureLOC,Texture.MM_LINEAR,Texture.FM_LINEAR);
ts.setTexture (texture);


MaterialState ms = display.getRenderer ().createMaterialState ();
ms.setEmissive (new ColorRGBA(0.6f, 0.6f, 0.6f, 1));
ms.setShininess (10.0f);
ms.setSpecular (new ColorRGBA(0.5f, 0.5f, 0.5f, 1));

// ...Ahh, multiple render states are allowed? And necessary to get specular lights on textured objects?
big_teapot.setRenderState(ts);
big_teapot.setRenderState(ms);



Thanks!!

By the way, what is the range of the parameter in "setShininess(..)"?

use the materialstate instead to do that

MrCoder said:

hehe jme would be somewhat lacking in usefulness if you had to choose between using a shader, or a texture, or a material, or lighting :)


Well, NOW that's logical for me.. it hasn't been before.  :roll:

setRenderState(..) appeared to me (as a noob) that you set EXACTLY ONE state..
if there are multiple states I would have expected somewhat like
setMaterialState(..) and setTextureState(..) and so on...
Quote:
The range of setShininess is 0.0f - 128.0f

Hmmm..  :D I know I'm getting annoying... but the range would be interesting
in the javadoc of setShininess(..).. wouldn't it ?  :)

Ive been following this thread and have been able to get my textured .obj models shiny but I cant seem to get a collada model exported from blender to have specular reflection textured or not. Im using latest blender and script from illusoft. I have tried setSeperateSpecular and setting the MaterialState and nothing seems to work.

has anyone gotten a specular reflection on a blender/collada model?  :?

What specular color is set on your materials?