Demo - Morphing

Everything related to 3D programming
AZJIO
Addict
Addict
Posts: 1312
Joined: Sun May 14, 2017 1:48 am

Re: Demo - Morphing

Post by AZJIO »

https://disk.yandex.ru/d/h2lYYJcTrQaHEg

Code: Select all

08:12:30: All done
08:12:30: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at OgreGpuProgramParams.cpp (line 1441)
08:12:30: Texture: Dirt.jpg: Loading 1 faces(PF_R8G8B8,256x256x1) with 8 generated mipmaps from Image. Internal format is PF_X8R8G8B8,256x256x1.
08:12:30: Texture: soil_wall.jpg: Loading 1 faces(PF_R8G8B8,512x512x1) with 9 generated mipmaps from Image. Internal format is PF_X8R8G8B8,512x512x1.
08:12:30: Texture: MRAMOR6X6.jpg: Loading 1 faces(PF_R8G8B8,600x600x1) with 10 generated mipmaps from Image. Internal format is PF_X8R8G8B8,1024x1024x1.
08:12:30: Texture: Wood.jpg: Loading 1 faces(PF_R8G8B8,256x256x1) with 8 generated mipmaps from Image. Internal format is PF_X8R8G8B8,256x256x1.
08:12:30: Texture: DosCarte.png: Loading 1 faces(PF_A8R8G8B8,260x372x1) with 9 generated mipmaps from Image. Internal format is PF_A8R8G8B8,512x512x1.
08:12:30: Texture: RustySteel.jpg: Loading 1 faces(PF_R8G8B8,256x256x1) with 8 generated mipmaps from Image. Internal format is PF_X8R8G8B8,256x256x1.
08:12:30: OGRE EXCEPTION(5:ItemIdentityException): Unable to locate fragment program called sh0FP. in GpuProgramUsage::setProgramName at OgreGpuProgramUsage.cpp (line 73)
User avatar
pf shadoko
Enthusiast
Enthusiast
Posts: 280
Joined: Thu Jul 09, 2015 9:07 am

Re: Demo - Morphing

Post by pf shadoko »

@AZJIO
strange, the log indicates that you are in opengl 1.10 (your machine is not so old)
User avatar
StarBootics
Addict
Addict
Posts: 984
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: Demo - Morphing

Post by StarBootics »

I'm on Linux with a dual monitor and the demo don't work as is. I have to comment the Window flags #PB_Window_ScreenCentered|#PB_Window_BorderLess to make it to work otherwise I'm ending up with a white screen, one half on the left monitor and the other half on the right monitor.

Beside that nice job.

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
User avatar
pf shadoko
Enthusiast
Enthusiast
Posts: 280
Joined: Thu Jul 09, 2015 9:07 am

Re: Demo - Morphing

Post by pf shadoko »

I think this problem is not specific to my demo
can you try #PB_Window_ScreenCentered|#PB_Window_BorderLess on another example
if the problem is the same make a bug report otherwise let me know
User avatar
StarBootics
Addict
Addict
Posts: 984
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: Demo - Morphing

Post by StarBootics »

pf shadoko wrote: Tue Mar 28, 2023 12:04 pm I think this problem is not specific to my demo
can you try #PB_Window_ScreenCentered|#PB_Window_BorderLess on another example
if the problem is the same make a bug report otherwise let me know
I just try your Mountain demo even if it work I still experience half of the screen is on the left monitor and the other half is on the right monitor.

With the morphing demo, as I have said I have a white Screen with the mouse cursor stuck in the middle of the screen and I have half of the screen on the left monitor and the other half on the right monitor. If I remove the flags #PB_Window_ScreenCentered|#PB_Window_BorderLess everything work fine.

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
User avatar
pf shadoko
Enthusiast
Enthusiast
Posts: 280
Joined: Thu Jul 09, 2015 9:07 am

Re: Demo - Morphing

Post by pf shadoko »

Have you tried with PB examples?
User avatar
StarBootics
Addict
Addict
Posts: 984
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: Demo - Morphing

Post by StarBootics »

pf shadoko wrote: Tue Mar 28, 2023 5:53 pm Have you tried with PB examples?
To be honest, I'm very busy with own 3D engine development that I don't have time to play around with the 3D engine supplied with PB.

So the answer to your question is NO !
The Stone Age did not end due to a shortage of stones !
User avatar
pf shadoko
Enthusiast
Enthusiast
Posts: 280
Joined: Thu Jul 09, 2015 9:07 am

Re: Demo - Morphing

Post by pf shadoko »

this said, screencentered is useless since we are in full screen

(I was just talking about taking one of PB's 3D examples and testing it in windowedscreen with screencentered, to see how it behaves with 2 screens )
AZJIO
Addict
Addict
Posts: 1312
Joined: Sun May 14, 2017 1:48 am

Re: Demo - Morphing

Post by AZJIO »

The "Mountain" example works for me on Linux, I wanted to see how it would be on Windows.
I have a problem in Windwos, examples with sprites taken from the help file give an error.
User avatar
DK_PETER
Addict
Addict
Posts: 898
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Demo - Morphing

Post by DK_PETER »

Try this: WindowEvent is not handled correctly

Code: Select all

Procedure ColorBlend(color1.l, color2.l, blend.f)
    Protected r.w,g.w,b.w,a.w
    r=  Red(color1) + (Red(color2)     - Red(color1)) * blend
    g=Green(color1) + (Green(color2) - Green(color1)) * blend
    b= Blue(color1) + (Blue(color2) -   Blue(color1)) * blend
    a=Alpha(color1) + (Alpha(color2) - Alpha(color1)) * blend
    ProcedureReturn  RGBA(r,g,b,a)
EndProcedure

ExamineDesktops()
InitEngine3D():InitSprite():InitKeyboard():InitMouse()
ex=DesktopWidth (0)*1
ey=DesktopHeight(0)*1
OpenWindow(0, 0,0, ex,ey, "Test 3d - [F1, F2, F3, F4] - Change sample - [F12] Wireframe -  [Esc] quit",#PB_Window_ScreenCentered|#PB_Window_BorderLess)
OpenWindowedScreen(WindowID(0), 0, 0, ex, ey, 0, 0, 0)
 
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures",#PB_3DArchive_FileSystem)
Parse3DScripts()

CreateCamera(0, 0, 0, 100, 100):MoveCamera(0,0,0,-18):CameraLookAt(0,0,0,0)
CreateLight(0,$ffffff, 10000, 10000, 0000):SetLightColor(0,#PB_Light_SpecularColor,$ffffff)
AmbientColor($777777)

vert_pg.s="%%%#version 130%%uniform mat4 worldviewproj_matrix;//+24%uniform vec4 camera_pos_os;//+77%uniform vec4 light_pos_os;//+44 0%uniform vec4 light_att;//+41 0%uniform vec4 fog_params;//+31%%varying vec3 oviewdir;%varying vec3 olightdir;%varying vec3 onormal;%varying vec4 ovcolor;%varying float olightatt;%varying vec2 ouv;%%void main()%{%oviewdir=normalize(camera_pos_os.xyz-gl_Vertex.xyz);%olightdir=normalize(light_pos_os.xyz-gl_Vertex.xyz);%gl_Position=worldviewproj_matrix*gl_Vertex;%onormal=gl_Normal;%float Dist=distance(light_pos_os,gl_Vertex);%olightatt=1.0/(light_att.y+light_att.z*Dist+light_att.w*Dist*Dist);%ouv=(gl_TextureMatrix[0]*gl_MultiTexCoord0).xy;%ovcolor=gl_Color;%}%%%%"
frag_pg.s="%%%#version 130%%uniform vec4 diffuse_ml;//+69 0%uniform vec4 specular_ml;//+70 0%uniform vec4 ambient_ml;//+67 0%uniform float shininess;//+36%uniform float blend;//0.5%%uniform sampler2D tx1;//0%uniform sampler2D tx2;//1%%varying vec3 oviewdir;%varying vec3 olightdir;%varying vec3 onormal;%varying vec4 ovcolor;%varying float olightatt;%varying vec2 ouv;%%void main()%{%vec3 normal=normalize(onormal);if (gl_FrontFacing==false) normal*=-1;%vec3 viewdir=normalize(oviewdir);%vec3 lightdir=normalize(olightdir);%%vec4 tcolor=vec4(mix(texture(tx1,ouv),texture(tx2,ouv),blend))*ovcolor;%%float dif=max(dot(lightdir,normal),0)*olightatt;%float spe=pow(max(dot(normalize(lightdir+viewdir),normal),0),shininess);%gl_FragColor=vec4(tcolor.rgb,1)*(ambient_ml+diffuse_ml*dif)+specular_ml*tcolor.a*spe;%}%%%"

CreateShader(0,vert_pg,frag_pg)

LoadTexture(0, "Dirt.jpg")
LoadTexture(1, "soil_wall.jpg")  
LoadTexture(2, "MRAMOR6X6.jpg")
LoadTexture(3, "Wood.jpg")
LoadTexture(4, "DosCarte.png")
LoadTexture(5, "RustySteel.jpg")

Procedure material(n,tx,scale,culling,tx0=0,tx1=0)
	CreateShaderMaterial(n,0):MaterialShaderTexture(n,TextureID(tx0),TextureID(tx1),0,0)
  MaterialShininess(n,256,$ffffff)
  If culling:MaterialCullingMode(n,#PB_Material_AntiClockWiseCull):EndIf
  MaterialFilteringMode(n,#PB_Material_Anisotropic,4)
  ScaleMaterial(n,1/scale,1/scale)
EndProcedure

Structure PB_MeshVertexV
  p.vector3
  n.vector3
  t.vector3
  u.f
  v.f
  color.l
EndStructure

Procedure Mix3D(*R.Vector3, *V1.Vector3, *V2.Vector3, r.f)
  *R\x = *V1\x + r * (*V2\x - *V1\x)
  *R\y = *V1\y + r * (*V2\y - *V1\y)
  *R\z = *V1\z + r * (*V2\z - *V1\z)
EndProcedure

Global n=64,n2=n/2
Global Dim p0.vector3(n,n)
Global Dim p1.vector3(n,n)
Global Dim t.PB_MeshVertexv(n,n)
For j=0 To n
	For i=0 To n
		With t(i,j)
			\u=i/n
			\v=j/n
			\color=$ffffffff
		EndWith
	Next
Next

Procedure mesh_morph(r.f)
  For j=0 To n
    For i=0 To n
        Mix3D(t(i,j)\p,p0(i,j),p1(i,j) ,r)
    Next
  Next
  CreateDataMesh(0,t(),8+2)
  CreateEntity(0,MeshID(0),MaterialID(0),0,0,0)
  CreateEntity(1,MeshID(0),MaterialID(1),0,0,0)
EndProcedure

Procedure geometrie(Array p.vector3(2),num,a.f,b.f,c.f,m=0)
  Protected.f u,v
  For j=0 To n
    For i=0 To n
      With p(i,j)  
        u=(j-n2*m)/n*2*#PI
        v=(i-n2*m)/n*2*#PI   
        Select num
          Case 0; double torre
            \x=(a+b*(Cos(u)*Sin(v/2)-Sin(u)*Sin(v)))*Cos(u*2)
            \y=(a+b*(Cos(u)*Sin(v/2)-Sin(u)*Sin(v)))*Sin(u*2)
            \z=-b*4*(Sin(u)*Sin(v/2)+Cos(u)*Sin(v))
          Case 1; sphere
            u/2
            \x=a*Sin(u)*Cos(v)
            \y=b*Sin(u)*Sin(v)
            \z=c*Cos(u)
          Case 2; coquille
            u*4
            \x=(a+b*Cos(v))*Exp(c*u)*Cos(u)
            \y=(a+b*Cos(v))*Exp(c*u)*Sin(u)
            \z=(3*a+b*Sin(v))*Exp(c*u)-5
          Case 3; coussin
            u/2
            \x=a*Sin(u)
            \y=b*Sin(v)
            \z=c*Cos(u)*Cos(v)/Sqr(2)
          Case 4; tetraedre
            \x=a*Cos(u)
            \y=b*Cos(v)
            \z=-c*Cos(u+v)
           Case 5; fleur
            \x=u*Cos(v)
            \y=u*Sin(v)
            \z=a*Cos(b*v)
          Case 6; dé creux
            \x=a*Sin(u)
            \y=a*Sin(v)
            \z=a*Sin(u+v)
          Case 7; truc
            \x=a*(u/(1+u*u+v*v))
            \y=b*(v/(1+u*u+v*v))
            \z=-c*(u*v/(1+u*u+v*v))
          Case 8; goutte
            u/2
            \x=b/2*a*Sin(u)*Cos(v)
            \y=b/2*a*Sin(u)*Sin(v)
            \z=8-a*4*Sin(u/2)
          Case 9; octaedre
            v/2
            \x=a*Pow(Cos(v),b)*Pow(Cos(u),c)
            \y=a*Pow(Cos(v),b)*Pow(Sin(u),c)
            \z=a*Pow(Sin(v),b)
          Case 10; berlingo
            u/#PI
            \x=b*a*(1+u)*Cos(v)
            \y=b*a*(1-u)*Sin(v)
            \z=-a*u
          Case 11 ;tri truc
            u/(2*#PI)
            b=3*Cos(u)/(Sqr(2)-a*Sin(2*u)*Sin(3*v))
            \x=b*(Cos(u)*Cos(2*v)+Sqr(2)*Sin(u)*Cos(v))
            \y=b*(Cos(u)*Sin(2*v)-Sqr(2)*Sin(u)*Sin(v))
            \z=-b*3*Cos(u)+8
        EndSelect
     EndWith 
    Next
  Next
EndProcedure

Procedure sample(Array p.vector3(2),num)
  ;num=1;If Random(1):num=12:Else:num=2:EndIf
  Select num
    Case 0:geometrie(p(),0,4,1,0,0)
    Case 1:geometrie(p(),1,8,6,3,0)
    Case 2:geometrie(p(),2,3,4,-0.1,0)
    Case 3:geometrie(p(),3,6,6,4,1)
    Case 4:geometrie(p(),4,4,4,5,1)
    Case 5:geometrie(p(),5,1,7,0,0)
    Case 6:geometrie(p(),6,4,0,0,0)
    Case 7:geometrie(p(),7,10,10,10,1)
    Case 8:geometrie(p(),8,3,4,0,0)
    Case 9:geometrie(p(),9,8,3,3,1)
    Case 10:geometrie(p(),10,6,0.5,0,1)
    Case 11:geometrie(p(),11,1,0,0,0)
    Case 12:geometrie(p(),2,4,3,-0.15,0)
    Case 13:geometrie(p(),5,2,3,0,0)
    Case 14:geometrie(p(),9,7,3,1,1)
    Case 15:geometrie(p(),9,6,1,3,1)
  EndSelect
EndProcedure

Define cpt,co0,co1,co,cf,cf0,cf1,tx0,tx1, dt_trans=60*4:dt_tot=60*6
Define.f rx,ry,rz,trans, ev, Quit = #False

Repeat
  Repeat 
    ev = WindowEvent()
    If ev = #PB_Event_CloseWindow : Quit = #True : EndIf
  Until  ev = 0
	If cpt=0
		CopyArray(p1(),p0()):sample(p1(),Random(15))
		co0=co1:co1=RGB(Random(127),Random(127),Random(127))
		cf0=cf1:cf1=RGB(Random(255),Random(255),Random(255))
		tx0=tx1:tx1=Random(5)
		material(0,0,4,0,tx0,tx1)
		material(1,1,4,1,tx0,tx1)
	EndIf
	If cpt<=dt_trans
		trans=(1-Cos(cpt/dt_trans*#PI))/2
		mesh_morph(trans)
		MaterialShaderParameter(0,1,"blend",#PB_Shader_Float,trans,0,0,0)
		MaterialShaderParameter(1,1,"blend",#PB_Shader_Float,trans,0,0,0)
		co=ColorBlend(co0,co1,trans)
		SetMaterialColor(0,#PB_Material_AmbientColor|#PB_Material_DiffuseColor,$808080+co)
		SetMaterialColor(1,#PB_Material_AmbientColor|#PB_Material_DiffuseColor,$ffffff-co)
		cf=ColorBlend(cf0,cf1,trans)
    CameraBackColor(0,cf)
	EndIf
	ExamineMouse()
	ExamineKeyboard()
	If KeyboardReleased(#PB_Key_F12):fdf=1-fdf:If fdf:CameraRenderMode(0,#PB_Camera_Wireframe):Else:CameraRenderMode(0,#PB_Camera_Textured):EndIf:EndIf
	If KeyboardPushed(#PB_Key_Space)=0:cpt=(cpt+1)%dt_tot:EndIf
	
	rx+0.8:ry+0.5:rz+0.6
	RotateEntity(0,rx,ry,rz,0)
	RotateEntity(1,rx,ry,rz,0)
	RenderWorld()
	FlipBuffers()    
Until Quit = #True Or  KeyboardReleased(#PB_Key_Escape) Or MouseButton(3)

Code above works great using Ubuntu - if not - try updating:
(Edit: Not great after all. It does work but it froze on third trial run)
On windows it works without a hitch.

Code: Select all

sudo apt-get update
sudo apt-get install cmake pkg-config
sudo apt-get install mesa-utils libglu1-mesa-dev freeglut3-dev mesa-common-dev
sudo apt-get install libglew-dev libglfw3-dev libglm-dev
sudo apt-get install libao-dev libmpg123-dev
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.
User avatar
pf shadoko
Enthusiast
Enthusiast
Posts: 280
Joined: Thu Jul 09, 2015 9:07 am

Re: Demo - Morphing

Post by pf shadoko »

@DK_PETER
I corrected the code
User avatar
DK_PETER
Addict
Addict
Posts: 898
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Demo - Morphing

Post by DK_PETER »

Edit:
Ran it twice now without freezing...
It seems like it struggles during the morphing?

On windows it works fast and flawlessly, though.
Good example.
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.
User avatar
StarBootics
Addict
Addict
Posts: 984
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: Demo - Morphing

Post by StarBootics »

pf shadoko wrote: Tue Mar 28, 2023 7:36 pm this said, screencentered is useless since we are in full screen

(I was just talking about taking one of PB's 3D examples and testing it in windowedscreen with screencentered, to see how it behaves with 2 screens )
OK I took time to try one example (MeshManual.pb) Windowed 800X600 and #PB_Window_ScreenCentered flag. On my dual monitor, the window is not Screen centered at all on the Left Monitor. The right side of the Window coincide with the right side of the left monitor. On fullscreen mode, the screen open on the right monitor and the left monitor looses all signals and goes extinct. That is one of the reason why I use GLFW library instead of SDL for Screen management in my game project.

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
AZJIO
Addict
Addict
Posts: 1312
Joined: Sun May 14, 2017 1:48 am

Re: Demo - Morphing

Post by AZJIO »

Why if I compile it doesn't work?
User avatar
pf shadoko
Enthusiast
Enthusiast
Posts: 280
Joined: Thu Jul 09, 2015 9:07 am

Re: Demo - Morphing

Post by pf shadoko »

@StarBootics
SDL replacement under consideration

@AZJIO
to distribute a PB program using 3d you need engine3D.dll in the exe folder (...\PureBasic\Compilers\)
Post Reply