Advertisement

Normal Mapping Code

Started by June 20, 2004 02:00 PM
43 comments, last by cippyboy 20 years, 5 months ago
with shaders it's always best to keep them in external files, not to compile them in...
That way you can have notepad open, and just add a key like 'R' to reload them.. so editing and refining them is very simple and fast

The flexibility pixel and vertex shaders give you is most definitly worth the time invested in getting a robust shader system into your code. Once you start using them they just become another tool like texturing, blending, etc. Ie, you won't go back to trying to do the same things without them.
Quote: Original post by cippyboy
Vertex/Pixel Shaders... ? I haven`t entered that area, it feels strange, it feels like writing a huge amount of code, but I`ll do it some day :)

Oddly enough, you have to write much less code for pixel and vertex shaders than for any other shading capibility (I mean, setting up thigs like texture env combine). The problem with shaders is that (i) you won't be able to execute them if the hardware doesn't support it or if the driver doesn't expose a software emulation, and (ii) you need to have a pretty good knowledge of the OpenGL pipeline in order to understand what you are doing with shaders, why it works, and what are the limitations.
Advertisement
[vincoof] & [RipTorn] Thanks a lot for the tips, I`ll try to put something up later this summer, now I`m working in another field and I don`t like to leave it undone, but thanks anyways ;)

[RipTorn] I really like the distorsion/refraction effect on some sandy scene(found on youre site), does it slow down rendering a lot ? I was just curios :)

Relative Games - My apps

yes that effect does hit rendering a fair bit.. you can't directly fudge the colour buffer like that so you need textures, so there are two render-textures, one for reflection and one for refraction. To make it even more annoying they both must be clipped so you need to render the main view twice.. so you end up rendering the scene 3 times. However, I feel it's worth it, and with use of portals and enough frustum culling it's not as bigger hit as you'd expect.. At least on ati hardware where shaders don't eat up so much time.
Oh... ok! That sounds kool, by the way if where`s still here, I`ve seen some games with some kind of depthblur effect, how can you do that without shaders ? if it`s possible ?

Relative Games - My apps

If you mean depth-fo-field effects, then yes it's possible without shaders. Typically, there are two methods, but both are pretty slow unfortunately :

1- render the scene multiple times in the accumulation buffer with a slight projection matrix change every time (around the focused plane) and blend all scenes. (that's the way depth-of-field is explained in the Red Book)

2- render your scene to texture, use hardware mipmapping, and map this texture onto a 'whole quad' over the screen, but use a bias mipmap level, and blend according to the distance to the focused plane.

The problem with the first one is that accumulation buffer is not supported on all hardware, and the few hardware that can support it already support fragment shaders so it's better to use shaders then. Moreover the accumulation buffer based DOF effect is very slow because you have to render the scene many times in order to get a good effect.
Advertisement
[vincoof] Thanks a lot :). Uh... how do I manualy get the mipmap levels ? I could render the viewport at 3-4 resolutions and stuff but that would be slow(I guess)

Relative Games - My apps

If you want to use a blurred texture, use texture filter control (*) for biasing and hardware mipmapping (**) for filling the mipmap levels.

(*) glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 2.f);

(2.f means you bias 2 level of mipmaps, which means you get the average of 16 neighbouring pixels, but you could use another bias value if you want)
This should be done at the texture unit level.

(**) glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);

This should be done at the texture object level.

PS: hope you know the difference between texture units and texture objects.
[vincoof] I`m sorry to say that... I don`t really know the difference(Texture unit, like in multitexturing and texture object, like the ID passed to glBindTexture() right ?) or I don`t understand what you actually said...
I see that the LOD BIAS is a texture enviroment so It`ll be easy to implement that if I have(which one ?) these extensions GL_EXT_texture_lod
GL_EXT_texture_lod_bias
GL_EXT_texture_object
The second looks like a texture parameter so... in order to use the the above I need to generate the mipmaps accordingly(like you mentioned right ?) for that I`ll need to have the GL_SGIS_generate_mipmap extension ?

I mentioned all that because at least I wanna have things clear, hope I don`t mind anyone with my... stupid questions

Relative Games - My apps

Right on all points. And I belive you only need GL_EXT_texture_lod_bias for that (GL_EXT_texture_object has been in core since v1.1 or so).
You should never let your fears become the boundaries of your dreams.

This topic is closed to new replies.

Advertisement