I want to share a problem which is driving me crazy.
I want to replicate the explosion method shown in the Ogre Wiki http://www.ogre3d.org/tikiwiki/Explosio ... e=Cookbook.
I have been able to make work the HLSL explosion, but not the GLSL one, which should be very easy to implement. The fragment program only accesses the 3D texture using the "st" texture coordinates and 1.0 minus the alpha value of the current color. This one seems to work using Direct3D RenderSystem and the HLSL implementation, which is:
Code: Select all
void main_vp(float4 position : POSITION,
float2 uv : TEXCOORD0,
float4 color : COLOR0,
out float4 oPosition : POSITION,
out float2 oUv : TEXCOORD0,
out float4 oColor : COLOR0,
uniform float4x4 worldViewProj)
{
oPosition = mul(worldViewProj, position);
oUv = uv;
oColor = color;
}
void main_fp(
float4 position : POSITION,
float2 uv : TEXCOORD0,
float4 color : COLOR0,
uniform sampler3D tex:register(s0),
out float4 oColour : COLOR)
{
oColour = tex3D( tex, float3(uv.x, uv.y, 1.0 - color.a));
}And this is the GLSL fragment shader I want to make work:
Code: Select all
uniform sampler3D tex;
void main()
{
vec4 color = vec4(0.0, 0.0, 0.0, 0.0);
vec3 textureAccessIndex = vec3(0.0, 0.0, 0.0);
textureAccessIndex.x = gl_TexCoord[0].s;
textureAccessIndex.y = gl_TexCoord[0].t;
textureAccessIndex.z = gl_Color.a * 16.0;
color = texture3D(tex, textureAccessIndex);
gl_FragColor = color;
}So I use the alpha value of the current color and multiply it by 16.0, which seems to be enough to access the 3D Texture. Please, tell me if
I'm wrong, because this doesn't work.
I have tried using a 2D texture, and the texture2D method to get the final color, and it works. So I don't really know where the problem is, but it
seems that the texture3D call is not working for some reason.
This is the vertex shader, maybe the problem is in here?:
Code: Select all
uniform mat4 worldViewProj;
void main()
{
gl_FrontColor = gl_Color;
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
} Any ideas?
Regards,
Roberto.