openGL Wormily (procedural images/normal maps)

BlitzMax Forums/OpenGL Module/openGL Wormily (procedural images/normal maps)

Taron(Posted 2010) [#1]
Welcome to a piece of chaos GL code on my way into understanding the basics of it. I've been bouncing all over the place to wedge myself into the concept, but my stuff is probably shamefully crappy at this point.

HOWEVER, I've decided to share with you my first baby-steps that were finally plenty of fun for me.

Should anyone of you notice idiotic stuff in there, worthy of poking me for, please, please, do so! It's literally my first piece of openGL code with great help from FreakForFreedom for loading shaders amongst other tips, but I have not been much of a good student thus far. :}

No images needed... just save the .vert and .frag somewhere.


shader_l1.frag

shader_l1.vert


shader_l2.frag

shader_l2.vert



_JIM(Posted 2010) [#2]
Almost there... I get a few shader compilation errors:

DebugLog:ShaderLog: Vertex shader was successfully compiled to run on hardware.
DebugLog:ShaderLog: Fragment shader failed to compile with the following errors:
ERROR: 0:29: error(#164) l-value required assign "N" (can't modify a varying)
ERROR: 0:30: error(#164) l-value required assign "N" (can't modify a varying)
ERROR: 0:31: error(#164) l-value required assign "N" (can't modify a varying)
ERROR: 0:33: error(#164) l-value required assign "N" (can't modify a varying)
ERROR: 0:34: error(#164) l-value required assign "v" (can't modify a varying)
ERROR: 0:35: error(#164) l-value required assign "v" (can't modify a varying)
ERROR: 0:39: error(#160) Cannot convert from 'const int' to '3-component vector of float'
ERROR: error(#273) 7 compilation errors.  No code generated
DebugLog:ShaderLog: Vertex shader was successfully compiled to run on hardware.
DebugLog:ShaderLog: Fragment shader was successfully compiled to run on hardware.


Never done GLSL (just a bit of HLSL and GC) but managed to fix it :) Here's the fixed shader_l1.frag:


This is looking very cool yet very strange :)


Taron(Posted 2010) [#3]
Oh man, thanks Andrei! I had no idea, because it simply compiled without complains here, but it actually seems like it wasn't working properly compared to how it looks with your fix. (subtle but important different shows in the specular highlights. They were bothering me before a bit. Now they bother me less...HAHA! I mean, it's all a bit arbitrary, since I just try to "fake" geometry by offsetting the "camera" according to the heightmap as a test. It's mathematical snake-oil to some degree.

But-Wow-that's weird...?
<Why would it have difficulties to compile somewhere else?>
<Different versions of openGL or glew or so?>
<Fascinating.>
But it proofs my point that I appreciate but dislike overloaded operators or how ever that's called. I prefer seeing what I'm doing more clearly.

Thanks Andrei, that's awesome! And thanks! :)

Here's a slight variation, but it's really cute, I think! :}
(hit 'A' to swallow some air at this point, hehe!)



_JIM(Posted 2010) [#4]
That's really cool! I blame you for much of my time going to waste :D

Right now I'm busy with other stuff, but soon I'll have to work on a bunch of shaders for my own game and I am going to tear your code apart :)

Also, after pressing 'A', even though I know it will never happen, I somehow expect something to come out the other end :))


Taron(Posted 2010) [#5]
LOL, HAHAHAHA, I HAD THE EXACT SAME THOUGHT Already... LOL!

Well, I'm currently trying to understand blooming. The framebuffer stuff is still chewy to me, since everything's still new to me... <THE PAIN>

I hope I'll understand and can control it today already.

(You should see what else I wrote a few hours ago..haha...funny strange stuff. It's a great sandbox already!)

Oh, by the way, if you have questions about the shaders, ask me! It's all very easy stuff at this point!


Taron(Posted 2010) [#6]
This thing only runs on my machine, really. I wonder if it makes any sense to use openGL, if it's so fragile? I mean, I'm sure I'm doing 90% wrong of what can be done wrong, but... it's scary and challenging to entertain hope. :{


_JIM(Posted 2010) [#7]
It could help if we knew the specs. Are you using an nVidia card or an ATi? (I suspect nVidia).

Basically, as long as you steer away from the vendor-specific extensions and make sure your shaders are properly written, you should have no problem. OpenGL runs just fine on Win, Linux and Mac OS X.

I decided to use OpenGL-only and ditch the support for DirectX for now as I'm using lots of low-level stuff, and the last thing I want right now is copy the code 3 times (OGL, DX7, DX9). So I'm just using the one that's cross-platform: OpenGL.

I am aware that particularly ATi and Intel video cards have lower performance in OpenGL than DX9 and DX7 (Intel), but I'm counting on my optimization skills for now. It's true that I'm not using shaders yet, but so far, I didn't experience any corruption/error even on a VIA Chrome 9 video card which is about as bad as I have personally ever seen. Even though it has shader 2.0 support, it runs at about 40 fps drawing 4 1024x1024 alphablended images. There's no way I can make my game playable on that. Still, there's no errors.

So, if you're having problems it's because you don't know how to do everything the right way. I remember when I first played with shaders and they ran flawlessly on my ATi card. Then I though I'd test them on my secondary card (nVidia). Surprise! Everything was corrupted (and I mean everything... both pixel and vertex shaders). Just to later find out that I was lucky that my shader ran well, because I was doing lots of fishy stuff.

Regarding shaders, you could use a proper shader editor and look for errors/warnings. Particularly warnings. It's those that make it run on one setup, but not another.

Also, if you need help testing (or perhaps coding shaders), I'll happily provide it. :)


Taron(Posted 2010) [#8]
Thanks, Andrei! I think as soon as I have my code run on my intel mobile gfx board on the laptop, I'll be perfectly thrilled! I'm worried that it doesn't support the GLSL shader stuff, uhm, rather simply "shader stuff".

It's a tough ride for me, that's for sure. Approaching GL from scratch appears to be a rather complex set of challenges/knowledge-requirement.

What turned me down a little bit was that I didn't even get Grover's stuff to run on the laptop. Tough to stay encouraged.

I'm not giving up, though, that's for sure!

Oddly enough, there are still a lot of very basic system related programming things I havn't dealt with properly. I neatly skipped straight into what I know and manage to accomplish a few pretty things, but when it comes to error checking and throwing exceptions, haha, I'm the ball and not the pitcher. :D

So, yeah, any little piece of code that inches me towards getting it by example will be a giant boost, that's for sure. I've always learned by understanding what I'm looking at and not teaching myself the theory. Reverse engineering is my way of leaping forward. Sometimes there are some low overhangs though on which I bang my head so hard, in knocks me out, so to say... LOL.

Eitherway, any help is always BIG TIME appreciated! I'm thrilled to gain control over this, because even now I can feel what's possible and create these little glimpses into it.


Taron(Posted 2010) [#9]
For example, here's the most primitiv version of how I'm approaching the GLSL use. It's not too thoughtful, that's for sure, but it gets the general idea across...

And I mean an idea about all the mistakes I'm making!



or a bit more fun version...


or even wilder... kind of modern art! (I'm digressing, I know!)



_JIM(Posted 2010) [#10]
That looks pretty.

First of all, did you check if your intel gfx has shader support? GMA 950 has Shader 2.0 and Vertex 3.0: http://www.intel.com/products/chipsets/gma950/index.htm

Newer cards should obviously have better support, however this seems like the most common VGA chip right now.

I REALLY want to start playing with shaders, but I'm still busy with other important stuff like undo system, copy/cut/paste, multiple selection, particle system, etc. Shaders are somehow at the bottom of my list now :)

EDIT: Oh and Grover's stuff was never designed for intel cards as far as I know. Deferred rendering is a pretty advanced technique of rendering and in most cases requires support for fancy floating point textures, non-power-of-two textures and 64-bit textures. I'm not sure, but chances are none of this is supported by most Intel cards.

Try running the simplest example out there, fix the problems (if there are any) and build up on that.


Taron(Posted 2010) [#11]
AH, hehehe...wrote "unlimited" undo/redo, copy/cut/paste/insert and shifting as well as particle systems, except multiple selection, actually...I think...nah, that one I havn't done, yet, but meant to for my synth (syntaron), hehe.

Hmmm, so I guess it's alright if I go at shaders, now! :o))))

But, yeah, I should probably go and start from the very bottom with testing GL on the laptop. It's an older HP, though, which doesn't even have the 950, but 915GM/910GML (what ever that means). Maybe that's asking for too much to let decent GL stuff with shaders run there, LOL.

Well, heck, thanks again, Andrei! I always feel encouraged, when I read your replies! And I think I'll always keep fishing for your reactions for that matter already! :}


_JIM(Posted 2010) [#12]
Sadly, that "thing" they call graphics card doesn't run shaders :(

And feel free to fish my reactions. I am highly interested in what you're doing. Particularly because programmer art usually sucks, and so does artist programming. However, you and I seem to be slight exceptions :)