How to create Glass transparent object with OGRE ?

Advanced game related topics
marc_256
Enthusiast
Enthusiast
Posts: 744
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

How to create Glass transparent object with OGRE ?

Post by marc_256 »

Hi,

I need to create a glass transparent object,
but I can't find a way to do it !!
I did some tests with RGBA() colors ... not working at all.

Is there a solution for this ?

I can't find any post on the forum.

Thanks,
marc
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: How to create Glass transparent object with OGRE ?

Post by IdeasVacuum »

It probably needs an Ogre material script. To get a 'real' glass effect is the realm of the renderer of course.
http://www.ogre3d.org/tikiwiki/Material ... ass_Window
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Fred
Administrator
Administrator
Posts: 16664
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: How to create Glass transparent object with OGRE ?

Post by Fred »

If you only want alpha transparency, there is an example in the package: CreateTexture2.pb (which I just renamed to CreateTextureAlpha.pb)
User avatar
DK_PETER
Addict
Addict
Posts: 898
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: How to create Glass transparent object with OGRE ?

Post by DK_PETER »

Hi marc

Maby something like this could be useful? (Updated)

Use whatever you images want:
images removed (cleanup time)..

Code: Select all

InitEngine3D()
InitSprite()
InitKeyboard()

UseJPEGImageDecoder()

Add3DArchive("\",#PB_3DArchive_FileSystem)


OpenScreen(800,600,32,"Glass test",#PB_Screen_SmartSynchronization,60)

Cam  = CreateCamera(#PB_Any, 0, 0, 100, 100)
MoveCamera(Cam, 0, 0, 30, #PB_Absolute)

light = CreateLight(#PB_Any, $FFFFFF)
MoveLight(light,0,20,20)

Cube1 = CreateCube(#PB_Any, 2)
Cube2 = CreateCube(#PB_Any, 5)
Cube3 = CreateCube(#PB_Any, 7)

Tex1  = LoadTexture(#PB_Any, "crystal.jpg")
Mat1 = CreateMaterial(#PB_Any, TextureID(Tex1))
MaterialBlendingMode(Mat1, #PB_Material_Color)
SetMaterialColor(Mat1, #PB_Material_DiffuseColor, RGBA(255, 255, 255, 100))

Tex2  = LoadTexture(#PB_Any, "glass.jpg")
Mat2 = CreateMaterial(#PB_Any, TextureID(Tex2))
MaterialBlendingMode(Mat2, #PB_Material_Color)
SetMaterialColor(Mat2, #PB_Material_DiffuseColor, RGBA(255, 255, 255, 100))
ScrollMaterial(Mat2,-0.5,0.5,#PB_Material_Animated)

ent1 = CreateEntity(#PB_Any, MeshID(Cube1), #PB_Material_None)
ent2 = CreateEntity(#PB_Any, MeshID(Cube2), MaterialID(Mat1))
ent3 = CreateEntity(#PB_Any, MeshID(Cube3), MaterialID(Mat2))

Repeat
	
	RotateEntity(ent1, 1, 1, -1,#PB_Relative)
	RotateEntity(ent2, -0.5, 0.5, 0.5,#PB_Relative)
	RotateEntity(ent3, 0.5, -0.5, 0.5,#PB_Relative)
	
	ExamineKeyboard()
	
	RenderWorld()
	FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
Best regards
Peter
Last edited by DK_PETER on Sun Sep 15, 2013 10:27 am, edited 3 times in total.
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: How to create Glass transparent object with OGRE ?

Post by applePi »

thanks Peter, also i see this cube a glassy one: http://www.purebasic.fr/english/viewtop ... 36&t=56502
User avatar
Comtois
Addict
Addict
Posts: 1429
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: How to create Glass transparent object with OGRE ?

Post by Comtois »

few material examples here
Please correct my english
http://purebasic.developpez.com/
marc_256
Enthusiast
Enthusiast
Posts: 744
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: How to create Glass transparent object with OGRE ?

Post by marc_256 »

Sorry, was very busy last days :wink:

I study more what I want in details,
what I need are some 50000 freely programmable points (positions, alpha transparency)
Who represents a specific model.
That I can change (positions and alpha transparency) in a loop.

There we go again ...

Thanks for the info.

marc,
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
marc_256
Enthusiast
Enthusiast
Posts: 744
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: How to create Glass transparent object with OGRE ?

Post by marc_256 »

My first test,

I have some light, and colored points and colored lines.
But I do not see any color in the scene... ?

I started with some examples in the PB 3D directory,

Code: Select all

;===================================================================================================
;- TRANSPARENT VIEWER
;===================================================================================================

;---------------------------------------------------------------------------------------------------
;- Setup zone
;---------------------------------------------------------------------------------------------------

	EnableExplicit

;---------------------------------------------------------------------------------------------------
Global Event.i
Global i.l

;===================================================================================================
If InitEngine3D()

	InitSprite()
	InitKeyboard()
	InitMouse()

	If OpenWindow(0, 100, 100, 800, 800, "Alpha Points Test ", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
		OpenWindowedScreen(WindowID(0), 0, 0, 800, 800, 0, 0, 0)
			ClearScreen($009C00)


;---------------------------------------------------------------------------------------------------
;- Create mesh
;---------------------------------------------------------------------------------------------------
	CreateMesh(1, #PB_Mesh_PointList, #PB_Mesh_Static)
		For i = 0 To 5000			;10000
			MeshVertexPosition(Random(500)-250, Random(500)-250, Random(500)-250)
			MeshVertexColor($100000E0)
		Next i


		For i = -250 To 250
			MeshVertexPosition(-250, -250, i)
			MeshVertexColor($100000E0)

			MeshVertexPosition(250, -250, i)
			MeshVertexColor($100000E0)

			MeshVertexPosition(250, 250, i)
			MeshVertexColor($100000E0)

			MeshVertexPosition(-250, 250, i)
			MeshVertexColor($100000E0)



			MeshVertexPosition(i, -250, -250)
			MeshVertexColor($1000E000)

			MeshVertexPosition(i, 250, -250)
			MeshVertexColor($1000E000)

			MeshVertexPosition(i, 250, 250)
			MeshVertexColor($1000E000)

			MeshVertexPosition(i, -250, 250)
			MeshVertexColor($1000E000)



			MeshVertexPosition(-250, i, -250)
			MeshVertexColor($100000E0)

			MeshVertexPosition(250, i, -250)
			MeshVertexColor($100000E0)

			MeshVertexPosition(250, i, 250)
			MeshVertexColor($100000E0)

			MeshVertexPosition(-250, i, 250)
			MeshVertexColor($100000E0)

		Next i

		FinishMesh(#False)

		CreateNode(2)
		AttachNodeObject(2, MeshID(1))

;---------------------------------------------------------------------------------------------------
;- Camera
;---------------------------------------------------------------------------------------------------
		CreateCamera(3, 0, 0, 100, 100)
		MoveCamera(3, 0, 1000, 1000, #PB_Absolute)
		CameraFOV(3, 40)
		CameraLookAt(3, 0, 0, 0)
		CameraBackColor(3, $009C00)
		CameraProjectionMode(3, #PB_Camera_Perspective)
		CameraRenderMode(3, #PB_Camera_Plot)

;---------------------------------------------------------------------------------------------------
;- Light
;---------------------------------------------------------------------------------------------------
		CreateLight(4, RGB(100, 100, 100), 0, 0, 0, #PB_Light_Point)
;		AmbientColor(RGB(190, 190, 190))

;---------------------------------------------------------------------------------------------------
;- DO LOOP ZONE
;---------------------------------------------------------------------------------------------------
		Repeat

			Event = WindowEvent()

			ExamineKeyboard()

			ExamineMouse()

			RotateNode(2, 0.1, 0.1, 0.1, #PB_Relative)

			RenderWorld()

			FlipBuffers()

			Delay(1)

		Until KeyboardPushed(#PB_Key_Escape)
	EndIf

Else
	MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf

End

How come ?

Marc,
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: How to create Glass transparent object with OGRE ?

Post by applePi »

Hi
i can't follow your code, but here a working one adapted from my previous code for xors and it depends completely on meshmanuals examples in the 3D section.
,( success by a pure luck so i will study it later )
it seems to me transparent points, it draws a 100000 points with conditions, and when you press arrow keys it moves a 50000 points from its place to another,
all data are stored in MyMesh array by GetMeshData, press "Q" to display its size
if you don't want tranparency delete line 54.

Code: Select all

Enumeration
   #MESH
   #LIGHT
   #CAMERA
   #mainwin
 EndEnumeration
Structure Vector3
  x.f
  y.f
  z.f
EndStructure
Define.Vector3 v1, v2, v3 


Global x.f = 0
Global y.f = 10
Global z.f = -30
Global Dim MeshData.PB_MeshVertex(0)

ExamineDesktops()
If OpenWindow(#mainwin, 0, 0, DesktopWidth(0), DesktopHeight(0), "press arrows to move some points ", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)


Define.f KeyX, KeyY
Declare UpdateMatrix()
Declare CreateMatrix()
Declare DrawMatrix()

If InitEngine3D()
  
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home + "Examples/Sources\Data", #PB_3DArchive_FileSystem)
  Add3DArchive("/", #PB_3DArchive_FileSystem)
  
  InitSprite()
  InitKeyboard()
  OpenWindowedScreen(WindowID(#mainwin), 0, 0, DesktopWidth(0), DesktopHeight(0)-60, 0, 0, 0)
    
    CreateMaterial(0, LoadTexture(0, "White.jpg"))
    DisableMaterialLighting(0, #True)
    ;MaterialShadingMode(0, #PB_Material_Wireframe     )
    MaterialCullingMode(0, #PB_Material_NoCulling)
    CreateMatrix()
            
    CreateCamera(0, 0, 0, 100, 100)
    MoveCamera(0, 0, 0, 600, #PB_Absolute)
    CameraFOV(0, 70)
    CameraBackColor(0, $330000)
    CameraLookAt(0,0,0,0)
        
    CreateLight(0, RGB(255,255,255), 10, 60, -10)
    AmbientColor(RGB(90, 90, 90))
    
    MaterialBlendingMode(0, #PB_Material_AlphaBlend)   ; allow alphablending and vertex alpha
;MaterialBlendingMode(0, #PB_Material_Add )
;MaterialBlendingMode(0, #PB_Material_Color )
DisableMaterialLighting(0, 1)
       
    Repeat
      Event = WindowEvent()
                  
      If ExamineKeyboard()
                
        If KeyboardReleased(#PB_Key_Right)
          x - 0.4 :UpdateMatrix()
        ElseIf KeyboardReleased(#PB_Key_Left) 
          x - 0.4 :UpdateMatrix()
        EndIf
        
        If KeyboardReleased(#PB_Key_Up)
          y + 0.5:UpdateMatrix()
        ElseIf KeyboardReleased(#PB_Key_Down)
          y - 0.4 :UpdateMatrix()
        ElseIf KeyboardReleased(#PB_Key_Q) 
          MessageRequester( "", Str(ArraySize(MeshData())))
                
        EndIf
        EndIf
      rot.f+0.6
      RotateEntity(0,0,rot,0)
      RenderWorld()
      FlipBuffers()
      
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  EndIf
  
Else
  MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf

End


Procedure DrawMatrix()
    For i=0 To 100000 
  x = Random(200)-100:y = Random(200)-100:z = Random(200)-100
  If y< -80 And z< -80
    r=255:g=0:b=0
    ElseIf x < -80 And z< -80
      r=0:g=255:b=0
       ElseIf x< -80 And y< -80
         r=0:g=0:b=255
       Else
         r=255:g=119:b=119
       EndIf 
;(x - x0)^2 + (y - y0)^2 + (z - z0)^2 <= r^2  
;check if point inside a specific sphere:       
If (Pow(x,2) + Pow(y,2) + Pow(z,2)) <= 4900
  r=0:g=0:b=255
EndIf  

MeshVertexPosition(x, y, z)
MeshVertexColor(RGBA(r,g,b,100))  
;MeshVertexColor(RGB(r,g,b)) 
Next
    
EndProcedure  
Procedure CreateMatrix()
  
  CreateMesh(0, #PB_Mesh_PointList, #True)
  DrawMatrix()
  FinishMesh(#True)
  SetMeshMaterial(0, MaterialID(0))
    
  CreateEntity(0, MeshID(0), #PB_Material_None)
  
  ScaleEntity(0, 2, 2, 2)
  GetMeshData(0,0, MeshData(), #PB_Mesh_Vertex, 0, MeshVertexCount(0)-1)
  
EndProcedure


Procedure UpdateMatrix()
  For i=0 To 50000
      MeshData(i)\x + x
      MeshData(i)\y + y
      MeshData(i)\z + z
      Next    
      SetMeshData(0,0, MeshData(), #PB_Mesh_Vertex, 0, MeshVertexCount(0)-1)
    
    EndProcedure
    
    
marc_256
Enthusiast
Enthusiast
Posts: 744
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: How to create Glass transparent object with OGRE ?

Post by marc_256 »

Hi applePi,

Very nice example,
go to work with it this weekend,
On first view, it is just what I need.

thanks,
marc,
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: How to create Glass transparent object with OGRE ?

Post by applePi »

Marc
i have posted another thread in the 3D section for this points issue
http://www.purebasic.fr/english/viewtop ... 36&t=56635
marc_256
Enthusiast
Enthusiast
Posts: 744
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: How to create Glass transparent object with OGRE ?

Post by marc_256 »

Hi applePi,

That are nice examples, (like always) just what I'm looking for.

Thanks again,
marc
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
marc_256
Enthusiast
Enthusiast
Posts: 744
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: How to create Glass transparent object with OGRE ?

Post by marc_256 »

Hi,

Two weeks ago, they told my father that he haves cancer :evil: :cry:
So I went to the hospital with him a few times, to see the doctor, and taking some CT scans.
When we received the results, the views are in 2D b&w 24 bits (518x518 pixels).
I converted these to 3d images, and after that to a mesh (32 bits), of 150 layers of images.
So with your helps and hints the result till now is this,
a 3D view of my fathers chest with colored cancer part in red.
I made the possibility to zoom, move, rotate and cut parts of the view for better visibility.
Then I colored the selected zone.

http://www.marc-systems.be/scan_view_001.png

I did all this with the snipper of applePi and some examples of PB (thanks for that).
but he use a entity, and after rotating the view to much, it becomes transparent (normals ?).
So, what I need are '3D programmable POINTS', visible from all sides,
I did some test with fred's example ' CreateTexture2.pb' works well, but these points are not transparent.
And also DK_PETER cube example is working very well, but is made with mesh faces.

Is there a better solution for this, help is very appreciated.

Marc,
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: How to create Glass transparent object with OGRE ?

Post by applePi »

Hi
visible from all sides
in the mesh made from triangles usually this phenomena because the absence of this line
MaterialCullingMode(#MAT, #PB_Material_NoCulling )
also try MeshVertexNormal(x, y, z) after every MeshVertexPosition

your mesh are made from points, note that the array MeshData(i) have the structure item \NormalX to Z. but you should first fill the array with mormalize using GetMeshData with #PB_Mesh_Normal then apply something like
MeshData(i)\NormalX = 1
MeshData(i)\NormalY = 1
MeshData(i)\NormalZ = 1
and then use SetMeshData with #PB_Mesh_Normal
may be MeshVertexNormal are sufficient.

think of converting your points mesh to triangles mesh and this is a hard task but there are people who are doing this look
http://meshlabstuff.blogspot.com/2009/0 ... louds.html
http://lcni.uoregon.edu/~dow/Projects/B ... _mesh.html
but it is a nightmare realy, look my post here http://www.forums.purebasic.com/english ... 36&t=54708
and here http://www.purebasic.fr/english/viewtop ... &start=375 a very crude attempt to convert mandelbrot set to mesh (very rough), but it seems the author succeeded
also try MP3D, try the same previous code in MP3D , but i cant give points an alpha i will ask after making more tests

note: the cube are deceiving the eye at first (at least my eyes) but it is rotating left,

Code: Select all

; code for MP3D
Declare DrawMatrix()
;Declare isolate()

Global xres=640, yres=480
MP_Graphics3D (xres,yres,0,3)
SetWindowTitle(0, "Mandel 3D, press Z, X keys to zoom  ")

camera=MP_CreateCamera()

light=MP_CreateLight(2)
MP_LightSetColor (light, RGB(255,255,255))

MP_PositionEntity(light, 0, 10, 20)
MP_EntityLookAt(light,0,0,0)

Global Entity= MP_CreatePrimitives (2000000, 1)   
  

Define.f red, green, blue


Quit.b = #False

;==============================================================
        
MP_ScaleEntity(Entity, 1.5, 1.5, 1.5)
MP_MeshSetBlendColor(Entity, $FFFFFFFF)
MP_MeshSetAlpha(Entity,3)
MP_MeshAlphaSort(Entity)


DrawMatrix()
;MP_SaveMesh("asd.x",Entity) ; not work with points

MP_PositionCamera(camera, 0, 0, 700)
MP_CameraLookAt(camera,0,0,0)
MP_PositionEntity(light, 0 , 0, 10)
MP_EntityLookAt(light,0,0,0)

xx.f=0 :zz.f=0
While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow
  
  If MP_KeyDown(#PB_Key_Z) 
    
    zz.f + 20
  ElseIf MP_KeyDown(#PB_Key_X) 
    
    zz.f - 20
  EndIf 
      
    MP_PositionEntity(Entity, xx, 0, zz)
    MP_TurnEntity(Entity,0,1,0) 
   
  MP_RenderWorld()
   
  MP_Flip ()

Wend

Procedure DrawMatrix()
    For i=0 To 100000 
  x = Random(200)-100:y = Random(200)-100:z = Random(200)-100
  ;(x - x0)^2 + (y - y0)^2 + (z - z0)^2 <= r^2  
;check if point inside a specific sphere:  
  q.f = (Pow(x,2) + Pow(y,2) + Pow(z,2))
  If q <= 4900
    r=0:g=0:b=255
    MP_SetPrimitives(Entity, i,  x, y, z,  MP_ARGB(100,r,g,b))
    ElseIf q > 4900 And q <= 10000
      
      r=255:g=0:b=0
      MP_SetPrimitives(Entity, i,  x, y, z,  MP_ARGB(100,r,g,b))
    ElseIf q>10000
      ;r=255:g=119:b=119
      r=0:g=255:b=0
      MP_SetPrimitives(Entity, i,  x, y, z,  MP_ARGB(100,r,g,b))
   
    
  EndIf 


Next
    
EndProcedure  

    
 
User avatar
DK_PETER
Addict
Addict
Posts: 898
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: How to create Glass transparent object with OGRE ?

Post by DK_PETER »

@Applepi.

Nice example.

@Marc.

yes, you should try mp3d.
My very best wishes to your dad, Marc.
Lost mine last year to the same damn decease. 64 years old.

Best regards
Peter
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
Post Reply