World Wind Forums

Go Back   World Wind Forums > WorldWind JAVA forums > Development Help

Development Help Help for building applications or diagnosing problems with WWJ

Reply
 
Thread Tools Display Modes
Old 05-09-2012, 08:40 AM   #1
BuM
Member
 
Join Date: Jan 2012
Posts: 94
BuM is on a distinguished road
Question Layer opacity via shader

Hi there,

we want to bring the field AbstractLayer.opacity to good use by having its value multiplied to each of its renderables. This way we would have easy control over the visibility of a whole layer, no matter the kinds of its renderables.

We thought an easy approach would be a shader assigned to the layer which just multiplies the alpha value to each fragment created by the layer. As we are new to shaders, our solution is rather clumsy:

Code:
uniform sampler2D testTexture;

// alpha value to use
uniform float alpha;

// to decide where the color of the fragment comes from
uniform int textured = 0;

void main(void) {
 if (gl_TexCoord[0].s < 0.0 || gl_TexCoord[0].s > 1.0) discard;
 if (gl_TexCoord[0].t < 0.0 || gl_TexCoord[0].t > 1.0) discard;

 if (textured > 0) {
  gl_FragColor = texture2D(testTexture, gl_TexCoord[0].xy);
  gl_FragColor = gl_FragColor * alpha;
 } else {
  gl_FragColor = gl_Color * alpha;
 }
}
As there seem to be two sources for the color (textured and gl_Color, depending on the renderable) and we do not know how to automatically tell which one to take, we have this extra field "textured" which we have to set manually for each (overridden) renderable class.

1. Is there a way to automatically identify the correct source of the fragment color?
2. Is there even an easier way to accomplish our goal?

Thanks a lot!
BuM is offline   Reply With Quote
Old 06-18-2012, 11:07 AM   #2
BuM
Member
 
Join Date: Jan 2012
Posts: 94
BuM is on a distinguished road
Unhappy different Renderable types

A problem with this approach is that it is not enough to activate the shader at the start of the AbstractLayer.doRender() method because not all renderables are rendered at this phase:
1. OrderedRenderables are not rendered, but added to DrawContextImpl.orderedRenderables to be drawn later.
2. Same with surface objects which are drawn at another phase.

So for both types of renderables the shader (or just the opacity value) has to be set inside the renderable class, which takes away much of the convenience of the shader solution.

Another idea of ours is to iterate through each of the layer's renderables at the preRender phase of the layer to set their opacity value. Unfortunately, not all renderables do have such an opacity value (like UserFacingIcon, and possibly others).

So now we have different solutions for different types of renderables, which is rather unsatisfying and not easily adaptable to new situations.
Any ideas for improvement are welcome!
BuM is offline   Reply With Quote
Reply

Tags
alpha, color, layer, opacity, shader


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Shader Issue duindain Development Help 4 11-14-2011 05:13 PM
GetCurrentPosition question... ruso Development Help 19 08-24-2011 04:07 PM
Problems displaying a layer from cache jpralle Development Help 0 11-02-2010 01:27 PM
WW1.3.2-Plugin: Layer Edit canosso Add-ons & Scripts 21 02-27-2010 04:37 AM
GPX to Track and Layer, Waypoints to Layer canosso Add-ons & Scripts 14 03-05-2005 06:37 PM


All times are GMT +1. The time now is 11:54 PM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.