Home › Forums › TimelineFX Module › DX 11 implementation
Tagged: DX 11
Thanks Peterigz, this information is just what I needed.
By changing the blend mode from
SrcBlend = D3D11_BLEND_ONE;
DestBlend = D3D11_BLEND_ONE;
BlendOp = D3D11_BLEND_OP_ADD;
SrcBlendAlpha = D3D11_BLEND_ONE;
DestBlendAlpha = D3D11_BLEND_ZERO;
BlendOpAlpha = D3D11_BLEND_OP_ADD;
to
SrcBlend = D3D11_BLEND_SRC_ALPHA;
DestBlend = D3D11_BLEND_ONE;
BlendOp = D3D11_BLEND_OP_ADD;
SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
DestBlendAlpha = D3D11_BLEND_ZERO;
BlendOpAlpha = D3D11_BLEND_OP_ADD;
I managed to get this in my test program :
Now that looks a lot like the image the TimeLineFX Editor is rendering.
Explosions also look the same as in TimeLineFX Editor :
I still need to work out the alpha blending as there is big difference in rendering.
TimeLineFX Editor :
My test program :
That looks better!
Regarding the smoke emitter, it looks like it’s not spawning enough particles, maybe you can check how many particle it’s spawning compared to the editor?
Hi Peterigz.
Sorry for a bit late replay, but after some digging I have found all the information needed to render particles correctly as they are rendered in TimeLineFX Editor.
Just to confirm, TimLineFX Editor uses TimeLineFX BlitzMax code library. Yes or no?
First, blend states from BlitzMax module you linked on the 1st page are not used. TimeLineFX has its own BlitzMax module where it configures blend states :
Case ALPHABLEND
glEnable GL_BLEND
glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA
glDisable GL_ALPHA_TEST
Case LIGHTBLEND
glEnable GL_BLEND
glBlendFunc GL_ONE, GL_ONE
glDisable GL_ALPHA_TEST
https://github.com/peterigz/rigz.mod/blob/master/glmax2dext.mod/glmax2dext.bmx
Second, color is not used “as is”, but is multiplied by alpha value :
Method SetColor(red:Int, green:Int, blue:Int)
currentred = red
currentgreen = green
currentblue = blue
color4ubext[0] = Min(Max(red, 0), 255) * currentalpha
color4ubext[1] = Min(Max(green, 0), 255) * currentalpha
color4ubext[2] = Min(Max(blue, 0), 255) * currentalpha
glColor4ubv color4ubext
End Method
https://github.com/peterigz/rigz.mod/blob/master/glmax2dext.mod/glmax2dext.bmx
Third, since color is multiplied by alpha, I assume texture color should also be multiplied by texture alpha :
float4 texture_pixel = shaderTexture.Sample (SampleType, input.texture_coordinates);
texture_pixel.x = texture_pixel.x * texture_pixel.w;
texture_pixel.y = texture_pixel.y * texture_pixel.w;
texture_pixel.z = texture_pixel.z * texture_pixel.w;
return texture_pixel * input.color;
Fourth, C++ library is ignoring IMPORT_OPTION attribute so images with GREYSCALE option are not loaded correctly. TimeLineFX loads such images by running them through this function first :
Function GreyScale:TPixmap(pixmap:TPixmap)
Local pixmapcopy:TPixmap = CopyPixmap(pixmap).Convert(PF_RGBA8888)
Local p:Byte Ptr
Local c:Int
For Local loc:Int = 0 Until pixmapcopy.capacity Step 4
p = pixmapcopy.pixels + loc
c = Min((p[0] *.3) + (p[1] *.59) + (p[2] *.11), p[3])
p[0] = 255
p[1] = p[0]
p[2] = p[0]
p[3] = c
Next
Return pixmapcopy
End Function
https://github.com/peterigz/rigz.mod/blob/master/singlesurface.mod/singlesurface.bmx
With all that information I can now render correctly particles with alpha blending. š
Great glad you got it working. Yes come to think it it that extra code I had might have been to do the pre-multiply alpha I had set up but it’s been quite a few years since I looked at the code!
You must be logged in to reply to this topic.