Cube reflection mapping problem [solved]

Problems building or running the engine, queries about how to use features etc.

Cube reflection mapping problem [solved]

Postby 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.
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: 1029
Kudos: 33
Joined: 29 Mar 2004
Location: the Netherlands

Postby sinbad » Sat Apr 07, 2007 1:18 pm

Code: Select all
float3 reflection : TEXCOORD3, 

That should be TEXCOORD0.
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
 
Posts: 19258
Kudos: 69
Joined: 06 Oct 2002
Location: Guernsey, Channel Islands

Postby 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.
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: 1029
Kudos: 33
Joined: 29 Mar 2004
Location: the Netherlands

Postby Oogst » Tue Apr 10, 2007 9:27 am

Does no one have a clue what I am doing wrong?
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: 1029
Kudos: 33
Joined: 29 Mar 2004
Location: the Netherlands

Postby 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.
Enough is never enough.
jjp
Silver Sponsor
Silver Sponsor
 
Posts: 597
Kudos: 0
Joined: 07 Jan 2007
Location: Cologne, Germany

Postby 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.
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
 
Posts: 19258
Kudos: 69
Joined: 06 Oct 2002
Location: Guernsey, Channel Islands

Postby 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
         }
      }
   }
}
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: 1029
Kudos: 33
Joined: 29 Mar 2004
Location: the Netherlands

Postby 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..
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
 
Posts: 19258
Kudos: 69
Joined: 06 Oct 2002
Location: Guernsey, Channel Islands

Postby 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).
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: 1029
Kudos: 33
Joined: 29 Mar 2004
Location: the Netherlands

Postby 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
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: 1029
Kudos: 33
Joined: 29 Mar 2004
Location: the Netherlands

Re: Cube reflection mapping problem [solved]

Postby 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)
OGRE_DT
Gnoblar
 
Posts: 5
Kudos: 0
Joined: 20 Jul 2010

Re: Cube reflection mapping problem [solved]

Postby 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.
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
 
Posts: 19258
Kudos: 69
Joined: 06 Oct 2002
Location: Guernsey, Channel Islands

Re: Cube reflection mapping problem [solved]

Postby 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.
OGRE_DT
Gnoblar
 
Posts: 5
Kudos: 0
Joined: 20 Jul 2010


Return to Help

Who is online

Users browsing this forum: No registered users and 1 guest