LightBlow Shader

Hi guys!



The Lightblow shader is an improved Lighting shader for JME.



Features:

1 Improved lighting calculations.

2 Improved reflection calculations.

3 Reflection map implementation with normal map alpha.

4 Improved Minnaert calculations.

5 Hemispherical lighting.

6 Image Based Lighting with Albedo.

7 Emissive map implementation with diffuse alpha.

8 normalization of normals by default.

9 Specular map implementation with normal map alpha.

10 Specular intensity implementation.

11 Switching -x/-y/-z normals for different normal maps. (3dmax, blender, xnormal have different approaches).

12 Specular Color now works with specular maps

13 Glowblow fragment shader is added with m_GlowIntensity? uniform. It’s possible to change glow intensity for objects. Please, use DiffuseMap? as GlowMap? instead of new additional Glow rgb texture.

14 Lightmaps are added.



Shader Repository:

http://code.google.com/p/jme-glsl-shaders/





http://www.youtube.com/watch?v=knROh_3o2uo&feature=player_embedded




Unlimited Free Image and File Hosting at MediaFire

4 Likes

Ok, I did patches here:

http://code.google.com/p/jmonkeyengine/issues/detail?id=310&colspec=ID%20Type%20Status%20Component%20Priority%20Product%20Milestone%20Owner%20Summary



http://code.google.com/p/jmonkeyengine/issues/detail?id=311&colspec=ID%20Type%20Status%20Component%20Priority%20Product%20Milestone%20Owner%20Summary



http://code.google.com/p/jmonkeyengine/issues/detail?id=312&colspec=ID%20Type%20Status%20Component%20Priority%20Product%20Milestone%20Owner%20Summary



Thanks to Erlend_sh for his article about javadoc patches: http://hub.jmonkeyengine.org/2011/01/22/submit-javadoc-patches-with-the-online-code-editor/



I hope my patches will be approved.

I can see why in some cases this patch would be useful. Specifically, many objects in the scene might not even use specularity so this could save a few cycles on old GPUs. However doing it this way means you have much more shader switches which are considered expansive.



@mifth, are you experiencing performance issues, which motivated you to make this change?

About the SpecIntensity parameter, remember you can always scale up the Specular color to achieve the same effect

  1. if you have a scene with 2 millions of polygons it will save you fps indeed. Especially, if you have other gpu effects (hdr, bloom, motion blur, blur etc.). The less shader calculation the better scene performance. I’m talking about complex scenes.

    Specular calculations are more complex even than reflection calculations. So i think if you don’t need specular, so it would be better to switch it off.


  2. About Spec SpecIntensity - if you assign a gray specular map you cannot make it more or less intensive (for instance twice or 3 times) with Specular color. SpecIntensity will be more usable as i suppose. It works like in blender, or 3d max or like in unity. I think this is a very important parameter and it presents in every pro shader.



    This picture shows on a mesh without maps the SpecIntensity power. You can easily multiply specular twice or devide on a half:

    http://img849.imageshack.us/i/speec.png/][/URL]



    Uploaded with ImageShack.us

Shader switches are only expensive on old GPU’s actually, all current gpus are able to to use them correctly. (The old do every branch and use ony the one wanted behaviour is kinda dead by now)

you mean if i don’t want to count specularity, so i should write another shader?



Do you mean that new GPU do not understand such things?:

#if defined(SPECULAR_LIGHTING) && !defined(VERTEX_LIGHTING)

…

…

…

#endif




well, i’m confused.

I can make a stress test: a scene with specular and a scene without specular.

Nvidia gts 250.

Old cpus in fact did not understood it, only newer (will a few years by now) gcs are able to perform branching in the program logic. ( the older ones just did everything procedually from top to bottom and then used only the wanted result.)

Ok, what will you suggest for lighting material improvements? My improvements are useful or useless?



Atleast SpecularIntensity will be useful.

Well, I think that one large material is probably simpler to use than dozens of small simple ones. So I think it might be usefull. A stress test for this would be kinda interesting however to see if the assumptions made here are correct.

Thanks man a lot!!! I’ll make a stress test when i’ll be at home.

Hi!



Ok, my stress test! Shaders with Specular map, normal map, diffuse map.



1)

I did a stress test with 2 millions of triangles.

Lighting shader: 86 fps.

My improved shader with specular: 86 fps (The same result as Lighting but specular map increased 3 times (SpecIntensity = 3.0)).

My improved shader without specular: 92 fps.



So my shader wins 6 fps with 2 million of polygons scene.



2)

I did a stress test with 1 million of triangles.

Lighting shader: 160 fps.

My improved shader with specular: 160 fps (The same result as Lighting but specular map increased 3 times (SpecIntensity = 3.0)).

My improved shader without specular: 177 fps.



So my shader wins 17 fps with 1 million of polygons scene.



3)


I did a stress test with 250 thousand of triangles.

Lighting shader: 516 fps.

My improved shader with specular: 516 fps (The same result as Lighting but specular map increased 3 times (SpecIntensity = 3.0)).

My improved shader without specular: 581 fps.



So my shader wins 65 fps with 250 thousand of polygons scene.



So you decide would you like to commit my shader improvements or no. :slight_smile:



Sceenshots of 2 million of triangles scene:

Lighting shader with Shininess = 2.0:





Uploaded with ImageShack.us



My improved shader with SPECULAR_LIGHTING and SpecIntensity=3.0, Snyniness=2.0:





Uploaded with ImageShack.us



My improved shader without specular:





Uploaded with ImageShack.us

1 Like

Well I think it seems quite usefull, but I’m not the one making such decisions ^^



about same in speed but with additional functionalities or a bit faster seems not bad for me at least.

Looks awesome! :slight_smile:

Thanks @EmpirePhoenix and @InShadow!

One remark to the shader: if you want to switch reflection on, so you will need to switch SPECULAR_LIGHTING on.



I hope the core devs will accept my changes.

That’s nice indeed, I guess we can integrate this in the lighting shader.

However it has to be thoroughly tested because the lighting shader is likely to be widely used.

The decision to integrate it in the end is Momoko_Fan’s call.

I can see why you would get a speed improvement.

Maybe we can have a boolean like:



[java]mat.setBoolean(“DisableSpecular”, true);[/java]



What do you think?



Or we could make it set the flag automatically when you set “Shininess”, e.g.



[java]mat.setFloat(“Shininess”, 16); // automatically enables specularity[/java]



The 2nd solution can be useful because on NVIDIA cards, if you dont set shininess parameter, the material will look strange due to a bug. This way you avoid both the bug and you get a bit of optimization too.

1 Like

Well, actually I did boolean like already in the improved material with “SPECULAR_LIGHTING”. If “SPECULAR_LIGHTING” will be switched of, so many computations will be switched off (lightComputeSpecular method, and SpecularSum2 * specularColor * light.y in gl_FragColor).





This is my material how looks like:

[java]

mat = new Material(assetManager, “MatDefs/ma.j3md”);



mat.setTexture(“DiffuseMap”, assetManager.loadTexture(“Models/guy/guy.png”));

mat.setTexture(“SpecularMap”, assetManager.loadTexture(“Models/guy/1.png”));

mat.setTexture(“NormalMap”, assetManager.loadTexture(“Models/guy/guy_normal.png”));



mat.setBoolean(“SPECULAR_LIGHTING”, true);

mat.setFloat(“SpecIntensity”, 4.0f);

mat.setBoolean(“Minnaert”, true);

mat.setFloat(“m_Shininess”, 5.0f);

// mat.setBoolean(“VertexLighting”, true);



char_boy.setMaterial(mat);

rootNode.attachChild(char_boy);





[/java]



Everything is implemented in the improvemented matdef, frag and vert LIGHTING. just test it.

If you want to improve something I missed you are welcome!

WOW!!! I found the way how to make more speed imrovements again.



I just did a quick stress test of a scene with 500 thousand of polygons:



355 fps - my new improved without specular

316 - my improved without specular

280 - standart lighting material



Also, i want to correct Minnaert function. And post all together soon.