Shaders and Effects.

BlitzMax Forums/MiniB3D Module/Shaders and Effects.

FBEpyon(Posted 2010) [#1]
Hello,

I know this is like beating a dead horse with a stick, but i need some help, I have been working on a terrain system for the last year off and on between computers and losing source, but now that I have most of my code back I have been working on my game again, I have most of the terrain system back up which is nice, but I'm wanting to start with some new stuff like water and reflected surfaces.

I have seen a lot of different codes and what not, but nothing that I can see about making normal maps work in raw MiniB3D with out using a dll extension or completely re-writing the game out of c++, but the main reason I got Blitz was because of the coding easy and not needing additional content to make things happen (well at least super large header files and complex APIs).

Is there anything or any source that would help me with my problem I'm having, I'm looking for a bit of code that will help make the terrain and objects reflect on the waters surface but not kill the over all game's frame rate.

:GAME IDEA:

The over all game will end up being a RPG with a 3/4 view, I'm needing the reflective services and maybe some new ideas into how it would be possible to do vertex shading (vertex shadowing).

Currently I have a shadowing system for my terrain which works nice, but its very basic and I'm wanting to add shadows to my tree meshes and other buildings and such.

:EXAMPLE CODE FOR TERRAIN LIGHTING:



:EXAMPLE CODE FOR TERRAIN LIGHTING:

The code will color the vertex based on the height and light direction, but it took me a while to get it to work again as when I original code back I forgot how it worked, but since I lost the code and recently got it thanks to the grace of "WINGS", I have forgotten what it even does but it works LOL.

:GAME IDEA:

I was looking at this as well :

Shadow Mapping

Shadow Techniques

Anyways above is the research and information I have found, now I'm just asking for help :(

Thanks for any information


Kryzon(Posted 2010) [#2]
Try exploring the Extended version by Klepto, until you can understand the way he set things up and then you can use a similar approach.

I don't really know what's the current opinion on the Extended version shader support, but it's said to work.

As for the shadows, the good thing is that there are plenty tutorials on how to implement them with OpenGL (but with other languages) - at least shadow maps (example). The only problem is adapting it to BMax and MiniB3D.


jkrankie(Posted 2010) [#3]
Didn't Klepto's version support shadows too? Anyway, the extended version is fairly out of date, but you should be able to glean the info you require from it.

Cheers
Charlie


FBEpyon(Posted 2010) [#4]
Thanks for the responce, I have gone thru the extended edition I will be looking at it more tonight when I get home from work, I'm hoping to break it apart and start adapting the current version of MiniB3D to better support shaders.

Let me know if anyone is wanting to help, email: fbepyon@...


jkrankie(Posted 2010) [#5]
Don't have time to help, but if you get shaders working with the current version then please share :)

Cheers
Charlie


FBEpyon(Posted 2010) [#6]
Hello,

Thanks for all the support so far, I have one other question for everyone, I was looking at the GLSL (opengl shaders), and I noticed the vert and frag files, can anyone explain the difference of theses?

From what I have gathered its VERT for vertex shaders, as far as I can tell. FRAG looks to stand for fragmented (pixel shader), but I don't understand how the file system would work after looking at MiniB3D Ext.


FBEpyon(Posted 2010) [#7]
Hello (Sorry for the double post),

I'm interested in this as well, the only problem I'm having is attaching the shaders to the object or texture however it works, I got ahold of tom speeds module well the start of it.

I'm trying to get it to link to my mesh and shade it..

The current files I have are terrain_shade.vert and terrain_shade.frag, but when attached its just a black mesh.


Kryzon(Posted 2010) [#8]
See this:
http://www.blitzforum.de/forum/viewtopic.php?t=30247

Kudos to ShadowTurtle for pointing out the link previously.

PS: Use translate.google.com if you can't read german, ja?


SLotman(Posted 2010) [#9]
Can someone use that code and post a sample program/shader to test?

Since it says it works with miniB3D, I would love to see if it can achieve effects like Bloom and others through shaders, instead of "basic coding" like in B3D... but I have no idea how to write pixel shader code :(

Edit: I tried this, but couldn't get it to work.... am I doing something wrong, or my card just can't run those shaders? (it does says on the debug mode it compiled successfully to run on hardware, so I assume it must be supported by the card, right?)



flatten.vert and flatten.frag are both from this page (look at the page bottom for the download link)

flatten.frag:
void main(void)
{
	gl_FragColor = vec4(0.8,0.3,0.3,1);
}


flatten.vert:
uniform float time;

void main(void)
{
	vec4 v = vec4(gl_Vertex);
	v.z = sin(5.0*v.x+time)*0.5;
	gl_Position = gl_ModelViewProjectionMatrix * v;
} 



FBEpyon(Posted 2010) [#10]
I tried the code as well, and the only thing I can think of is there is missing Uniform Code, but I don't know where that goes..?


SLotman(Posted 2010) [#11]
'uniform float' is not a code missing, it's a variable type.

I think this won't work as the guy said on the post, just by putting the glUseProgram before renderworld. I will try to write some pure ogl code to test it, and see the results :/


SLotman(Posted 2010) [#12]
Got it working... sorta.



The important thing I was missing was to read the return value from loadshader, and use that on glUse...;

The bad thing is, instead of flatening, the cube became a plane... bug in the shader? in the loader? ATI's faulty implementation? :(


FBEpyon(Posted 2010) [#13]
See I tried that as well, and got nothing from it, I think I might be doing something wrong as well, I'm using a Nivida GTS 240 and it supports all the shaders needed, I'm at work and will look again, maybe its working I just need to move the camera..

P.S if you are using the small fix version of Minib3d, you don't need the glewInit() in the top its part of the Graphics3D command now.

Also:

Try not rotating the cube by 45 when you first make it, just let the turnentity code after words handle that for you instead. I have a feeling its just the prospective you are looking at the model, but in my case I still get nothing from the above code for a Nvidia Card.


SLotman(Posted 2010) [#14]
The problem is (as far as I could gather) GLSL isn't that well supported on drivers, so there are lots of issues on different cards.

Probably using CG would be a better idea, I don't know. I guess that's why most people go to Direct-X, much easier to get shaders going there.

I can guarantee that the code is working and running the shaders. If the shader itself doesn't work, it's a driver issue. (I tested several shaders here, I could only get 1 to work as intended...)

As for miniB3D, I'm using my own version (I'm the one who gathered and posted about all 'small fixes' on that thread - even fixed a couple of problems myself, and I keep looking for more improvements here and there all the time); I just posted the glewInit() there to be on the safe side.


FBEpyon(Posted 2010) [#15]
Okay,

I was looking at the Small Fixes and I was wanting to know why Minib3D is using the SEtGraphicsDriver GLMax2DDriver() and not using the GLGraphicsDriver(), I would think that if you are trying to use OpenGL u would set the Graphics3D() command to mix with the GLGraphicsDriver() not the GLMax2DDriver().

I was just looking thru the commands.


SLotman(Posted 2010) [#16]
It uses it, so you can use normal bmax commands to draw 2D on top of everything.


FBEpyon(Posted 2010) [#17]
WOW you must be surfing the web lol..

Anyways so I was looking at this thread : http://www.blitzmax.com/Community/posts.php?topic=88944

I see there are something not added into the minib3d that might be cause the problems, we might want to look into adding something the other ENABLE COMMANDS.


nrasool(Posted 2010) [#18]
Hey there,

Even though this is a week old, I tested it out and it works for me, I even tested your example with the following shader and again it works for me, see http://www.clockworkcoders.com/oglsl/tutorial4.htm


SLotman(Posted 2010) [#19]
nrasool: I never said it wouldn't work... but get it working on all cards, that's the problem, since GLSL isn't all that well supported as CG for example.

I got *some* shaders working here on ATI, but most of them ran and didn't produce the desired result, like that 'flatten' shader I posted.

(Which is a shame really, this would be fairly easy to integrate into miniB3D)


FBEpyon(Posted 2010) [#20]
I have a very good Video Card and I can't seem to get any of the examples to work..



nrasool

Hey there,

Even though this is a week old, I tested it out and it works for me, I even tested your example with the following shader and again it works for me, see http://www.clockworkcoders.com/oglsl/tutorial4.htm




I have a GTS 240 Nvidia 1Gb, but I will try that shader.


nrasool(Posted 2010) [#21]
Hey there,

Weird as both examples work for me, very strange. My graphics card is Nvidia Geforce 8500 GT 1gb

One thing for FBEpyon is have you updated to the latest driver? I'm using 6.14.11.8122 which is working well so far

@SLotman I take what you meant, sorry if I was not clear, it is a shame that OpenGL drivers seems to be flaky with you, as this is a great way of implementing shader without any fuss


FBEpyon(Posted 2010) [#22]
Hello,

I was able to get both examples to work with klepto2 new ext2 version and its very fast !!

So I think I figured it out now..


nrasool(Posted 2010) [#23]
Hey FBEpyon

Sorry to resurrect this thread, but what did you do, did you customised your minib3d to include part of klepto2 new ext2 version concerning shaders? If so, please can you post what you did

Many thanks

Kind Regards


klepto2(Posted 2010) [#24]
Hi,

he is saying that he was using ext2 version.

@all: I have 2 weeks of free time from the upcoming week and I will try to add clean up the googlecode version a bit. eg: uploading per SVN, adding some more loaders, a few other samples and a few experimental files.

The experimental files contains a very simple shadowmapping sample via shaders so this may a good start for someone to implement shadowmapping completely.

screens:

experimental bsp loader:


shadowmapping:



Kryzon(Posted 2010) [#25]
Hello Klepto2, this looks very nice.

Some sort of PCF or filtering going on?

PS: did you get my e-mail about the GLSL sprite rotation?


KronosUK(Posted 2011) [#26]
Any movment on this? I'm particularly interested in the shadowmapping.


FBEpyon(Posted 2011) [#27]


vertex code


fragment file


Hello All,

Can you please look at this, I'm not able to get the textures to blend and give me my normal mapping.. :( can you see what I might be missing..

Get images from here http://www.ozone3d.net/tutorials/normal_map.php

Thanks,

Fbepyon

Last edited 2011

Last edited 2011