Results 1 to 3 of 3

Thread: Problem with uniform boolean var to turn lighting on/off

  1. #1
    Junior Member
    Join Date
    Dec 2009
    Posts
    2

    Problem with uniform boolean var to turn lighting on/off

    Hi,

    I guess this goes in the beginner section rather than the advanced section.

    I'm developing a 3D viewer of OpenStreetMap http://www.openstreetmap.org data which also shows terrain generated from NASA SRTM height data. The current version (very much pre-pre-alpha grade...) is available at http://www.free-map.org.uk/3d/.

    I'd like to turn lighting on for the terrain, but off for the OpenStreetMap data (roads, footpaths, and other vector map data) because I don't need lighting effects on the OSM data. I attempted to do this by declaring a boolean uniform variable and then using code in the vertex shader such as:

    if (uDoCalculation==true)
    {
    // calculate lighting
    }
    else
    {
    vLightWeighting = vec3(1.0, 1.0, 1.0);
    }

    I render the SRTM data first, then the OpenStreetMap data. My plan was to set uDoCalculation to true when rendering the former, and to false when I render the latter. However this does not work (I get a blank screen), and even if I switch off the OpenStreetMap layer and just render the terrain (i.e uDoCalculation is always true) I just get a blank screen, with neither terrain nor OpenStreetMap data rendering.

    However, if I change the if statement in the above code to if(true) it works, and if I change it to if(uDoCalculation==false) I get (as expected) a scene with no lighting effects.

    I have checked that the vertex variable location for uDoCalculation is >=0 (rather than -1) and it is, so I'm really stumped as to why this is not working. It's almost as if the shader variables are being corrupted in some way. Does anyone have any suggestions?

    Thanks,
    Nick

  2. #2
    Member Coolcat's Avatar
    Join Date
    Oct 2009
    Location
    NRW, Germany
    Posts
    75

    Re: Problem with uniform boolean var to turn lighting on/off

    Hi,
    first of all: It is not a wise idea to program an universal shader. Don't try to rebuild the fixed function! Your graphics hardware needs to do this decision for every vertex! If you do that in the fragment shader, this is done for EVERY fragment/pixel. It's better to switch the shader program instead.

    However, you implementation should work...
    Maybe you set the uniform wrong?

    Code :
    // true
    gl.uniform1i(gl.getUniformLocation("uDoCalculation"), 1);
     
    // false
    gl.uniform1i(gl.getUniformLocation("uDoCalculation"), 0);

  3. #3
    Junior Member
    Join Date
    Dec 2009
    Posts
    2

    Re: Problem with uniform boolean var to turn lighting on/off

    Hi, thanks for that. Am now using a separate shader for the layer which doesn't need lighting so works fine thanks

    Nick

Similar Threads

  1. iOS - 2d image turn into a 3d
    By mathewi9 in forum OpenGL ES general technical discussions
    Replies: 0
    Last Post: 03-25-2013, 12:55 AM
  2. A problem about the non-uniform scaling.
    By akaiwall in forum OpenVG and VGU
    Replies: 3
    Last Post: 04-15-2009, 08:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •