#### Archived

This topic is now archived and is closed to further replies.

# Cubemapping problems (my ocean is teh evil)

This topic is 5273 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have a problem with rendering my ocean or rather with rendering the reflection of my sky on the ocean. It doesn''t really seem to matter what I do with my texture matrix, the reflection on the ocean will show either the top, back and bottom faces or the top, front and bottom faces. The texcoords are generated by opengl using GL_REFLECTION_MAP_ARB, so I''m pretty sure I shouldnt be seeing the cubemap''s bottom side when the camera is above the water surface. Conclusion: I must be doing something quite stupid Rendering Code:

glMatrixMode(GL_MODELVIEW);
m_camera->SetView();

glEnable(GL_TEXTURE_CUBE_MAP_ARB);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);

glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_VBOVertices );
glVertexPointer( 3, GL_FLOAT, 0, (char *) NULL );
glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_VBONormals );
glNormalPointer( GL_FLOAT, 0, (char *) NULL );
glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, m_VBOIndices);

glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, m_skyCubemap);
glTexCoordPointer(3, GL_FLOAT, 0, m_texcoordstream );

glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB);
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB);

glMatrixMode(GL_TEXTURE);
glScalef(-1,-1,-1);

m_camera->rotateInvDirection();

glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);

glEnable(GL_NORMALIZE);

glDrawElements(...);

glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);

glDisable(GL_TEXTURE_CUBE_MAP_ARB);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_TEXTURE_GEN_R);


I don''t really think generation and loading of my cubemap is the problem, but if you can''t see a problem with the rendering code I''ll post the code showing creation and loading aswell. This is really confusing me, so any help would be appreciated.

##### Share on other sites
Okay, atleast two problems weren''t even in the code i posted
My normals were inverted and something else screwed around with my rotation matrix, rendering my texture matrix transforms pretty useless.

Now the ocean actually looks like it''s reflecting the sky, but I can get all 6 cubemap faces to show when I rotate around and I don''t really want to see that _evil_, _pink_ cube bottom in the middle of my ocean.

I guess given enough time I''ll figure this out aswell, but somehow it now looks like a common problem so I hope someone can point me in the right direction.

##### Share on other sites
quote:
Original post by Eternal
Now the ocean actually looks like it''s reflecting the sky, but I can get all 6 cubemap faces to show when I rotate around and I don''t really want to see that _evil_, _pink_ cube bottom in the middle of my ocean.

Well, depending on how your water wave normals and your viewpoint is oriented, you can easily get reflection vectors pointing towards the lower half of the sky cube. In reality, such view rays would reflect the water itself, but the cubemap approximation doesn''t take that into account.

The easiest solution is to replace that pink bottom of your sky map with something, hmm, less pink Usually, some shades of blue and green will do the trick. Or you can try to somehow blend in an image from an ocean surface. Another possibility is to simply mirror the sky cubemap around it''s horizon axis, and tint the bottom with some blue colour. That will simulate a kind of double reflection effect, as if the waves reflected the sky (tinted by the water colour) when the reflected ray points downwards.

If you really want to, you could also clamp the reflection vectors to never point below the horizon (using a vertex program), but that''s not worth the trouble.

Experiment a little, until you get a nice result.

##### Share on other sites
The problem I had was _still_ caused by my camera (*bangsheadagainstdesk*), now my "ocean" finally begins to resemble water.

Thanks for your reply anyway, I had realised I would get artifacts with reflections from my waves, but I was not sure how to go about this. The double reflection idea sounds nice, should be doable with decent speed even on my gf2mx.

I just wish I had more time to play around with this.

[edited by - Eternal on June 8, 2004 1:40:46 AM]

1. 1
Rutin
22
2. 2
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633307
• Total Posts
3011288
• ### Who's Online (See full list)

There are no registered users currently online

×