Average: Opacity still not working without code modification
by Matthew Hoesterey · in Torque X 2D · 05/25/2009 (7:26 am) · 8 replies
This problem has existed for some time and has not been fixed in the latest engine version:
Objects will not appear translucent without hand modification of the xml file or modifying the SimpleMaterial.cs file by setting:
bool _isColorBlended = true;
Modifying the xml file is not a valid option for non pro users as every time the builder saves it will rewrite the xml file deleting your hand edits.
This change needs to be updated in the next build or the builder needs some way to set a materials translucentcolorblend properties to true
Objects will not appear translucent without hand modification of the xml file or modifying the SimpleMaterial.cs file by setting:
bool _isColorBlended = true;
Modifying the xml file is not a valid option for non pro users as every time the builder saves it will rewrite the xml file deleting your hand edits.
This change needs to be updated in the next build or the builder needs some way to set a materials translucentcolorblend properties to true
#2
06/23/2009 (10:37 am)
I solved this with a component and the following codeprotected override bool _OnRegister(TorqueObject owner)
{
if (!base._OnRegister(owner) || !(Owner is T2DSceneObject))
return false;
SimpleMaterial m = null;
if (Owner is T2DStaticSprite)
{
m = (Owner as T2DStaticSprite).Material as SimpleMaterial;
}
else if (Owner is T2DAnimatedSprite)
{
m = (Owner as T2DAnimatedSprite).AnimationData.Material as SimpleMaterial;
}
else if (Owner is T2DScroller)
{
m = (Owner as T2DScroller).Material as SimpleMaterial;
}
if (m != null)
{
m.IsColorBlended = true;
}
return true;
}
#3
@Christian - Nice... guess that fix will work for those who can't modify the source.
Brian
Edit: @Matthew - Hmm... In regards to my statement about performance... I was just thinking any logic may actually have the opposite effect on the XBox as the Processor is underpowered but the GPU is higher performance... might need more research than I originally thought.
06/23/2009 (3:24 pm)
@Matthew - Is there any kind of performance hit for enabling that for all objects using the SimpleMaterial? I wonder if it is worth time to put some logic in there to see if the Visibility Level is less than 1 to determine if it should be enabled or not. I can investigate when I get home as my low performance machine is a laptop with an underpowered video card.@Christian - Nice... guess that fix will work for those who can't modify the source.
Brian
Edit: @Matthew - Hmm... In regards to my statement about performance... I was just thinking any logic may actually have the opposite effect on the XBox as the Processor is underpowered but the GPU is higher performance... might need more research than I originally thought.
#4
06/23/2009 (6:24 pm)
I haven't had a problem with performance. To be honest I'm hoping my fix is temporary until garage games puts in a real fix and thus haven't put any thought into the performance ramifications. I don't think you'll have any performance issues though. :)
#5
Will having ColorBlending always on amount to a significant performance hit? I suppose that would depend on the total number of pixels in question and the GPU doing the math.
But, it's always good to think in terms of efficiency. After all, two tried-and-true axioms of game programming:
1) There's always a bug left.
2) It's never fast enough.
06/23/2009 (9:39 pm)
Regarding performance, I see that in the SimpleEffect pixel shader, it has the line:if (useColor)
color *= input.color;So if IsColorBlended = true, then there is an extra multiply done for each pixel on each render. Unfortunately, IsColorBlended is set on a material, so as soon as you set it for one sprite or scroller, it will be on for all things that reference that material. That means for a given sprite, just because it's opacity gets set to full doesn't necessarily mean you can turn off ColorBlending, since that would affect every other reference to that material which might still need it on.Will having ColorBlending always on amount to a significant performance hit? I suppose that would depend on the total number of pixels in question and the GPU doing the math.
But, it's always good to think in terms of efficiency. After all, two tried-and-true axioms of game programming:
1) There's always a bug left.
2) It's never fast enough.
#6
06/23/2009 (9:48 pm)
And while I'm thinking about all this, I remember that you can set a particle effect to have the visibility of particles change over time. It might be enlightening to see how visibility is handled in rendering particles, though I don't have the time or inclination right now to slog through that code...
#7
@Scott - Yeah, luckily, the XBox 360's video card is actually pretty powerful and even has an advantage over PC video cards that were based on it with the eDRAM acting as kinda a hardware backbuffer. If you do end up checking up on particle visibility, let us know.
Brian
06/23/2009 (10:34 pm)
@Matthew - Yeah, you're right, even on my "low performance" machine, AKA, my laptop, I didn't see a noticeable difference in speed so you're probably right. Not really worth pursuing at this time.@Scott - Yeah, luckily, the XBox 360's video card is actually pretty powerful and even has an advantage over PC video cards that were based on it with the eDRAM acting as kinda a hardware backbuffer. If you do end up checking up on particle visibility, let us know.
Brian
#8
--the VisibilityLevel of the T2DSceneObject
--the alpha originally set on the vertex
--the opacity of the material itself.
When the VisibleLife value is set for a particle, that is set as the alpha of each vertex of that particle's triangles. So, that would necessitate having ColorBlending on for it to work. Here's how it is handled for emitters: in the Material property set
Just thought I'd show that as something to take into account on how blending should be handled.
The component shown above is a nice approach. Hopefully in the future, there will be either a checkbox for all SceneObjects to enable it, or have it turn on automatically if VisibilityLevel goes below 1.0.
06/24/2009 (9:57 am)
FYI, I've deduced that when IsColorBlended is true, the final alpha of a pixel comes from the combination of its color interpolated between vertices and the texture color for that texel; and the vertex alpha is the product of three parts:--the VisibilityLevel of the T2DSceneObject
--the alpha originally set on the vertex
--the opacity of the material itself.
When the VisibleLife value is set for a particle, that is set as the alpha of each vertex of that particle's triangles. So, that would necessitate having ColorBlending on for it to work. Here's how it is handled for emitters: in the Material property set
set
{
// Set Material.
_material = value;
// Valid Material?
if (_material != null)
{
if (_material is SimpleMaterial)
(_material as SimpleMaterial).IsColorBlended = true;
// Yes, so lookup material name.
_materialName = _material.NameMapping;
}
else
{
// No, so set name to empty.
_materialName = String.Empty;
}
}So any material used by an emitter gets blending turned on when it is assigned to that emitter.Just thought I'd show that as something to take into account on how blending should be handled.
The component shown above is a nice approach. Hopefully in the future, there will be either a checkbox for all SceneObjects to enable it, or have it turn on automatically if VisibilityLevel goes below 1.0.
Torque Owner Brian
www.garagegames.com/community/forums/viewthread/95203
Brian