Problems trying to make work the explosions from the wiki

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
che1404
Gnoblar
Posts: 18
Joined: Sun Mar 18, 2007 4:50 pm

Problems trying to make work the explosions from the wiki

Post by che1404 »

Hi all!
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;
}
I am using GDebugger to debug the shader, and I have noticed that a) the 3D texture is uploaded, and b) the 3D texture has 16 dimensions in "r".
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();
} 
Well, I don't know what else to try.
Any ideas?

Regards,
Roberto.

Jusas
Halfling
Posts: 91
Joined: Mon May 14, 2007 9:14 am
x 8

Re: Problems trying to make work the explosions from the wik

Post by Jusas »

A late reply but I'm hoping not too late... I'm not too familiar with GLSL but a few questions:
- Is the texture defined as 3D in the material file?
- Is the Z-value (or alpha) meant to be between [0..1] or [1..16] ?

che1404
Gnoblar
Posts: 18
Joined: Sun Mar 18, 2007 4:50 pm

Re: Problems trying to make work the explosions from the wik

Post by che1404 »

Hi!
I finally solved it. The problem was in the material file.
I had to disable the texture filtering in z. The texture unit section now has the value:
filtering linear linear none


Regards!

Post Reply