Page 1 of 3

material shader: Phong, fake reflect, bloom

Posted: Fri Oct 23, 2015 9:36 am
by jimy-byerley
I taken a long time to find good material shaders on the internet, with effects like phong diffuse and specular, fake reflect, ... But I never found anything that was really good. Most of the some things I found were not working well, or had very bad optimization.

So I finally did theses shaders myself and I publish they here.

The archive with my shaders and the .cpp codes to use it (unix makefile, for windows, lets see the tutorial):
google drive
All this code is free, do what you want with it (but maybe the 3d model is'nt).

The result is:

Only basic Phong shader:
Image

Same with diffuse, specular, normal and emission textures:
Image

Support for multiple light (max number fixed by user or automatically detected)
Image

cubemap added to make a fake reflect:
Image

With a bloom (light glow) effect:
Image

These shader have very hight performaces ! I tested it, and it works with around 60 FPS on a small laptop (AMD A1 and graphic chipset)

Principe of Phong shader is explained here:
lighting with glsl
phong model
Rotation matriix:
rotation matrix, transformations

Edit: Render issue for bloom sample size over 256 px FIXED ! (see this post

Re: material shader: Phong, fake reflect, bloom

Posted: Fri Oct 23, 2015 10:11 am
by mongoose7
I think you need to add bump-mapping to make it useful. You should post the images again, too.

Re: material shader: Phong, fake reflect, bloom

Posted: Fri Oct 23, 2015 10:13 am
by jimy-byerley
there is already normalmapping, no bumpmapping because it's GPU consumpting, but it can be added easily ...

Re: material shader: Phong, fake reflect, bloom

Posted: Mon Oct 26, 2015 3:23 pm
by jimy-byerley
I finally added a bumpmap support, let's see the code in cycle/exemple-bumpmap.frag
I used the specular map as entry for bumpmap, and the render look actually as with a normalmap.

Re: material shader: Phong, fake reflect, bloom

Posted: Tue Oct 27, 2015 1:20 pm
by CuteAlien
Thanks, nice stuff.

Edit: figured out how to download - stupid adblock blocked the download button in google-drive *sigh*. Somehow adblock plus got really bad in blocking too much stuff lately.

Re: material shader: Phong, fake reflect, bloom

Posted: Tue Oct 27, 2015 7:00 pm
by Vectrotek
@ jimy-byerley..
Very Cool!
I don't know if you are aware of this but when Irrlicht sees "map_Bump" in your material file i.e. "*.mtl"
it attempts to render the bump map in its own way overriding all your effort with the Normal mapping.
Try disabling the mention of the bump map in the file by commenting it out using "#"
like..

# map_Bump /home/jimy/tron-reboot/repo/textures/light-vehicles/MG_MovieCycle_Body_NORM.tga
map_Kd /home/jimy/tron-reboot/repo/textures/light-vehicles/MG_MovieCycle_Body_DIFF.tga
map_Ke /home/jimy/tron-reboot/repo/textures/light-vehicles/MG_MovieCycle_Body_EMSS.tga
map_Ks /home/jimy/tron-reboot/repo/textures/light-vehicles/MG_MovieCycle_Body_SPEC.tga

I Haven't tested your code yet but I'm sure there will be an improvement.

I like your "Bloom" effect and will surely try it out.
Good job!

Re: material shader: Phong, fake reflect, bloom

Posted: Tue Oct 27, 2015 7:10 pm
by Vectrotek
Oh! The way you handled the "Skymap" is pure genius!
I think that this might be the solution I'm looking for!

Re: material shader: Phong, fake reflect, bloom

Posted: Wed Oct 28, 2015 7:48 am
by jimy-byerley
@Vectortek

Thanks! I added some additionnal comments in the skymap calculation for the reflect, it was a bit poor.
I removed texture parameters from light-cycle.mtl but it doesn't change anything, the normalmap were active yet.
The current problem is to use more than the fourths textures imposed by irrlicht. I think the developpers would change it ...

Re: material shader: Phong, fake reflect, bloom

Posted: Wed Oct 28, 2015 9:43 am
by Vectrotek
If an engine recompile with an altered "IrrCompileConfig.h" don't work then it is probably a hardware thing..

Re: material shader: Phong, fake reflect, bloom

Posted: Wed Oct 28, 2015 11:43 am
by CuteAlien
Yeah, 4 texture limit is annoying. Reason that number is hardcoded is probably to avoid any dynamic memory allocation inside materials. Reason it's just 4 instead of 8 is maybe that having more textures will cost some speed even when those textures are not used and most projects don't need more. And a tiny bit more memory (unlikely to matter). Will have to profile that, maybe increasing to 8 makes no noticable difference. Otherwise maybe there is some way to make this value a template parameter (probably ugly, would have to be passed through a lot of classes). I'll put it on my todo to check this - people run into that already a few times.

Re: material shader: Phong, fake reflect, bloom

Posted: Wed Oct 28, 2015 3:05 pm
by hendu
That, and a lot of recent Geforces still only supporting 4.

http://feedback.wildfiregames.com/repor ... RE_UNITS#4

Re: material shader: Phong, fake reflect, bloom

Posted: Wed Oct 28, 2015 3:27 pm
by CuteAlien
Wait - my card only supports 4??? Damn, it...

Well, but I suppose we still should allow more. Maybe add some warning in comments that it will not work on many systems then.

Re: material shader: Phong, fake reflect, bloom

Posted: Wed Oct 28, 2015 4:24 pm
by Vectrotek
Mmm.. When I run 3D Labs's "Shadergen" it informs me that my card only supports 4 textures, but when I do an engine
recompile I definitely have access to EIGHT textures?

Re: material shader: Phong, fake reflect, bloom

Posted: Wed Oct 28, 2015 6:24 pm
by jimy-byerley
I think too there should be only warnings in case of using more than 4 but not limit as short as that.
When hendu said many geforces support only 4, it means that in blender we can have only 4 textures for an object ? or blender is using an other render pipeline ?

Re: material shader: Phong, fake reflect, bloom

Posted: Wed Oct 28, 2015 7:56 pm
by devsh
All recent geforces support 16 to 32 textures, and post-fermi support as many as you like with bindless textures

Our version of irrlicht with just minor modifications supports 8 textures in all shaders and materials.

Irrlicht should be able to support 16 textures in shaders, but when I tried I couldn't get it to work straight off the bat.

The "Shadergen" queries the wrong (obsolete) OpenGL implementation constant and that is why you're getting the number 4.