Bump mapping/Normal mapping

Started by
4 comments, last by JackTheRapper 14 years, 5 months ago
Hello everybody this time i need your help =( well im going to add bump mapping to my game so it looks better. the only thing i have succeeded with is reading the bump map and add all the pixel colours in a list from 0 to 1. Now i just wonder how to add it on a simple rectangle polygon with the texture. Here is the code for the wall or something
glPushMatrix()
        
        glTranslatef(*self.pos)
        
        glRotatef(self.rotate[0],1,0,0)
        glRotatef(self.rotate[1],0,1,0)
        glRotatef(self.rotate[2],0,0,1)
        
        glScalef(*self.scale)
        
        glBindTexture(GL_TEXTURE_2D, self.tex)
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
        GL_LINEAR_MIPMAP_LINEAR)

                  
        glBegin(GL_QUADS)
        
        # This is for the normals
        Num0 = 1.0+self.scale[0]
        Num1 = 1.0+self.scale[1]
        Num2 = 1.0+self.scale[2]
        
        glNormal3f(0.0,0.0,Num2) # Front Face
        glTexCoord2f(0.0, 0.0); glVertex3f(-1.0,-1.0,  1.0)
        glTexCoord2f(1.0, 0.0); glVertex3f( 1.0,-1.0,  1.0)
        glTexCoord2f(1.0, 1.0); glVertex3f( 1.0, 1.0,  1.0)
        glTexCoord2f(0.0, 1.0); glVertex3f(-1.0, 1.0,  1.0)

        ###################### 
                                  
        glEnd()

        glPopMatrix()

this is for loading the texture


glGenTextures(2,id); glBindTexture(GL_TEXTURE_2D,id)

        S = pygame.image.load(path).convert_alpha()
        Data = pygame.image.tostring(S, "RGBA", 1)
        xw = S.get_width()
        yw = S.get_height()

        gluBuild2DMipmaps(GL_TEXTURE_2D,GL_RGBA, xw, yw,         GL_RGBA, GL_UNSIGNED_BYTE, Data )

what i have done for the map

S = pygame.image.load(path).convert()
        pxarray = pygame.PixelArray(S)
        for xnum,row in enumerate(pxarray):
            for ynum,pixel in enumerate(row):
                rgba = S.unmap_rgb(pixel)
                r = rgba[0]/255.0
                g = rgba[1]/255.0
                b = rgba[2]/255.0
                self.Rgbpix.append((r,b,g))

please explain to me how i would do this step by step thanks, really appreciate those who will help me !
Advertisement
Quote:well im going to add bump mapping to my game so it looks better

That's not a valid reason. If you don't know the basic concepts of 3D rendering (and 3D APIs) then you will only waste your time when you try to add it.
So, for now, here's your to-do list:
1. Learn the basics of 3D rendering (APIs) like:
- what a vertex consists of, how these components are processed, how they are used..
- textures - how they are stored, what are mipmaps, what effect the texture states have on the usage of textures
- matrices - the concept, storage, math, how OpenGL rendering pipeline uses them
- vectors - vector math (they don't really belong to 3d rendering but they are very useful)
- shaders - the shading language, structure of a vertex/fragment shader program, usage of shaders
- optimal methods for rendering something (not really useful when you deal with bump mapping but helps anyway)
2. Think whether you really need bump mapping or you can get away with a good art direction.. and only then, if you really think you can't live without it,
3. Get an article that describes normal mapping and get a code sample and examine them. !!Don't learn from the source code only because it doesn't help without proper documentation.
Quote:Original post by snake5
Quote:well im going to add bump mapping to my game so it looks better

That's not a valid reason. If you don't know the basic concepts of 3D rendering (and 3D APIs) then you will only waste your time when you try to add it

I do know the basics
i currently have a little world in my game with skybox small boxes with collision,
a really good moving camera on all directions using trigonometry etc
if that was what you meant with bascis

gameo.png
You want to be putting your glTexParameterf stuff in your texture generation code before gluBuild2DMipmaps rather than calling it each rendering frame (it only needs to be set when the texture is being created).

If you want to implement bump mapping, the step up in terms of theory as pretty large compared to basic textured primitive rendering, and I certainly wouldn't want to do it without shaders.

There's basically 2 approaches: object space and tangent space bump mapping. Both have their ups and downs, but tangent space, although a little more difficult, is generally more flexible (and a good skill/knowledge area to get under your belt).

To even consider tackling either, you need a good understanding of mapping to and from the various coordinate systems (tangent/object/world/view/projection) as well as a good understanding of 3D concepts e.g. vector arithmetic, matrices, etc. Also, a good (pratical) uderstanding of shaders is would be necessaryto implement bump mapping without having to use the fixed pipeline.

As snake5 said, it's not really the sort of thing you can learn by plugging in source code from various websites as this is garuanteed to result in failure unless you understand the concepts being implemented.

Anyways, all said and done, here's the articles from my bookmarks folder on tangent space bump mapping:


Tangent Space
-------------

http://www.gamasutra.com/view/feature/1515/messing_with_tangent_space.php?page=2
http://www.gamedev.net/community/forums/topic.asp?topic_id=252198
http://jerome.jouvie.free.fr/OpenGl/Lessons/Lesson8.php
http://www.terathon.com/code/tangent.html
http://www.3dkingdoms.com/weekly/weekly.php?a=37
http://www.gamedev.net/community/forums/topic.asp?topic_id=395336&whichpage=1�

Tangent Space Bump (Normal) Mapping
-----------------------------------
http://www.3dkingdoms.com/tutorial.htm
http://www.paulsprojects.net/tutorials/simplebump/simplebump.html
http://www.ozone3d.net/tutorials/bump_mapping.php
http://www.blacksmith-studios.dk/projects/downloads/bumpmapping_using_cg.php

good luck

[Edited by - JackTheRapper on October 25, 2009 8:16:53 AM]
Thanks allot, gonna check those links
Sorry, that last article isn't really relevent, I've removed it from the list

This topic is closed to new replies.

Advertisement