learning shaders

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
TheGameMaker
Posts: 275
Joined: Fri May 12, 2006 6:37 pm
Location: Germany

learning shaders

Post by TheGameMaker »

Hi all out there. reacently i decided, that i have to learn how to do shaders...
So i´ll going to learn HLSL...
Here i´ll post allt the shaders i do...
(and maybe some questions ) :D
Greetz TGM
TheGameMaker
Posts: 275
Joined: Fri May 12, 2006 6:37 pm
Location: Germany

Post by TheGameMaker »

ok.. here the first one i did:
Bloom
Image
(i have to admit, that this screen is faked in Rendermonkey by using a screenshot as texture for a plane, but it will look the same way in irrlicht.)
Unfortunably DevC++ is unable to use Irrlicht with DX, so I couldn´t make a irrlicht shader out of it. Does somebody know a HLSL->GLSL converter??
or can Code::Blocks compile Irrlicht with DX??

so.. some new shader done by me:
A nice little on shild effec(looks much better in front of something else):
Image

A bumpmap shader(Rendermonkey sampel), which I improved with Alpha+ specmap. The best thing about it is, that it only needs two textures, color+alpha in alphachanel and Normal+spec in alpha chanel:
Image

and Realtime Enviorment distortion via render to tex and a distortion Normalmap:
Image
Last edited by TheGameMaker on Thu Oct 19, 2006 6:31 pm, edited 1 time in total.
Xaron
Posts: 310
Joined: Sun Oct 16, 2005 7:39 am
Location: Germany
Contact:

Post by Xaron »

Just send me a PM, I can host it for you. ;)

Nice work! :)

And here is the link: http://www.leidel.net/dl/irrlicht/bloom.rar

Regards - Xaron
juliusctw
Posts: 392
Joined: Fri Apr 21, 2006 6:56 am
Contact:

good job

Post by juliusctw »

:D

good job with the shaders

just wondering why you pick HLSL instead of GLSL , we linux boy won't be able to use it :?

please keep posting your shaders, especially when you get to the water, irrlicht's water right now looks pretty fake
klikmaster
Posts: 40
Joined: Mon Sep 11, 2006 1:06 pm

Post by klikmaster »

Looking good so far! Keep at it, some water shaders would be nice :P
~IRRLICHT ROX MY SOX~
Nova
Competition winner
Posts: 99
Joined: Mon May 09, 2005 10:32 am

Post by Nova »

may i ask what ressources (tutorials/books/etc.) you use to learn the shader language?
TheGameMaker
Posts: 275
Joined: Fri May 12, 2006 6:37 pm
Location: Germany

Post by TheGameMaker »

well... i first really tried using GLSL, but as C++ Programmer I liked HLSL more.. but i definitiv will make a switch to GLSL if the time is come. Momentan I´m fokusing on understanding the way shaders work. (cause i can´t use them, too I´m working with DevC++ :evil: )
You linux guys can use them if you assemble them first. I think this should be no problem and shaderassembly should run in every system(just tell me if this isn´t corret.)
tuturials... i didn´t used much tuts.
this one,
http://www.facewound.com/tutorials/shader1/
and the free sample chapter of the X2 book which seems to be very good, maybe i´ll buy it. The rest I learned by looking at the very simpelst shaders in rendermonky (unshaded tex, pong with tex etc.)

Greetz TGM
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

HLSL is easily switched over to GLSL. Instead of asking someone to do both for you, you should try it out yourself and learn shaders a bit more.

They are virtually the same. Some simple research will show you that GLSL uses float, vec2, vec3, vec4 whereas HLSL used float, float2, float3, float4.

Also, you'll find that the GLSL compiler is stricter than the HLSL compiler. For example, if you have a vec4 for a texture coord, and you want to do a 2d texture lookup, you have to explicitly cast the vec4 to a vec2.

That's honestly about it. GLSL can seem a little easier, because instead of having to set a shader constant for the WorldViewProjection as you do in HLSL, it's already set for you. And you can even go simpler by transforming your vertex position in your vertex shader by simply calling -

Code: Select all

gl_Position = ftransform();
As well as many other things are automatically set for you. Some simple research will show you all these things.

I'll even help you from having to search the web. I have 2 basic files I used to learn GLSL( after of course already knowing HLSL and knowing shaders, but still, should be all you need ) I've found them on the web, and saved the pdf's, so no clue where I got them, but I've put them on my website here -

http://www.spintz.com/glsl_quickref.pdf
http://www.spintz.com/GLSLangSpec.Full.1.10.59.pdf
Last edited by Spintz on Thu Oct 19, 2006 2:12 pm, edited 1 time in total.
Image
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Yeah, looks verry nice !!!

For the DX support with MinGW/GCC (C::B, DevCpp) you'll have to recompile the Irrlicht dll (please search the forum for this) !!!

Or use my IrrExtensions, it will setup the Irrlicht project for recompiling with all drivers you want !!!
But you'll have to install the DX-Devpak (also for C::B), a link can be found on my site...
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
TheGameMaker
Posts: 275
Joined: Fri May 12, 2006 6:37 pm
Location: Germany

Post by TheGameMaker »

thx for the GLSL tuts.. i´ll have a look on them.
HLSL is easily switched over to GLSL. Instead of asking someone to do both for you, you should try it out yourself and learn shaders a bit more.
hmm... I thought I wrote this a little bit above.

In my Opinion DX suxx, i don´t like the way its designed.. OGL is much more confortable... so I really want to switch to GLSL, but as already mentioned i felt more confortable with the HLSL layout..

but I got one question. I want to render the scence into a tex, and projekt thi tex onto a model (for desorstion). So its neccessary to get the texcoord by the position in Viewspace. I want the Rendered Texture to be Projekted onto the objekt as like as a video beamer would projekt it. I tried to set the texcoord to the pixelpos in viespace(x&y values). Unfortunably this doesn´t work as expected, because the texture scale remained constant relativ to the objekt. I want it to be streched about the whole screen... as like as this picture shows:
Image
(both spheres are the same and the second one is only scaled/zoomed out. The grey patter is the rendered texture ) as you can see the pattern should allways fill the renderoutput without tiling/stretcheng. and so should the mapped&textured sphere be invisible(cause the background and the rendered&projekted Tex are seamles blending). What way can I achief this Planar mapping??
hope, that you understand what problems I got,
thx in advance TGM
TheGameMaker
Posts: 275
Joined: Fri May 12, 2006 6:37 pm
Location: Germany

Post by TheGameMaker »

*update*
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

Linux wont be able to runs anything dx even dx assembly.
Nice work you can get visual studio for free from ms it runs dx fine, you can also ask me to help you convert the shaders.

But rember the .fx files dont just do the actual code, they also determine the rendering orders, passes, RTT's etc....

You will have to custom code all of that in irrlicht C++, so maybe trying to break down these shaders would help you in the c++ stage.

Also rember irrlicht doesnt load varaiables into hardware semantics
only the normals and texcoords are loaded so for the bumpmapping and maybe the other stuff you will have to load them via unused texcoords

render monkey uses
BINORMAL0;
TANGENT0;

or attribs in glsl

irr cant load them unless you modify the drivers(tri strip draw and stuff)
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

btw i encountered the same texture projection bug, to solve it you must use a
scaling matrix, since the matrix orders are diffrent for hlsl and glsl row order vs column order ill write the matrix operation as a linear algebra

remember POS is the vertex after it has been transformed, since it is transformed by the modelview,camera projection etcc... the camera would be the projector, to change the projector to something else load the projection matrix of the object instead of the camera's

projCoord =pos * 1.0 / pos.w
projCoord += (1,1,1,1)
projCoord *= (.5,.5,.5,.5)

you would then use texture 2d not texture proj (or texture proj if you miss out the first line in the equation i gave you)

you can do the above in the ps or vs but the texcoord must reach the ps.
Nova
Competition winner
Posts: 99
Joined: Mon May 09, 2005 10:32 am

Post by Nova »

are those all rendermonkey shots? because it would be cool to see some irrlicht examples ;)
don't get me wront, nice stuff *gg* I'd just like to see for once a shader enhanced irrlicht scene
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

TheGameMaker wrote:thx for the GLSL tuts.. i´ll have a look on them.
HLSL is easily switched over to GLSL. Instead of asking someone to do both for you, you should try it out yourself and learn shaders a bit more.
hmm... I thought I wrote this a little bit above.
Sorry, wasn't intended for you. Was intended for i think julius that was saying "give us Linux users this stuff in GLSL" I think you're doing a fine job :P
Image
Post Reply