Some More Shader Questions

This is a discussion on Some More Shader Questions within the C++ Programming forums, part of the General Programming Boards category; The boards seem a little dead today? Geez I feel bad being the two most recent posts. However, a man ...

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    44

    Some More Shader Questions

    The boards seem a little dead today? Geez I feel bad being the two most recent posts. However, a man has needs

    I've gotten significantly further in my program, but I need help with two things: toggling between shaders and testing to see if I've been calculating my normals correctly in a triangle mesh.

    In regards to the normals, I just want to know a good method for testing. I know I can subtract the value of the normal from the color so that all normals that are approximately unit length on a single axis (e.g. (1,0,0) or (0,1,0)) will be shaded red, green, or blue, depending on what value remains, but if it's done correctly, should I be seeing distinct shades of RGB, or should I be seeing the in-between as well, such as purple or orange?

    As for toggling between shaders, I need a pointer in the right direction. By toggling between shaders I mean between parts of the vertex and fragment shaders. I realize both run each time I run the program, but I would like to have it so that I could have PARTS of the code run from each depending on a certain mode input. I've tried setting up a handler to take input keyboard keys as int values and pass them to an appropriate variable in both the vertex and fragment shaders, but if I try to use a flag with that parameter and put the code inside if statements, a rendering results in a uniformly colored image.

    I'm not quite sure where to go from here. I've checked to see if the values are being passed incorrectly or if there aren't proper handles, but that all checks out. I'd post code but there's quite a bit.

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    1,198
    Assuming your shader code looks something along these lines (very simplified):
    Code:
    // Vertex shader
    in vec3 normal;
    in vec3 position;
    
    out vec3 Color;
    
    void main()
    {
        Color = normal;
        gl_Position = vec4( position, 1.0 );
    }
    // Fragment shader
    in vec3 Color;
    
    out vec4 outColor;
    
    void main()
    {
        outColor = vec4( Color, 1.0 );
    }
    You will see the colors mix between the vertices.

    Can't you just write debug shaders and "production" shaders and then depending on if you are in debug mode or in production mode you just choose which shader program to use, that is you perform everything up to linking the shader program but the selection of program is done at render time? Although it sounds very weird that you are not able to just use an integer uniform to select which mode to use.

  3. #3
    Registered User
    Join Date
    Feb 2011
    Posts
    44
    Quote Originally Posted by Shakti View Post
    Assuming your shader code looks something along these lines (very simplified):
    Yes, that's the gist of it, though my actual color takes into account calculations for both Phong and Gouraud shading in the fragment and vertex shaders, respectively. The calculation part is what I want to switch.

    Quote Originally Posted by Shakti View Post
    You will see the colors mix between the vertices.
    Am I understanding this correctly in assuming this means that if I can see the purples and the yellows and oranges I'm doing it right?

    Quote Originally Posted by Shakti View Post
    Can't you just write debug shaders and "production" shaders and then depending on if you are in debug mode or in production mode you just choose which shader program to use, that is you perform everything up to linking the shader program but the selection of program is done at render time? Although it sounds very weird that you are not able to just use an integer uniform to select which mode to use.
    I could write the debug and protection but I have no idea what they are: I'm fairly new to lighting and writing my own shaders. I'm going to mess around with sending in the uniform int through a handler some more, maybe there's something I missed while coding for 11 hours straight

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Rayleigh scattering shader
    By psychopath in forum Game Programming
    Replies: 18
    Last Post: 07-07-2009, 04:01 PM
  2. Cel Shader
    By taelmx in forum Game Programming
    Replies: 4
    Last Post: 11-15-2006, 06:36 AM
  3. Sky scattering shader
    By VirtualAce in forum Game Programming
    Replies: 9
    Last Post: 08-24-2006, 12:51 PM
  4. Shader hell
    By VirtualAce in forum Game Programming
    Replies: 4
    Last Post: 08-18-2006, 09:21 PM
  5. BSP loader with shader support
    By glUser3f in forum Game Programming
    Replies: 18
    Last Post: 02-17-2005, 07:50 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21