Sign in to follow this  

[SlimDX] Particle Effect Alpha FadeOut

Recommended Posts

mdx    182
I'm drawing a pointlist as sprite (renderstate Setup) with a Texture. In the VB6 Tutorial, the Texture fades out by changing the Colors Alpha. I'm doing the same thing, but changing Alpha takes no Effect. I'm using then System.color, not SlimDX.Color4. How can i easy change the Transparenz, to fade out the particle ? Thanx for Help !

Share this post

Link to post
Share on other sites
mdx    182
First i create the VertexStructure

#Region "Custom Vertexformat Structure"
Private Structure PositionColored
Public position As Vector3
Public color As Color

Public Sub New(ByVal pos As Vector3, ByVal col As Color)
Me.position = New Vector3(pos.X, pos.Y, pos.Z)
Me.color = col
End Sub
Public Shared ReadOnly Property SizeBytes() As Integer
Return System.Runtime.InteropServices.Marshal.SizeOf(GetType(PositionColored))
End Get
End Property
Public Shared ReadOnly Property Format() As Direct3D9.VertexFormat
Return (VertexFormat.Position Or VertexFormat.Diffuse)
End Get
End Property
End Structure
#End Region

Then i create a particle list

Private _vertex() As PositionColored
Private _listOfParticle As New List(Of Particle)

Private Sub createListOfParticle()
For i As Integer = 0 To _particleCount
_listOfParticle.Add(New Particle)
End Sub

Private Sub update()
For Each p As Particle In _listOfParticle
If p.Lifetime <= 0 Then
End If
Dim i As Integer
For Each p As Particle In _listOfParticle
_vertex(i).position = p.Position
_vertex(i).color = p.Color
i += 1
End Sub

if liftime <= 0 the particle is dead
else update particle position and color

The next for each:
get new positions and
get new colors for all particle

Thats the Updatepart from the Particle Class

Public Sub update()
'#update position
_position.X += CSng(_speed.X * dxGametime.GameRendertime(400))
_position.Y += CSng(_speed.Y * dxGametime.GameRendertime(400))
_position.Z += CSng(_speed.Z * dxGametime.GameRendertime(400))
'#update speed
'_speed += _acceleration
'#update lifetime
_lifetime -= CSng(_decreasLifetime * dxGametime.GameRendertime(400))
If _lifetime < 0 Then _lifetime = 0
'#color Update
red = _color.R
green = _color.G
blue = _color.B
alpha = CInt(_lifetime * 255)
'#new Alpha Color
_color = Color.FromArgb(alpha, red, green, blue)
End Sub

Here is the render part

dxTextures.AlphaBlending3 = True '#for AlphaBlending

dxDevice.SetRenderState(RenderState.PointSpriteEnable, True)
dxDevice.SetRenderState(RenderState.PointScaleEnable, True)
dxDevice.SetRenderState(RenderState.PointSize, 0.04F)
dxDevice.SetTexture(0, _tex)
dxDevice.VertexFormat = PositionColored.Format
dxDevice.DrawUserPrimitives(PrimitiveType.PointList, _vertex.Length - 1, _vertex)

That's it. Lights are turned off.
I've tried this
dxDevice.SetTextureStageState(0, TextureStage.AlphaArg1, TextureArgument.Diffuse)

with no change...

I've changed all System.color to SlimDX.Color4. With same Code only the red channel works.

Thanx for Help

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this