GLSL Volumetric light Scattering shader in Max ...?
Hello, I'd like to test this shader in Max (thanks Tarik Barr <3) and I still have problem to implement it.
The shader is described there:
https://stackoverflow.com/questions/13489703/sfml-2-0-glsl-volumetric-light-scattering-shader
Would someone could point me my obvious stupid error ...? I'm sure there is one.
going to gl.pix with codebox with it could be better...
still on it...
uniform float exposure;
uniform float decay;
uniform float density;
uniform float weight;
uniform vec2 lightPositionOnScreen;
uniform sampler2D myTexture;
const int NUM_SAMPLES = 100 ;
void main()
{
vec2 deltaTextCoord = vec2( gl_TexCoord[0].st - lightPositionOnScreen.xy );
vec2 textCoord = gl_TexCoord[0].st;
deltaTextCoord *= 1.0 / float(NUM_SAMPLES) * density;
float illuminationDecay = 1.0;
for(int i=0; i < NUM_SAMPLES ; i++)
{
textCoord -= deltaTextCoord;
vec4 sample = texture2D(myTexture, textCoord);
sample *= illuminationDecay * weight;
gl_FragColor += sample;
illuminationDecay *= decay;
}
gl_FragColor *= exposure;
}
the shader and patch you posted mixes rectangular textures with non-rectangular texture sampling. rectangular textures (jit.gl.texture @rectangle 1, the default) need to be sampled using sampler2DRect, texture2Drect and using texture coordinates that have been scaled using the texture matrix:
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
otherwise, set the texture to non-rect (@rectangle 0)
i'd recommend checking our federico's excellent implementation here
it was easIER with codebox than with jxs shader writing. more natural in many ways.
(THANKS Tarik B. for having quoted the shader way instead of other "real" volumetric 3D stuff)