Using dFdx? #135
-
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
The problem is that Malt uses the same source code for vertex and pixel shaders. Derivative functions are only available from pixel shaders, so to use them you have to make sure the code is only present in the generated pixel shader code: vec3 partial_derivative_x(vec3 v)
{
#ifdef PIXEL_SHADER
{
return dFdx(v);
}
#else
{
return vec3(0);
}
#endif
} Another workaround could be to just define them as macros on vertex shaders. That way the compiler won't complain: #ifndef PIXEL_SHADER
#define dFdx(a) (a)
#define dFdy(a) (a)
#endif I have thought about adding this kind of "compatibility" macros before, but I'm not sure about it. They could end up being problematic for debugging. |
Beta Was this translation helpful? Give feedback.
The problem is that Malt uses the same source code for vertex and pixel shaders.
This is more convenient for the most part, but it also means that using some built-in GLSL functions requires some extra care.
Derivative functions are only available from pixel shaders, so to use them you have to make sure the code is only present in the generated pixel shader code:
Another workaround could be to just define them as macros on vertex shaders. That way the compiler won't complain: