![]() |
|
|||||||
| Development Help Help for building applications or diagnosing problems with WWJ |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Jan 2012
Posts: 94
![]() |
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;
}
}
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! |
|
|
|
|
|
#2 |
|
Member
Join Date: Jan 2012
Posts: 94
![]() |
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! |
|
|
|
![]() |
| Tags |
| alpha, color, layer, opacity, shader |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |