I'm trying to create cube map for normal map lighting purposes. Instead if calculating vertex to light normal I'll apply "normalcubemap" to mesh (texture 0) and then apply normal map.
This is code that I hacked together for calculating cube map textures.
I think this is not right method to do it as for example front face z component / blue is constant acros the face and it makes normal mapped object little bit flat even if for example a sphere object seems to be lit ok..
Any ideas for correct or better way to make this kind of "normalizing" cube map?
This is code that I hacked together for calculating cube map textures.
;------------------------------------------------------------ ; creates cubemap textures and saves one too as a single image Function MakeCubeFace(tex) image = CreateImage(256,256) cubeimage = CreateImage(256*6, 256) SetBuffer ImageBuffer(image) ; left SetCubeFace tex,0 For y=0 To 255 For z=0 To 255 Color 255, y, 255-z Plot z,y Next Next CopyRect 0,0,256,256,0,0,ImageBuffer(image),TextureBuffer(tex) CopyRect 0,0,256,256,0,0,ImageBuffer(image),ImageBuffer(cubeimage) ;back SetCubeFace tex,1 For x=0 To 255 For y=0 To 255 Color 255-x, y, 0 Plot x,y Next Next CopyRect 0,0,256,256,0,0,ImageBuffer(image),TextureBuffer(tex) CopyRect 0,0,256,256,256,0,ImageBuffer(image),ImageBuffer(cubeimage) ; right SetCubeFace tex,2 For y=0 To 255 For z=0 To 255 Color 0, y, z Plot z,y Next Next CopyRect 0,0,256,256,0,0,ImageBuffer(image),TextureBuffer(tex) CopyRect 0,0,256,256,512,0,ImageBuffer(image),ImageBuffer(cubeimage) ;front SetCubeFace tex,3 For y=0 To 255 For x=0 To 255 Color x, y, 255 Plot x,y Next Next ;EndIf CopyRect 0,0,256,256,0,0,ImageBuffer(image),TextureBuffer(tex) CopyRect 0,0,256,256,256*3,0,ImageBuffer(image),ImageBuffer(cubeimage) ; top SetCubeFace tex,4 For z=0 To 255 For x=0 To 255 Color 255-x, 0, 255-z Plot x,z Next Next CopyRect 0,0,256,256,0,0,ImageBuffer(image),TextureBuffer(tex) CopyRect 0,0,256,256,256*4,0,ImageBuffer(image),ImageBuffer(cubeimage) ;bottom SetCubeFace tex,5 For z=0 To 255 For x=0 To 255 Color 255-x, 255, z Plot x,z Next Next CopyRect 0,0,256,256,0,0,ImageBuffer(image),TextureBuffer(tex) CopyRect 0,0,256,256,256*5,0,ImageBuffer(image),ImageBuffer(cubeimage) SaveImage (cubeimage,"cubemap6.bmp") FreeImage(image) FreeImage(cubeimage) SetBuffer BackBuffer() End Function
I think this is not right method to do it as for example front face z component / blue is constant acros the face and it makes normal mapped object little bit flat even if for example a sphere object seems to be lit ok..
Any ideas for correct or better way to make this kind of "normalizing" cube map?