Results 1 to 2 of 2

Thread: deferred rendering and normal mapping

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2012
    Posts
    26

    deferred rendering and normal mapping

    During a gbuffer stage I save in textures a depth, normals, diffuse and specular colors, shininnes factors but also
    normals from a normal maps (tangent space) and tangent vectors (I can calculate binormal vectors using normals from a normal maps and tangent vectors ).
    Only some objects are shaded using normal maps. For objects which don't use normal maps I save in texture vec3(0,0,0) as a normal from a normal map.
    Then in a framgent shader I do something like this :
    Code :
    if(a normal vector from a normal map is equal vec3(0,0,0))
    {
    	fragColor = standard_shading_function( some parameters );
    }
    else
    {
    	fragColor = nm_shading_function( some parameters );
    }

    'If' statement in a shader program can be expensive but I don't have any other ideas how to solve above problem.
    Do you know any better solution ?

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    One way to avoid IF tests is is to use some function that has a binary result like this
    Code :
     float ln = length(normal); // will be 0 or 1
     fragColor = standard_shading_function(..) * ln + nm_shading_function(..)* (1-ln);

    But this is not necessarily faster code.

    AFAIK IF tests are bad if a block of compute units (I think they are small like 4x4) don't all take the same path. In your case this will only be on the boundary of objects so practically this may not be so bad.

Similar Threads

  1. Replies: 5
    Last Post: 05-25-2018, 06:55 PM
  2. opengl bump mapping (normal mapping) problem with VBO and GLSL
    By emrekaya413 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-29-2018, 03:52 AM
  3. Shadow mapping & deferred rendering problem
    By Giclaa in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 01-02-2018, 11:07 AM
  4. Deferred Rendering + Normal Mapping + SSAO
    By radu1986 in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 12-16-2015, 06:36 AM
  5. Deferred Shadow Mapping (another one)
    By manum3d in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 07-02-2013, 03:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean