Jump to content

Accessing lights for a GLSL viewport shader


Nabrin

Recommended Posts

I'm attempting to write a custom GLSL shader for the viewport to aid in the development of a game that will have a toon shaded style (following some ideas from this Guilty Gear Xrd talk from GDC). I want to end up with the same shader applied in the viewport as the shader that will be used in the game to make the modeling and texturing pipeline easier.

I'm new to GLSL and learning by experimenting as I go. I've been able to hardcode a simple directional light in the fragment shader that is relative to the viewport by using a vec3:

    if (dot(nN, lightDirection) < 0) {
        lspec = vec3(1.0);
    } else {
        lspec = vec3(0.0);
    }

(I'm using lspec to test the formula at this point, because it's on the top layer.)

The next step is to pull the lightDirection from a Houdini light instead of hard coding it. This is where I'm running into some problems.

 

There are two sources of documentation I've found:

http://www.sidefx.com/docs/houdini15.0/shade/opengl

http://www.sidefx.com/docs/hdk15.0/_h_d_k__viewport_g_l3.html

The first says to use light uniform blocks like this:

layout(std140) uniform light0
{
    vec3        pos;
    vec3        dir;
    vec3        atten;
    vec3        amb;
    vec3        spec;
    vec3        diff;
    float       coscutoff;
    bool        point;
} lightSource0;

When I use this, and try to get lightSource0.pos, the model goes black and has no lighting applied. I'd like to query this variable to debug it, but I'm not sure how to do that within GLSL itself.

The second source of documentation uses a slightly different variable:

layout(std140) uniform glH_Light0
{
    vec3        pos;            // light position, world space
    vec3        dir;            // light direction, world space
    vec3        atten;          // attenuation - .x: d^2, .y: d, .z: const
    vec3        amb;            // ambient color component
    vec3        spec;           // specular component
    vec3        diff;           // diffuse component
    float       coscutoff;      // cosine(cutoff) to compare to dot(dir,P-pos)
    bool        point;          // point light (true), spot light (false)
} lightSource0;

When I use this code, the shader fails to compile and says "ERROR: Multiple definitions of interface block 'glH_Light0' differ in name/type/order/qualification of members". Because of this error, I think that the glH_Light0 name is the correct one to use, but I'm not implementing this correctly. I've looked for more documentation on this, but have come up dry. Does anyone know how to properly reference lights in GLSL? I appreciate any help or insights.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...