CubeMapping

Everything related to 3D programming
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

CubeMapping

Post by applePi »

i have watched in the "Ogre Demos 1.7.0" the cube map example in witch the ogre head reflect the clouds and a rotating fish, i saw in the PB docs the CreateCubeMapTexture and EntityCubeMapTexture functions, i understand that the TextureName$ in CreateCubeMapTexture is virtual ie dynamic which will reflect the surrounding, i have tried the same example in Ogre Demos 1.7.0 but without the fish but it is enough to reflect the clouds and the red plane beneath. the ogrehead is here
http://www.mediafire.com/?2y6wu85z6tovxy8
but i don't see reflection. i have done a million experimnets but failed.
PS: i have corrected the code on the light of the code posted by Fred, now the Ogrehead textured and it is reflecting a real time rotating red cube also the plane beneath
use this texture to texture the ogre head with gold
Image
the texture are added using
AddMaterialLayer(1, TextureID(4) , #PB_Material_Modulate )

Image
the material script i have used is the same in the docs:

Code: Select all

material CubeMapMaterial
  {
    technique
    {
      pass
      {
        texture_unit
        {
          cubic_texture CubeMapTexture combinedUVW
          tex_address_mode clamp
          env_map cubic_reflection
        }
      }
    }
  }

Code: Select all

Enumeration
   #MESH
   #TEXTURE
   #TEX
   #MATERIAL
   #ENTITY
   #CAMERA_ONE
   #LIGHT
   #cube
   #cube2
EndEnumeration

;Set the width, height and bit depth of the screen
;Abbreviated variables are used here due to page width constraints :(
;Global ScrW.l = 1024
;Global ScrH.l = 768
Global ScrW.l = 800
Global ScrH.l = 600
Global ScrD.l = 32
;Other global variables
Global Quit.b = #False

;Simple error checking procedure
Procedure HandleError(Result.l, Text.s)
   If Result = 0
      MessageRequester("Error", Text, #PB_MessageRequester_Ok)
      End
   EndIf
EndProcedure

;Initialize environment
HandleError(InitEngine3D(), "InitEngine3D() command failed.")
HandleError(InitSprite(), "InitSprite() command failed.")
HandleError(OpenScreen(ScrW, ScrH, ScrD, ""), "Could not open screen.")
HandleError(InitKeyboard(), "InitKeyboard() command failed.")
SetFrameRate(60)

Add3DArchive("Data\", #PB_3DArchive_FileSystem)
Add3DArchive(".", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/Sources\Data", #PB_3DArchive_FileSystem)
Parse3DScripts()
;SkyDome("clouds.jpg",2)
MyCubeMap = CreateCubeMapTexture(#PB_Any, 256, 256, "CubeMapTexture")
GetScriptMaterial(1,"CubeMapMaterial")
SetMaterialColor(1, #PB_Material_SelfIlluminationColor, $FFFFFF)

Mesh = LoadMesh(#PB_Any,"ogrehead.mesh")
Entity = CreateEntity(#PB_Any,MeshID(Mesh),MaterialID(1))
EntityCubeMapTexture(MyCubeMap, Entity)
MoveEntity(Entity, 0,0,0)
  
CreateMaterial(4, LoadTexture(4, "gold.png"))
  
;;0000000000000000000000000000000000000000000000    
CreateCube(#cube,10)
CreateMaterial(2, LoadTexture(2, "MRAMOR6X6.jpg"))
MaterialCullingMode(2, #PB_Material_NoCulling)
DisableMaterialLighting(1, 0)
 CreateEntity(#cube,  MeshID(#cube), MaterialID(2))
 ScaleEntity(#cube, 10,0.1,10)
 MoveEntity(#cube, 0,-30,0)
 
 CopyMesh(#cube, #cube2)
 CreateMaterial(3, LoadTexture(3, "Geebee2.bmp"))
 CreateEntity(#cube2,  MeshID(#cube2), MaterialID(3))
 ScaleEntity(#cube2, 0.7,0.7,0.7)
 MoveEntity(#cube2, -30,10,0)
AddMaterialLayer(1, TextureID(4) , #PB_Material_Modulate   )

CreateLight(#LIGHT, RGB(255,255,255),12.9, 72, 15.7)
CreateCamera(#CAMERA_ONE, 0, 0, 100, 100)
MoveCamera(#CAMERA_ONE, 0, 30, 100)

;Main loop
Repeat

CameraLookAt(#CAMERA_ONE, 0, 0, 0)
MoveEntity(#cube2,0, 0, -0.1, #PB_Local)
   RotateEntity(#cube2, 0, -1, 0, #PB_Relative)
   RenderWorld()
   FlipBuffers()

   ExamineKeyboard()
   If KeyboardReleased(#PB_Key_Escape)
      Quit = #True
   EndIf
Until Quit = #True
End
a more friendly windowed version :

Code: Select all

Enumeration
   #mainwin
   #MESH
   #TEXTURE
   #TEX
   #MATERIAL
   #ENTITY
   #CAMERA_ONE
   #LIGHT
   #cube
   #cube2
EndEnumeration

Global Quit.b = #False

;Simple error checking procedure
Procedure HandleError(Result.l, Text.s)
   If Result = 0
      MessageRequester("Error", Text, #PB_MessageRequester_Ok)
      End
   EndIf
EndProcedure

ExamineDesktops()
OpenWindow(#mainwin, 0, 0, DesktopWidth(0), DesktopHeight(0), "cube mapping reflection ", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

;Initialize environment
HandleError(InitEngine3D(), "InitEngine3D() command failed.")
HandleError(InitSprite(), "InitSprite() command failed.")
;HandleError(OpenScreen(ScrW, ScrH, ScrD, ""), "Could not open screen.")
HandleError(InitKeyboard(), "InitKeyboard() command failed.")
OpenWindowedScreen(WindowID(#mainwin), 0, 0, DesktopWidth(0), DesktopHeight(0)-60, 0, 0, 0)
   
SetFrameRate(60)

Add3DArchive("Data\", #PB_3DArchive_FileSystem)
Add3DArchive(".", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/Sources\Data", #PB_3DArchive_FileSystem)
Parse3DScripts()
;SkyDome("clouds.jpg",2)
MyCubeMap = CreateCubeMapTexture(#PB_Any, 256, 256, "CubeMapTexture")
GetScriptMaterial(1,"CubeMapMaterial")
SetMaterialColor(1, #PB_Material_SelfIlluminationColor, $FFFFFF)

Mesh = LoadMesh(#PB_Any,"ogrehead.mesh")
Entity = CreateEntity(#PB_Any,MeshID(Mesh),MaterialID(1))
EntityCubeMapTexture(MyCubeMap, Entity)
MoveEntity(Entity, 0,0,0)
  
CreateMaterial(4, LoadTexture(4, "gold.png"))
  
;;0000000000000000000000000000000000000000000000    
CreateCube(#cube,10)
CreateMaterial(2, LoadTexture(2, "MRAMOR6X6.jpg"))
MaterialCullingMode(2, #PB_Material_NoCulling)
DisableMaterialLighting(1, 0)
 CreateEntity(#cube,  MeshID(#cube), MaterialID(2))
 ScaleEntity(#cube, 10,0.1,10)
 MoveEntity(#cube, 0,-30,0)
 
 CopyMesh(#cube, #cube2)
 CreateMaterial(3, LoadTexture(3, "Geebee2.bmp"))
 CreateEntity(#cube2,  MeshID(#cube2), MaterialID(3))
 ScaleEntity(#cube2, 0.7,0.7,0.7)
 MoveEntity(#cube2, -30,10,0)
AddMaterialLayer(1, TextureID(4) , #PB_Material_Modulate   )

CreateLight(#LIGHT, RGB(255,255,255),12.9, 72, 15.7)
CreateCamera(#CAMERA_ONE, 0, 0, 100, 100)
MoveCamera(#CAMERA_ONE, 0, 30, 100)

;Main loop
Repeat
Event = WindowEvent()
CameraLookAt(#CAMERA_ONE, 0, 0, 0)
MoveEntity(#cube2,0, 0, -0.1, #PB_Local)
   RotateEntity(#cube2, 0, -1, 0, #PB_Relative)
   RenderWorld()
   FlipBuffers()

   ExamineKeyboard()
   If KeyboardReleased(#PB_Key_Escape) Or Event = #PB_Event_CloseWindow
      Quit = #True
   EndIf
Until Quit = #True
End
Last edited by applePi on Wed Jul 17, 2013 8:14 pm, edited 2 times in total.
Fred
Administrator
Administrator
Posts: 18384
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: CubeMapping

Post by Fred »

Here is a full example to get you started:

http://www.purebasic.com/CubeMap.zip

I will add an example in the example folder for the final.
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: CubeMapping

Post by applePi »

this is a great gift, thank you Fred, this is an ethereal reflection scene, i have tried also the OgreHead.mesh and it is an eerie figure in this context , i have noticed that this is the most problematic and esoteric subject in the ogre forum .
best wishes
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: CubeMapping

Post by Danilo »

Fred wrote:Here is a full example to get you started:

http://www.purebasic.com/CubeMap.zip
Worked nicely with 5.20 beta 6. Now with beta 7 it is very slow, like 0.5 FPS maximum.

Mac OS X 10.8.4, Intel HD 4000 graphics.
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: CubeMapping

Post by applePi »

i have tried the cubmap (airplane and rotations and reflections) in windows xp , Geforce 210, the performance seems to me the same either in beta6 or beta7 : in the default subsys or opengl.
i saw there are a new example CubeMapping.pb inside 3D examples.
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: CubeMapping

Post by Danilo »

applePi wrote:i have tried the cubmap (airplane and rotations and reflections) in windows xp , Geforce 210, the performance seems to me the same either in beta6 or beta7 : in the default subsys or opengl.
What I said was for Mac only. Worked fine with beta6, unusable slow with beta7.
applePi wrote:i saw there are a new example CubeMapping.pb inside 3D examples.
Saw that too, but unfortunately all 3D examples that use Screen3DRequester.pb don't work anymore because there is a new InitMouse() bug on Mac OS X now. ;)
(3D examples work if I move all InitMouse() calls after Screen3DRequester() call)

EDIT:
If i replace SkyBox("Earth01.jpg") in Fred's example with SkyBox("Desert07.jpg") from PB 3D examples, it works fast again.
Don't know what has been changed between betas, but looks like Earth texture is too big now. Smaller Desert07 skybox textures are good.
User avatar
Lexicon
User
User
Posts: 98
Joined: Mon Jul 22, 2013 6:16 am
Contact:

Re: CubeMapping

Post by Lexicon »

Cube map textures

The cube map texture type (TEX_TYPE_CUBE_MAP) is a different beast from the others; a cube map texture represents a series of six two dimensional images addressed by 3D texture coordinates.

+X (face 0)

Represents the positive x plane (right).
-X (face 1)

Represents the negative x plane (left).
+Y (face 2)

Represents the positive y plane (top).
-Y (face 3)

Represents the negative y plane (bottom).
+Z (face 4)

Represents the positive z plane (front).
-Z (face 5)

Represents the negative z plane (back).

http://www.ogre3d.org/docs/manual/manua ... ture-Types
Where is the explanation? How can I make a cube with 6 textures? :?:
How to be called texture files? Where are the examples? You can only sit and think ...
PureBasic 5.11 | WinXP | 2GB RAM | GForce GT240
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 756
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: CubeMapping

Post by Samuel »

I believe a cube map texture is built the same way as textures for skyboxs.
This is the format for a skybox.

PictureName_BK.png
PictureName_FR.png
PictureName_RT.png
PictureName_LF.png
PictureName_DN.png
PictureName_UP.png

ApplePI's example doesn't use a textured cube map though. Are you having trouble running the code? Because it works fine for me.
So, I might be able to help you, but I'm not sure what part your stuck on.
Fred
Administrator
Administrator
Posts: 18384
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: CubeMapping

Post by Fred »

There is now a CubeMapping.pb example in 5.20 3D/ folder as well.
User avatar
Lexicon
User
User
Posts: 98
Joined: Mon Jul 22, 2013 6:16 am
Contact:

Re: CubeMapping

Post by Lexicon »

Samuel wrote:I believe a cube map texture is built the same way as textures for skyboxs.
This is the format for a skybox.

PictureName_BK.png
PictureName_FR.png
PictureName_RT.png
PictureName_LF.png
PictureName_DN.png
PictureName_UP.png

ApplePI's example doesn't use a textured cube map though. Are you having trouble running the code? Because it works fine for me.
So, I might be able to help you, but I'm not sure what part your stuck on.
This is material for cubemap:

Code: Select all


material CubeMapMaterial
{
	technique
	{
		pass
		{
			texture_unit
			{
				cubic_texture CubeMapTexture combinedUVW
				tex_address_mode clamp
				env_map cubic_reflection
			}
		}
	}
}

Where is the texture's name? And what is the format?
Can you give me a little example code and example material for sky box that using cubemap?

Thanks
PureBasic 5.11 | WinXP | 2GB RAM | GForce GT240
User avatar
Lexicon
User
User
Posts: 98
Joined: Mon Jul 22, 2013 6:16 am
Contact:

Re: CubeMapping

Post by Lexicon »

Fred wrote:There is now a CubeMapping.pb example in 5.20 3D/ folder as well.
Fred I have not PB 5.20
PureBasic 5.11 | WinXP | 2GB RAM | GForce GT240
Fred
Administrator
Administrator
Posts: 18384
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: CubeMapping

Post by Fred »

Cubemap texture automatically reflect the sourrounding, so there is no special texturename or anything. What you are refereing is standard skybox textures.
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: CubeMapping

Post by PMV »

Lexicon wrote: Where is the texture's name? And what is the format?
Can you give me a little example code and example material for sky box that using cubemap?

Thanks
http://www.ogre3d.org/docs/manual/manua ... 05ftexture
http://www.ogre3d.org/docs/manual/manua ... nv_005fmap

The example is already given by fred ... just use the link from fred and download that zip. :)
Post Reply