nathank Posted April 2, 2011 Share Posted April 2, 2011 Is it possible to mask a viewport, to make it round for instance? I understand how to use blending to apply this kind effect to a sprite, but in this case the mask I want to use is a different texture from the one being displayed by the viewport sprite, and I'm not sure how to apply that separate mask texture. Link to comment
ulf.schroeter Posted April 2, 2011 Share Posted April 2, 2011 Is it possible to mask a viewport, to make it round for instance? I understand how to use blending to apply this kind effect to a sprite, but in this case the mask I want to use is a different texture from the one being displayed by the viewport sprite, and I'm not sure how to apply that separate mask texture. I think at the moment there is no easy way to achive this masking. A possible solution might be to add a specialized mask post-processor material to the WidgetSpriteViewport which modulates viewport texture alpha channel with mask texture (e.g. circle) value. By setting up proper blending for WidgetSpriteViewport this should make it possible to softly blend non-rectangular regions of the viewport texture into the framebuffer. See this post for general technical approach. Unfortunately UNIGINE hasn't included this idea into core engine yet. UPDATE: see post #4 for sample implementation Link to comment
ulf.schroeter Posted April 2, 2011 Share Posted April 2, 2011 Is it possible to mask a viewport, to make it round for instance? I understand how to use blending to apply this kind effect to a sprite, but in this case the mask I want to use is a different texture from the one being displayed by the viewport sprite, and I'm not sure how to apply that separate mask texture. Another approach might be 1. WidgetSpriteViewport::renderImage() to render the viewport into a provided Image e.g. viewportImage 2. Then viewportImage.blend( maskImage,...) to alpha-blend viewport image with mask image 3. Finally assign viewport image to a WidgetSprite object and use WidgetSprite layer blending functions for blending with framebuffer Link to comment
ulf.schroeter Posted April 2, 2011 Share Posted April 2, 2011 Is it possible to mask a viewport, to make it round for instance? Proof-of-concept animated viewport mask post shader. Unzip viewportmask.zip to UNIGINE directory and start it via data/viewportmask/viewportmask_d3d9.bat. @UNIGINE: why not include this functionallity together with this post into UNIGINE core. Its all based on some small modfications of post material structure. This would provide much enhanced post-processor flexibility at nearly no costs. viewportmask.zip Link to comment
nathank Posted April 4, 2011 Author Share Posted April 4, 2011 Proof-of-concept animated viewport mask post shader. Unzip viewportmask.zip to UNIGINE directory and start it via data/viewportmask/viewportmask_d3d9.bat. Fantastic! I started to go down this exact path before I posted, but my experience with shaders is pretty limited and I gave up thinking there must be an easier way. It's nice to know that I was on the right track. Kudos to u my friend :) Just one problem I have. Your shader doesn't seem to work in DX10/11 (viewport doesn't show up at all) or OpenGL (viewport just appears as one solid color) and for some reason my terrain isn't working when I switch back to DX9. So atm I seem to have all the pieces but I can't get them all to work at the same time. Link to comment
ulf.schroeter Posted April 4, 2011 Share Posted April 4, 2011 Just one problem I have. Your shader doesn't seem to work in DX10/11 (viewport doesn't show up at all) or OpenGL (viewport just appears as one solid color) Right, I have just implemented DX9 shader code. Have a look into fragment_viewport_mask.shader and adopt DX9 to OpenGL/DX10/11. Quite simple and maybe nice training :-) I will upload this change this evening, so other user don't have the same problem. Link to comment
ulf.schroeter Posted April 4, 2011 Share Posted April 4, 2011 I will upload this change this evening, so other user don't have the same problem. Updated above ZIP-File with new fragment shader. Tested with DX9/OpenGL, but not under DX10/11/Playstation as I do not have compatible HW. Link to comment
ulf.schroeter Posted April 4, 2011 Share Posted April 4, 2011 I gave up thinking there must be an easier way. and you were right: you found another dummy doing the work :) Link to comment
nathank Posted April 5, 2011 Author Share Posted April 5, 2011 Updated above ZIP-File with new fragment shader. Tested with DX9/OpenGL, but not under DX10/11/Playstation as I do not have compatible HW. Working great in DX10/11 now. Still not working in OpenGL for me but I don't really need that for now anyway. Thanx again for the example. I find it hard to get through all the noise in most examples (including the other Unigine shaders) and work out what's really relevant, but this one is simple enough that I'm starting to get my head around it. I'll be keeping an eye out for other places to use it so I can try writing my own. Link to comment
ulf.schroeter Posted September 27, 2011 Share Posted September 27, 2011 Update viewport masking sample to new UNIGINE shader directory structure viewwportmask.zip Link to comment
Recommended Posts