Re: MP3D Engine Alpha 30
Posted: Thu Nov 17, 2011 8:28 pm
I miss some 2Dphysics examples. Right?
http://www.purebasic.com
https://www.purebasic.fr/english/
But how to use a simple alpha chanel (png with alpha chanel)?* what exactly do you mean? in normal case the black color is transparent and you can change the transparence color. If you need you can use the sprite blendmode, see example MP_SpriteBlendMode.pb
Code: Select all
MP_Graphics3D (640,480,0,3)
UsePNGImageDecoder()
Sprite = MP_CatchSprite(?MyData, ?EndOfMyData - ?MyData)
Sprite2 = MP_CatchSprite(?MyData, ?EndOfMyData - ?MyData)
ground = MP_CatchSprite(?MyGround, ?EndOfMyGround - ?MyGround)
part = MP_CatchSprite(?MyGround2, ?EndOfMyGround2 - ?MyGround2)
MP_SpriteSetZ(ground , 10)
MP_SpriteSetZ(Sprite , 50)
MP_SpriteSetCenterY(Sprite, 100)
MP_SpriteSetCenterY(Sprite2, 100)
;MP_TransparentSpriteColor(Sprite, RGB(255,0,255))
;MP_TransparentSpriteColor(Sprite2, RGB(255,0,255))
angle.f=0
While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow
MP_AmbientSetLight (RGB(0,50,128))
;{ drawsprite
MP_DrawTiledSprite(ground, 0,0)
;MP_DrawSprite(Sprite, 0, 25)
MP_DrawSprite(part, 150, 150,Abs(Cos(angle)*100))
MP_DrawSprite(Sprite, 300, 250, Abs(Cos(angle)*100))
MP_DrawSprite(Sprite2, x, y)
;}
;{ event keyboard and depth
angle+0.02
If MP_keyDown(#PB_Key_Right) : x+1 : EndIf
If MP_keyDown(#PB_Key_Left) : x-1 : EndIf
If MP_keyDown(#PB_Key_Up) : y-1 : EndIf
If MP_keyDown(#PB_Key_Down) : y+1 : EndIf
MP_SpriteSetZ(Sprite2 , y)
;}
;MP_drawtext(10,10,Str(y))
MP_RenderWorld()
MP_Flip ()
Wend
DataSection
;MyData : IncludeBinary #PB_Compiler_Home + "Examples\Sources\Data\Geebee2.bmp" : EndOfMyData :
MyData : IncludeBinary "sprite.png" : EndOfMyData :
MyGround : IncludeBinary #PB_Compiler_Home + "Examples\Sources\Data\Background.bmp" : EndofMyGround :
MyGround2 : IncludeBinary "particle1.png" : EndofMyGround2 :
EndDataSection
Code: Select all
MP_Graphics3D (640,480,0,3)
Sprite = MP_CatchSprite(?MyData, ?EndOfMyData - ?MyData)
ground = MP_CatchSprite(?MyGround, ?EndOfMyGround - ?MyGround)
MP_SpriteSetZ(ground , 10)
While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen
MP_AmbientSetLight (RGB(0,50,128))
; Draw our sprite
MP_DrawTiledSprite(ground, 0,0)
MP_DrawSprite(Sprite, 0, 25)
MP_DrawSprite(Sprite, x+100, 100, x)
x+1
If x = 300
x=0
EndIf
MP_RenderWorld() ; Erstelle die Welt
MP_Flip () ; Stelle Sie dar
Wend
DataSection
MyData: IncludeBinary "test.png": EndOfMyData:
MyGround : IncludeBinary #PB_Compiler_Home + "Examples\Sources\Data\Background.bmp" : EndofMyGround :
EndDataSection
ah ok. But how can we sort the sprite by Y, to do a Y-ordering ?if you change the order of
Sprite = MP_LoadSprite("donut.bmp")
Background = MP_LoadSprite("raupe40_60.bmp")
the background will be on the background and not in front. If you want you can use the MP_SpriteSetZ(Sprite , z) command to change this
Code: Select all
MP_SpriteSetZ(Sprite , y)
Thank you, here is a little example, based on MP_bloomEffect.pb- About the post processing (bloom, emboss) : can we have the bloom not on a GUi for example ?
* Please make me a little example. I will test it and find a solution
Code: Select all
shaderFX.s = PeekS(?Shader,?ShaderEnd-?Shader)
MP_Graphics3D (640,480,0,3)
SetWindowTitle(0, "Bloom & UI")
MP_VSync(0)
camera=MP_CreateCamera()
light=MP_CreateLight(1)
Mesh=MP_CreateTeapot()
MP_PositionEntity (Mesh,0,0,3)
;Texture = MP_CreateTexture(640,480)
;Texture2 = MP_CreateTexture(640,480)
Texture = MP_CreateBackBufferTexture()
Texture2 = MP_CreateBackBufferTexture()
MyShader = MP_CreateMyShader(shaderFX)
MyUi = MP_catchSprite(?Ui, ?UiEnd -?Ui)
ok.a =1
While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow
MP_TurnEntity (Mesh,0.1,0.1,0.1) ; dreh den Würfel
MP_RenderWorld() ; Erstelle die Welt
;{ Bloom
If ok = 1
MP_BackBufferToTexture (Texture)
MP_BackBufferToTexture (Texture2)
MP_SetTechniqueMyShader (MyShader,"DownScale")
MP_ShaderSetTexture (MyShader,"TextureA",Texture)
MP_UseBackbufferShader(Texture, MyShader)
MP_SetTechniqueMyShader (MyShader,"DownScale")
MP_ShaderSetTexture (MyShader,"TextureA",Texture2)
MP_UseBackbufferShader(Texture, MyShader)
MP_SetTechniqueMyShader (MyShader,"GaussianBlurH")
MP_ShaderSetTexture (MyShader,"TextureA",Texture)
MP_UseBackbufferShader(Texture, MyShader)
MP_SetTechniqueMyShader (MyShader,"GaussianBlurV")
MP_ShaderSetTexture (MyShader,"TextureA",Texture)
MP_UseBackbufferShader(Texture, MyShader)
MP_SetTechniqueMyShader (MyShader,"Bloom")
MP_ShaderSetTexture (MyShader,"TextureA",Texture)
MP_ShaderSetTexture (MyShader,"TextureB",Texture2)
MP_UseBackbufferShader(Texture, MyShader)
MP_TextureToBackBuffer (Texture)
EndIf
;} Bloom
If MP_keyhit(#PB_Key_Space) ; to Activate the bloom or not
ok = 1-ok
EndIf
; For example, I would like the text and the logo not "bloomed" ;)
MP_DrawSprite(MyUi,200,350)
MP_DrawText (1,1,"FPS = "+Str(MP_FPS()))
MP_Flip ()
Wend
DataSection
Shader: IncludeBinary "bloom.fx" : ShaderEnd:
Ui : IncludeBinary "../Epyxshader/power2.png" : UiEnd :
EndDataSection
Thanks, I will tried that soon* You can create a texture and color it. All Sprites have textures and if you change the texture you change the texture of the sprite too. use the command MP_SpriteFromTexture(Texture) for this.
of course, :- can we have an orthographic camera (to create a 3D isometric camera) ?
* i don't know, is the camera a normal one or not? Do you habe a example for this?
Code: Select all
CameraProjectionMode(0,#PB_Camera_Orthographic)
In fact, I'm looking for this function :- is there a way to project shadow with sprite, or to use normal mapping to illuminate the sprite ?
* You want to make shadow with sprite? or Iluminate it? I think this can be done with the MP_SpriteBlendMode
I think that MP3D could be use in a commercial game easily for 3D, and 2D, but with a few little features like :About the licence, can we use your engine in a commercial game ? Or is it a particular licence to use it ?
* the lib is for free, but please make a info that you use the MP3D in the intro
* i love donation but i am realist
Code: Select all
shaderFX.s = PeekS(?Shader,?ShaderEnd-?Shader)
MP_Graphics3D (640,480,0,3)
SetWindowTitle(0, "Bloom & UI")
MP_VSync(0)
camera=MP_CreateCamera()
light=MP_CreateLight(1)
Mesh=MP_CreateTeapot()
MP_PositionEntity (Mesh,0,0,3)
;Texture = MP_CreateTexture(640,480)
;Texture2 = MP_CreateTexture(640,480)
Texture = MP_CreateBackBufferTexture()
Texture2 = MP_CreateBackBufferTexture()
MyShader = MP_CreateMyShader(shaderFX)
MyUi = MP_catchSprite(?Ui, ?UiEnd -?Ui)
ok.a =1
While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow
MP_TurnEntity (Mesh,0.1,0.1,0.1) ; dreh den Würfel
MP_RenderWorld() ; Erstelle die Welt
;{ Bloom
If ok = 1
MP_BackBufferToTexture (Texture)
MP_BackBufferToTexture (Texture2)
MP_SetTechniqueMyShader (MyShader,"DownScale")
MP_ShaderSetTexture (MyShader,"TextureA",Texture)
MP_UseBackbufferShader(Texture, MyShader)
MP_SetTechniqueMyShader (MyShader,"DownScale")
MP_ShaderSetTexture (MyShader,"TextureA",Texture2)
MP_UseBackbufferShader(Texture, MyShader)
MP_SetTechniqueMyShader (MyShader,"GaussianBlurH")
MP_ShaderSetTexture (MyShader,"TextureA",Texture)
MP_UseBackbufferShader(Texture, MyShader)
MP_SetTechniqueMyShader (MyShader,"GaussianBlurV")
MP_ShaderSetTexture (MyShader,"TextureA",Texture)
MP_UseBackbufferShader(Texture, MyShader)
MP_SetTechniqueMyShader (MyShader,"Bloom")
MP_ShaderSetTexture (MyShader,"TextureA",Texture)
MP_ShaderSetTexture (MyShader,"TextureB",Texture2)
MP_UseBackbufferShader(Texture, MyShader)
MP_TextureToBackBuffer (Texture)
EndIf
;} Bloom
If MP_keyhit(#PB_Key_Space) ; to Activate the bloom or not
ok = 1-ok
EndIf
; For example, I would like the text and the logo not "bloomed" ;)
MP_DrawSprite(MyUi,200,350)
MP_DrawText (1,1,"FPS = "+Str(MP_FPS()))
MP_RenderSprite()
MP_RenderText()
MP_Flip ()
Wend
DataSection
Shader: IncludeBinary "bloom.fx" : ShaderEnd:
Ui : IncludeBinary "../Epyxshader/power2.png" : UiEnd :
EndDataSection
ok, thank youmpz wrote:i dont have forgotten your questions, but i need time to understand your problems and find a solution. In the mp3 3d engine i use dx9 sprites and they are different to pb sprites, because i think pb has Billboards (flat meshs) and not sprites. So the alpha transparency is different to use. The problem with the "trancparence bug" could be a order problem of the both sprites. if you change the order of sprite and background the picture is different. You can change the order also with a command MP_ListSwapElements(9, sprite , background). I will make some more tests with alpha transparency an sprite, perhaps i find a better solution or a new function for a future version of mp3d
ok. And can we "sort" the sprites, by their Y position (like with SortStructuredList()), and draw they by the Y ?MP_SpriteSetZ() is limited to 0-10 ?, yes use a trick and patch the z-order position with fixed values, i cant calculate for now but i work on it.
heu, what human and what animal ?I think you main question is to make light on the human position and make shadow on the animal position. I think you dont need alpha sprites for that, you can use the MP_SpriteBlendMode command for that. Can you send me the (anim) sprite of the human and the animal please (as pm) ? i will make a little demo with light and shadow without alpha sprites...
Thank you very much, it's great !post processing and gui = you need only MP_RenderSprite() for the sprite and MP_RenderText() for the fps
MP_RenderSprite()
MP_RenderText()
I totaly understand, I have a family too, and the family is more important than the codei will have a look on Camera_Orthographic on weekend, i have family and time is short
it's a really great newsP.S. Antialising 2x and 4x is integrated and works fine now, was a good idea...