Cube reflection mapping problem [solved]

Problems building or running the engine, queries about how to use features etc.
Post Reply
Oogst
OGRE Expert User
OGRE Expert User
Posts: 1034
Joined: Mon Mar 29, 2004 8:49 pm
Location: the Netherlands
Contact:

Cube reflection mapping problem [solved]

Post by Oogst » Sat Apr 07, 2007 1:05 pm

I am trying to do reflection mapping using a cube map, but I get quite odd results. Now I thought the code for this would be incredibly simple, but I am able to do something wrong anyway. So: what am I doing wrong here?

Material definition:

Code: Select all

vertex_program Cg_Reflector_VP cg
{
	source Reflector.cg
	entry_point Reflector_VP
	profiles vs_2_0

	default_params
	{
		param_named_auto worldViewProjMatrix worldviewproj_matrix
		param_named_auto cameraPosition camera_position_object_space
	}
}

fragment_program Cg_Reflector_FP cg
{
	source Reflector.cg
	entry_point Reflector_FP
	profiles ps_2_0
}

material Reflector
{
	technique
	{
		pass
		{
			vertex_program_ref Cg_Reflector_VP
			{
			}
			fragment_program_ref Cg_Reflector_FP
			{
			}
			texture_unit
			{
				cubic_texture FR.tga BR.tga LF.tga RT.tga UP.tga DN.tga separateUV
			}
		}
	}
}
Shaders:

Code: Select all

void Reflector_VP
	(
		float4 position : POSITION,
		float3 normal : NORMAL,

		out float4 oPosition : POSITION,
		out float3 oReflection : TEXCOORD0,

		uniform float4x4 worldViewProjMatrix,
		uniform float3 cameraPosition
	)
{
	oPosition = mul(worldViewProjMatrix, position);
	oReflection = reflect(position - cameraPosition, normal);
}

void Reflector_FP
	(
		float3 reflection : TEXCOORD0,

		out float4 oColour : COLOR,

		uniform samplerCUBE cubeTexture
	)
{
	oColour = texCUBE(cubeTexture, reflection);
}
Last edited by Oogst on Fri Apr 13, 2007 6:44 pm, edited 3 times in total.
0 x
blog.oogst3d.net: my dev blog and portfolio
Ronimo Games: my game dev company
Awesomenauts: platforming MOBA (PC/Mac/Linux/XBox360/PS3/PS4)
Swords & Soldiers: side-scrolling RTS (PS3/Wii/PC/Mac/Linux/iPhone/iPad/Android)
Proun: abstract racing game (PC)
Cello Fortress: mixing game and live cello performance

User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19261
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
Contact:

Post by sinbad » Sat Apr 07, 2007 1:18 pm

Code: Select all

float3 reflection : TEXCOORD3, 
That should be TEXCOORD0.
0 x

Oogst
OGRE Expert User
OGRE Expert User
Posts: 1034
Joined: Mon Mar 29, 2004 8:49 pm
Location: the Netherlands
Contact:

Post by Oogst » Sat Apr 07, 2007 2:51 pm

Ow, sorry, that TEXCOORD3 is actually a problem that came from simplifying my larger shader to just post the cube map problem here. So that is not the cause.

Maybe it helps if I show what is wrong. This is what my shader looks like right now:

Image

Image

Image

As can be seen, the number of reflections changes with the distance to the camera. That really should not happen.
0 x
blog.oogst3d.net: my dev blog and portfolio
Ronimo Games: my game dev company
Awesomenauts: platforming MOBA (PC/Mac/Linux/XBox360/PS3/PS4)
Swords & Soldiers: side-scrolling RTS (PS3/Wii/PC/Mac/Linux/iPhone/iPad/Android)
Proun: abstract racing game (PC)
Cello Fortress: mixing game and live cello performance

Oogst
OGRE Expert User
OGRE Expert User
Posts: 1034
Joined: Mon Mar 29, 2004 8:49 pm
Location: the Netherlands
Contact:

Post by Oogst » Tue Apr 10, 2007 9:27 am

Does no one have a clue what I am doing wrong?
0 x
blog.oogst3d.net: my dev blog and portfolio
Ronimo Games: my game dev company
Awesomenauts: platforming MOBA (PC/Mac/Linux/XBox360/PS3/PS4)
Swords & Soldiers: side-scrolling RTS (PS3/Wii/PC/Mac/Linux/iPhone/iPad/Android)
Proun: abstract racing game (PC)
Cello Fortress: mixing game and live cello performance

jjp
Silver Sponsor
Silver Sponsor
Posts: 597
Joined: Sun Jan 07, 2007 11:55 pm
Location: Cologne, Germany
Contact:

Post by jjp » Tue Apr 10, 2007 11:19 am

I am not 100% sure because I don't know a lot about shaders yet but my guess is: you need to make sure that all your variables are in the correct space when you do the calculation. An environment map is typically oriented in world space. So that's where your position, normal and camera position have to be as well.
0 x
Enough is never enough.

User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19261
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
Contact:

Post by sinbad » Tue Apr 10, 2007 12:06 pm

Can you confirm that's actually a cube map? Have you tried using the fixed-function cubic_reflection option?

BTW: I had a weekend break from the forums which is why I didn't reply.
0 x

Oogst
OGRE Expert User
OGRE Expert User
Posts: 1034
Joined: Mon Mar 29, 2004 8:49 pm
Location: the Netherlands
Contact:

Post by Oogst » Tue Apr 10, 2007 8:16 pm

I tried putting in the fixed function version and that seems to work:

Image

Image

Reflections move nicely when I move the camera around. A bit odd, though, is that the manual says this for cubic_reflection: "Requires that you bind a cubic_texture to this texture unit and use the 'combinedUVW' option." I tried using combinedUVW, but got an entirely white object. I then tried with separateUV and that works perfectly well. Just to be sure, these are my cube-map textures:

Image

Image

Image

Image

Image

Image

I think the allignment of these is wrong, so some of these names should actually be flipped, but that should just cause seams and the air in the wrong place, not the odd repetitions I am getting with my shader.

This is my fixed function version:

Code: Select all

material Reflector
{ 
   technique 
   { 
      pass 
      { 
         texture_unit
         { 
         	env_map cubic_reflection
         	cubic_texture FR.tga BR.tga LF.tga RT.tga UP.tga DN.tga separateUV
         } 
      }
   }
}
0 x
blog.oogst3d.net: my dev blog and portfolio
Ronimo Games: my game dev company
Awesomenauts: platforming MOBA (PC/Mac/Linux/XBox360/PS3/PS4)
Swords & Soldiers: side-scrolling RTS (PS3/Wii/PC/Mac/Linux/iPhone/iPad/Android)
Proun: abstract racing game (PC)
Cello Fortress: mixing game and live cello performance

User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19261
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
Contact:

Post by sinbad » Tue Apr 10, 2007 9:02 pm

No, that's not working - you're just seeing one of the cube faces there. You do need to use combinedUVW to create a proper cube map - separateUV generates 6 2D textures needed for skyboxes.

This is the underlying problem - I missed that in the material script. The shader pipeline is just wrapping differently. Take a second look at the manul - you can't use combinedUVW with 6 textures, you actually need a proper 3D texture or just a base name (this is a nuance in the way the loading works). Either rename your files or better, use the DirectX texture tool to combine those 6 textures into a cubic DDS texture, so you can use the one filename version..
0 x

Oogst
OGRE Expert User
OGRE Expert User
Posts: 1034
Joined: Mon Mar 29, 2004 8:49 pm
Location: the Netherlands
Contact:

Post by Oogst » Wed Apr 11, 2007 3:25 pm

Ah, I totally missed that aspect! Stupid of me! I'll give it a try (cannot do that at school right now).
0 x
blog.oogst3d.net: my dev blog and portfolio
Ronimo Games: my game dev company
Awesomenauts: platforming MOBA (PC/Mac/Linux/XBox360/PS3/PS4)
Swords & Soldiers: side-scrolling RTS (PS3/Wii/PC/Mac/Linux/iPhone/iPad/Android)
Proun: abstract racing game (PC)
Cello Fortress: mixing game and live cello performance

Oogst
OGRE Expert User
OGRE Expert User
Posts: 1034
Joined: Mon Mar 29, 2004 8:49 pm
Location: the Netherlands
Contact:

Post by Oogst » Fri Apr 13, 2007 6:44 pm

OK, I tried it and indeed that was the solution to the problem. Thank you very much! :D
0 x
blog.oogst3d.net: my dev blog and portfolio
Ronimo Games: my game dev company
Awesomenauts: platforming MOBA (PC/Mac/Linux/XBox360/PS3/PS4)
Swords & Soldiers: side-scrolling RTS (PS3/Wii/PC/Mac/Linux/iPhone/iPad/Android)
Proun: abstract racing game (PC)
Cello Fortress: mixing game and live cello performance

OGRE_DT
Gnoblar
Posts: 5
Joined: Tue Jul 20, 2010 2:32 pm

Re: Cube reflection mapping problem [solved]

Post by OGRE_DT » Tue Jul 20, 2010 2:51 pm

Hi,I'm doing it now ,but i have a problem is error C3004: function "texCUBE" not supported in this profile. Why?
21:23:09: OGRE EXCEPTION(7:InternalErrorException): Unable to compile Cg program fragment_dispersion: CG ERROR : The compile returned an error.
(9) : error C3004: function "texCUBE" not supported in this profile
(12) : error C3004: function "texCUBE" not supported in this profile
(13) : error C3004: function "texCUBE" not supported in this profile
(14) : error C3004: function "texCUBE" not supported in this profile
in CgProgram::loadFromSource at f:\codingextra\ogre\shoggoth_vc8\ogre\plugins\cgprogrammanager\src\ogrecgprogrammanagerdll.cpp (line 66)
21:23:09: High-level program fragment_dispersion encountered an error during loading and is thus not supported.
OGRE EXCEPTION(7:InternalErrorException): Unable to compile Cg program fragment_dispersion: CG ERROR : The compile returned an error.
(9) : error C3004: function "texCUBE" not supported in this profile
(12) : error C3004: function "texCUBE" not supported in this profile
(13) : error C3004: function "texCUBE" not supported in this profile
(14) : error C3004: function "texCUBE" not supported in this profile
in CgProgram::loadFromSource at f:\codingextra\ogre\shoggoth_vc8\ogre\plugins\cgprogrammanager\src\ogrecgprogrammanagerdll.cpp (line 66)
0 x

User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19261
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
Contact:

Re: Cube reflection mapping problem [solved]

Post by sinbad » Fri Jul 23, 2010 2:16 pm

The error is accuate, it means the shader profile doesn't support texCUBE. The most likely reason is that you accidentally used a vertex shader profile for a fragment shader. It's clear you didn't just copy the example because the shader name is different.
0 x

OGRE_DT
Gnoblar
Posts: 5
Joined: Tue Jul 20, 2010 2:32 pm

Re: Cube reflection mapping problem [solved]

Post by OGRE_DT » Fri Jul 23, 2010 3:10 pm

sinbad wrote:The error is accuate, it means the shader profile doesn't support texCUBE. The most likely reason is that you accidentally used a vertex shader profile for a fragment shader. It's clear you didn't just copy the example because the shader name is different.
yes, you are right. I changed the vertex shader profile for vs_1_1 vp40. And it works. Thank you for your help.
0 x

Post Reply