material shader: Phong, fake reflect, bloom

Post your questions, suggestions and experiences regarding to Image manipulation, 3d modeling and level editing for the Irrlicht engine here.
jimy-byerley
Posts: 27
Joined: Thu Oct 22, 2015 10:42 am

material shader: Phong, fake reflect, bloom

Post 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
Last edited by jimy-byerley on Sat Jan 21, 2017 7:21 pm, edited 6 times in total.
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: material shader: Phong, fake reflect, bloom

Post by mongoose7 »

I think you need to add bump-mapping to make it useful. You should post the images again, too.
jimy-byerley
Posts: 27
Joined: Thu Oct 22, 2015 10:42 am

Re: material shader: Phong, fake reflect, bloom

Post by jimy-byerley »

there is already normalmapping, no bumpmapping because it's GPU consumpting, but it can be added easily ...
jimy-byerley
Posts: 27
Joined: Thu Oct 22, 2015 10:42 am

Re: material shader: Phong, fake reflect, bloom

Post 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.
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: material shader: Phong, fake reflect, bloom

Post 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.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: material shader: Phong, fake reflect, bloom

Post 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!
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: material shader: Phong, fake reflect, bloom

Post by Vectrotek »

Oh! The way you handled the "Skymap" is pure genius!
I think that this might be the solution I'm looking for!
jimy-byerley
Posts: 27
Joined: Thu Oct 22, 2015 10:42 am

Re: material shader: Phong, fake reflect, bloom

Post 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 ...
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: material shader: Phong, fake reflect, bloom

Post by Vectrotek »

If an engine recompile with an altered "IrrCompileConfig.h" don't work then it is probably a hardware thing..
Last edited by Vectrotek on Wed Oct 28, 2015 4:20 pm, edited 2 times in total.
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: material shader: Phong, fake reflect, bloom

Post 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.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: material shader: Phong, fake reflect, bloom

Post by hendu »

That, and a lot of recent Geforces still only supporting 4.

http://feedback.wildfiregames.com/repor ... RE_UNITS#4
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: material shader: Phong, fake reflect, bloom

Post 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.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: material shader: Phong, fake reflect, bloom

Post 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?
jimy-byerley
Posts: 27
Joined: Thu Oct 22, 2015 10:42 am

Re: material shader: Phong, fake reflect, bloom

Post 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 ?
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Re: material shader: Phong, fake reflect, bloom

Post 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.
Post Reply