Jump to content

[SOLVED] Viewport background transparancy


photo

Recommended Posts

Is there a simple way to make the background colour of a WidgetSpriteViewport completely transparent so that the viewport behind can be seen behind the objects drawn on the above viewport?

Link to comment

There is no simple build-in function for doing this, but it can be done with some specialized viewport post-processing material. See attached sample which is a simplified version of texture-based viewport masking example. The sample scene renders the scenery both to the main window and an overlayed WidgetSpriteViewport, but nevertheless the background main scene remains visible in regions where otherwise the WidgetSprite black background would appear.

 

post-82-0-79896400-1317137850_thumb.jpg

 

For reasons of simplicity masking in the sample uses black background color. In a real-world scenario I think a check for a special color-code (not used for rendering you objects, e.g. magenta) would be more appropriate.

 

Please be advised that the sample only works for DX9. If you need this functionality for a different render system, than you have to adopt the fragment shaders accordingly to the provided DX9 version.

viewporttransparency.zip

Link to comment

In an attempt to get this working with a none black backround I have stumbled across a problem. (see image)

 

post-386-0-05193400-1317209221_thumb.jpg

 

The transpancy works for everywhere except the outline pixels of the mask color. Is there a way around this or have I coded it wrong? I'm thinking that maybe its sampling pixels from around the texcoord rather than one specific pixel so the blended color won't match the mask color. If so I'm not sure how to get around that.

 

struct FRAGMENT_IN {
float4 texcoord_0 : TEXCOORD0;
};
float4 mask_color;
/*
*/
float4 main(FRAGMENT_IN IN) : COLOR {

float3 color = tex2D(s_texture_0,IN.texcoord_0.xy).xyz;

float x = ceil(abs(color.x - mask_color.x));
float y = ceil(abs(color.y - mask_color.y));
float z = ceil(abs(color.z - mask_color.z));
return float4(color, 1) * saturate(x+y+z);
}

ViewportTransparancy.zip

Link to comment

That does indeed seem to be the problem as turning off anti-aliasing in the editor gave me a clean result. Can I ask of the origin of the "s_texture_0" sampler object in the DX9 code as it doesn't seem to be decalred like it is in the DX10/11 and openGL parts of the shader. If I was able to change the the sampler state filters to "point" I belive it may solve the problem, but I am having difficulties searching on how to do that. Is there a way of configuring the texture to do this in the .mat file?

Link to comment

If I was able to change the the sampler state filters to "point" I belive it may solve the problem, but I am having difficulties searching on how to do that. Is there a way of configuring the texture to do this in the .mat file?

 

I don't think that the artifacts are caused by texture filtering, so changing sampler filter mode will not solve the issue. Actually multi-sample edge anti-aliasing mixes primitive color with background color based on primitive per-pixel primitive coverage. Therefore the exact test for background color-key failes at edges. Hm, haven't thought of this in advance and unfortunately I don't see any easy solution for this problem...

Link to comment

Is there a simple way to make the background colour of a WidgetSpriteViewport completely transparent so that the viewport behind can be seen behind the objects drawn on the above viewport?

 

What kind of effect do you exactly want to achieve by drawing objects above main scene ? Maybe there is another technical approach than using WidgetSpriteViewport possible.

Link to comment

post-386-0-14748900-1317284508_thumb.jpg

 

I am trying to make a 3ds max style cube camera manipulator. The cube works perfectly, its just that being attached to the viewport it looks quite ugly with the background being drawn. I need it mounted on this viewport as it uses its own camera/player object and needs to stay in the top corner of the screen as it is essentially part of the GUI.

Link to comment

I did try using that originally and opted not to as it was inverting the y axis of my cube. I'm assuming this is not a bug, but it is confusing how its handling the view completely different manner and I'm not entirely sure why it does that and therefore I'm not sure how to switch it the correct way up.

Link to comment

post-386-0-90672300-1317292456_thumb.jpg

 

This image explains it better. As you can see from looking at the front face the y axis has been flipped and thus my mouse selection is showing a flipped result. I could write a quick shader to flip the texcoordinates but there should be a simpler approach.

 

EDIT: scratch that, WidgetSpriteNode has no setMaterials function so now I definately need a new approach

Link to comment
  • 10 months later...

I have to represent many 3D elements overlapped in 3d scene, I want them always visible and not affected by post-materials (visually in the same way as if they were widgets).

The idea is to use a WidgetSpriteViewport with transparency, the problem is transparency only works for WidgetSpriteNode but not for WidgetSpriteViewport. Reviewing the samples, in viewport_00.cpp, blend function is defined in the same way as in node_00.cpp but it doesn't the job.

 

Does Unigine support background transparency for WidgetSpriteViewport? How it should configured?

 

 

Thanks.

 

Edit: I will use WidgetSpriteNode with one node as root of all the other elements.

Link to comment

A cameras display data does not use the alpha channel as far as I know, your options are to use a post process effect as shown in the earlier part of this thread (although I could never figure out a way of removing the multisampling artifact) OR switch to WidgetSpriteNode by having your whole scene a child to an individual root node, thus achieving what you want (but this way you can manage what to render and what not to render by what is child to that root node). Unfortunately WidgetSpriteNode seems to be bugged at the moment and is waited on the next SDK update (see https://developer.unigine.com/forum/topic/1476-widgetspritenode-bug/ ), but I recommend you use WidgetSpriteNode.

Link to comment
×
×
  • Create New...