Lit instruction

There is the LIT instruction in low level shaders, I think it was in ARB_fragment_program or NV_fragment_program. How to make use of it in GLSL? Also, is it available in Cg?

It’s available in Cg, don’t know how to access it in GLSL.

Just under the OpenGL logo, Documentation : OpenGL Shading Language, on that page download the specifications & the quick reference guide.

No GLSL doesn’t have that function.

I’m pretty sure V-man read the GLSL specification thoroughly. He was asking for a way to access the functionality that is present on the hardware in GLSL. e.g. It’s possible to use Cg data types in GLSL with a preprocessor command. Or you can load a Cg shader in GLSL on nvidia cards through the GL_EXT_Cg_shader extension.


There is no reason to assume that this functionality was present in hardware at the first place. IMO, they just added it for programmers conveniance.

Of course there’s no way to be a 100% sure that it’s implemented in hardware (for me anyways). But if not, they should be more careful when using the word accelerate :slight_smile: LIT: Light Coefficients

The LIT instruction accelerates per-fragment lighting by computing 
lighting coefficients for ambient, diffuse, and specular light 

Here’s another part from the spec:

The exponentiation approximation function may be defined in terms of
the base 2 exponentiation and logarithm approximation operations in
the EX2 and LG2 instructions, where

  ApproxPower(a,b) = ApproxExp2(b * ApproxLog2(a)).
In particular, the approximation may not be any more accurate than 
the underlying EX2 and LG2 operations.
Also, since 0^0 is defined to be 1, RoughApproxPower(0.0, 0.0) will
produce 1.0.

so using the LIT instruction instead of your own can only be benificial in terms of speed. I’m guessing that’s what V-man is trying to do.

IMHO, it’s fairly reasonable to assume that all ops in the GL__fragment_program specs are hardware accelerated.

I don’t know if it is hw accelerated but I’ll give it a shot and see what happens.
My standard code (GLSL fs) doesn’t get recognized and I don’t see a LIT instruction. What I mean is that if it were recognized and it geenrated a LIT instruction, I’d be all set.
Anyone have any idea what the Cg function name is? I’ll just shove it in there and see what happens.

lit(float ndotl, float ndoth, float m)

Thanks. Not sure why I couldn’t find “lit” in the Cg manual.
Looks like when I compile with cgc.exe, it generates a LIT instruction. I don’t know if it improves performance.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.