I've been attempting to DIY a quad-based particle system while sprites seem not to be quite right (per separate issue), and it's all working fine, except that alpha appears not to work properly.
I've modelled Model.CreateRect below on Model.CreateBox so as to mirror what happens there, and I can see that Mesh.CreateRect does exactly the same internally as Mesh.CreateBox (bunch of vertices and indices, update tangents, done), with the Model version adding material and parent and adding to the scene.
However, as you can see here when moving mouse up/down, while the box alpha works correctly, anything other than 1.0 for the rect alpha appears solid black! Placing mouse at top of canvas goes white at 1.0.
Wondering if there's a particular number of vertices where alpha actually kicks in or something weird like that?
End result is I'm no better off than I was before! But does seem to have turned up a bug anyway... I've not found any other difference between Model.CreateBox and my Model.CreateRect that would affect it.
Namespace myapp3d
#Import "<std>"
#Import "<mojo>"
#Import "<mojo3d>"
Using std..
Using mojo..
Using mojo3d..
Class Model Extension
Function CreateRect:Model( size:Float,material:Material,parent:Entity=Null )
size = size * 0.5
Local mesh:=mojo3d.Mesh.CreateRect(New Rectf (-size, -size, size, size))
Local model:=New Model( mesh,material,parent )
Return model
End
End
Class MyWindow Extends Window
Field _scene:Scene
Field _camera:Camera
Field _light:Light
Field _ground:Model
Field alpha:Float = 1.0
Field rect:Model
Field cube:Model
Method New( title:String="Rect alpha",width:Int=640,height:Int=480,flags:WindowFlags=WindowFlags.Resizable )
Super.New( title,width,height,flags )
End
Method OnCreateWindow() Override
'create (current) scene
_scene=New Scene
_scene.ClearColor = New Color( 0.2, 0.6, 1.0 )
_scene.AmbientLight = _scene.ClearColor * 0.25
_scene.FogColor = _scene.ClearColor
_scene.FogNear = 1.0
_scene.FogFar = 200.0
'create camera
_camera=New Camera( Self )
_camera.AddComponent<FlyBehaviour>()
_camera.Move( 0,2.5,0 )
'create light
_light=New Light
_light.CastsShadow=True
_light.Rotate( 45, 45, 0 )
'create ground
Local groundBox:=New Boxf( -100,-1,-100,100,0,100 )
Local groundMaterial:=New PbrMaterial( Color.Lime )
_ground=Model.CreateBox( groundBox,1,1,1,groundMaterial )
_ground.CastsShadow=False
' D E M O . . .
Local size:Float = 1.0
Local mat:PbrMaterial = New PbrMaterial (Color.White)
' Local mesh:Mesh = Mesh.CreateRect (New Rectf (-size, -size, size, size))
' Local model:Model = New Model (mesh, mat)
rect = Model.CreateRect (size,mat)
rect.CastsShadow = False
rect.Move (1, 2.5, 2)
rect.Alpha = 1.0 ' < 1.0 = BLACK!
rect.Visible = True
cube = Model.CreateBox (New Boxf (-4, -4, -4, 4, 4, 4), 1, 1, 1, New PbrMaterial (Color.Red))
cube.Move (-4, 2.5, 10.0)
End
Method OnRender( canvas:Canvas ) Override
If Keyboard.KeyHit (Key.Escape) Then App.Terminate ()
'Print Mouse.WheelY
alpha = 1.0 - Float (Mouse.Y) / canvas.Viewport.Height
rect.Alpha = alpha ' < 1.0 = BLACK!
cube.Alpha = alpha
RequestRender()
_scene.Update()
_camera.Render( canvas )
canvas.DrawText ("Alpha (mouse up/down): " + alpha, 0, 0)
End
End
Function Main()
New AppInstance
New MyWindow
App.Run()
End
Original Author: DruggedBunny
I've been attempting to DIY a quad-based particle system while sprites seem not to be quite right (per separate issue), and it's all working fine, except that alpha appears not to work properly.
I've modelled Model.CreateRect below on Model.CreateBox so as to mirror what happens there, and I can see that Mesh.CreateRect does exactly the same internally as Mesh.CreateBox (bunch of vertices and indices, update tangents, done), with the Model version adding material and parent and adding to the scene.
However, as you can see here when moving mouse up/down, while the box alpha works correctly, anything other than 1.0 for the rect alpha appears solid black! Placing mouse at top of canvas goes white at 1.0.
Wondering if there's a particular number of vertices where alpha actually kicks in or something weird like that?
End result is I'm no better off than I was before! But does seem to have turned up a bug anyway... I've not found any other difference between Model.CreateBox and my Model.CreateRect that would affect it.