GLSL and your own defined functions

Started by
9 comments, last by zedzeek 18 years, 8 months ago
I don't see lerp() as a function in GLSL like HLSL? I coded up my own version and works fine in render monkey but in my engine it fails?

vec3 lerp(vec4 a, vec4 b, float s)
{
    return vec3(a + (b - a) * s);       
}

thats the function ahead of void main(void) do I have to pass in these functions as somekind of variable on the client side? Thanks
Advertisement
fails how?
and are you sure that mix() wont do the job?
Hi,
You can put that code in your method that compile and link your shader to see if there is an error message (which is writen in a file), and us what it is :

GLint infologLength = 0;	GLint charsWritten  = 0;	GLchar *infoLog;	glGetObjectParameterivARB(ph, GL_OBJECT_INFO_LOG_LENGTH_ARB, &infologLength);		    if (infologLength > 0)	    {			cout<<"shader "<<infologLength<<endl ;			infoLog = (char *)malloc(infologLength);			glGetInfoLogARB(ph, infologLength, &charsWritten, infoLog);			ofstream oFile3("infoLogFile.txt");			oFile3<<infoLog ;			free(infoLog);	    }
Re-hi !
The previous post is mine ;-)
Quote:Original post by phantom
and are you sure that mix() wont do the job?

That's so bizarre. Why did they call it "mix" instead of "lerp"?
Quote:Original post by Sneftel
That's so bizarre. Why did they call it "mix" instead of "lerp"?


mix() is also used by the renderman api.
glsl has quite a lot in common with above mentioned api
actually I like it, but your mileage may vary :)


Seb sorry I am getting an error on the glGetInfoLogARB saying it doesn't take 4 parameters, so I am giving up. Ok, I am using mix(). So when you code your own functions their isn't anything special I need to do then?

Thanks all
I'd heard that it owed a lot to Renderman, but I'd never used that system. I wonder why they chose "mix" for Renderman, though... was it an attempt to make the terminology less "mathy"?
i'm guessing because if you supply it with two colours it will 'mix' between them [smile]

Mars, afaik you dont have todo anything special, just make sure the compiler knows how to call the function like you'd do in C or C++.
Quote:Original post by Sneftel
I'd heard that it owed a lot to Renderman, but I'd never used that system. I wonder why they chose "mix" for Renderman, though... was it an attempt to make the terminology less "mathy"?


Renderman mix function actually looks like this (surprise! :p)

color mix(color,color,float)

maybe they chose mix instead of lerp, because "mixing colors"
sounds more natural than "lerping colors"

This topic is closed to new replies.

Advertisement