carl.sutton Posted September 27, 2011 Share Posted September 27, 2011 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
ulf.schroeter Posted September 27, 2011 Share Posted September 27, 2011 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. 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
carl.sutton Posted September 27, 2011 Author Share Posted September 27, 2011 Thanks for the response, I thought it may have needed to involve such a technique. I shall give it a try Link to comment
ulf.schroeter Posted September 27, 2011 Share Posted September 27, 2011 Extract the zip file into your UNIGINE root directory and than go to data\viewporttransparency folder and start the provided batch file. Link to comment
carl.sutton Posted September 28, 2011 Author Share Posted September 28, 2011 In an attempt to get this working with a none black backround I have stumbled across a problem. (see image) 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
ulf.schroeter Posted September 28, 2011 Share Posted September 28, 2011 Might be related to multi-sampling. On my low-end notbook without multisampling your DX9 code does not show these artifacts Link to comment
carl.sutton Posted September 28, 2011 Author Share Posted September 28, 2011 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
ulf.schroeter Posted September 28, 2011 Share Posted September 28, 2011 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
ulf.schroeter Posted September 28, 2011 Share Posted September 28, 2011 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
carl.sutton Posted September 29, 2011 Author Share Posted September 29, 2011 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
frustum Posted September 29, 2011 Share Posted September 29, 2011 Try WidgetSpriteNode class with (GUI_BLEND_SRC_ALPHA,GUI_BLEND_ONE_MINUS_SRC_ALPHA) blend function. The sample will be available in the next SDK update. 1 Link to comment
carl.sutton Posted September 29, 2011 Author Share Posted September 29, 2011 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
carl.sutton Posted September 29, 2011 Author Share Posted September 29, 2011 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
frustum Posted September 29, 2011 Share Posted September 29, 2011 You can flip image via changing the texture coordinates of sprite layer. Upcoming SDK will flip image automatically. Link to comment
carl.sutton Posted September 29, 2011 Author Share Posted September 29, 2011 Thank you, all help has been much appreciated Link to comment
ivan.cuevas Posted August 28, 2012 Share Posted August 28, 2012 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
carl.sutton Posted August 28, 2012 Author Share Posted August 28, 2012 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
Recommended Posts