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 [youtube.com] 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 [sidefx.com]
http://www.sidefx.com/docs/hdk15.0/_h_d_k__viewport_g_l3.html [sidefx.com]
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.
Accessing lights for a GLSL viewport shader
2603 3 0-
- Robert Shelline
- Member
- 5 posts
- Joined: Sept. 2014
- Offline
-
- malexander
- Staff
- 5285 posts
- Joined: July 2005
- Offline
It's
layout(std140) uniform glH_Light0
{
vec3 pos;
vec3 dir;
vec3 atten;
vec3 amb;
vec3 spec;
vec3 diff;
float coscutoff;
float cosfalloff;
bool point;
} lightSource0;
for up to 10 lights (0-9). There is also ‘uniform int glH_LightMask’ which is a bitfield indicating which lights are active - `(glH_LightMask & (1<<LIGHTNUM))`.
layout(std140) uniform glH_Light0
{
vec3 pos;
vec3 dir;
vec3 atten;
vec3 amb;
vec3 spec;
vec3 diff;
float coscutoff;
float cosfalloff;
bool point;
} lightSource0;
for up to 10 lights (0-9). There is also ‘uniform int glH_LightMask’ which is a bitfield indicating which lights are active - `(glH_LightMask & (1<<LIGHTNUM))`.
-
- Robert Shelline
- Member
- 5 posts
- Joined: Sept. 2014
- Offline
-
- malexander
- Staff
- 5285 posts
- Joined: July 2005
- Offline
-
- Quick Links

