Skip to main content
GameDev.net gamedev.net
🔒 Locked

glsl mad function

Started by subi May 11, 2006 at 1:54 AM 2 replies 7.6k views
Original Post
subi
subi
i am just trying to convert a cg shader to glsl and cg uses a function called mad....glsl don't have this and i assume it means multiply and add is this correct than?

float mad(float a,float b,float c)
{
return a + (b*c);
}
//or this:

float mad(float a,float b,float c)
{
return (a*b)+c;
}
//or perhpas something else??

[Edited by - subi on May 11, 2006 3:35:15 AM]
RPTD
RPTD
MAD reg1, reg2, reg3, reg4

is

reg1 = ( reg2 * reg3 ) + reg4

hende second version is the one to go
Life's like a Hydra... cut off one problem just to have two more popping out.
Leader and Coder: Project Epsylon | Drag[en]gine Game Engine
Danny02
Danny02
in cg u probably us mad for optimization, in glsl the compiler should do it automaticly.

both ur above examples should be optimized automaticly in glsl.

(a+1)*0.5 //not using mad
a*0.5 +0.5 //using mad


Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.