• Advertisement
Sign in to follow this  

cube mapping in OGL 3.3

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

I ran into this issue when I tried to make a cube mapped sphere. The sphere seems to be getting the reflected texture, however the texture looks wierd... (see the picture)

here's how I render the sphere:

modelview_stack.push_matrix();

modelview_stack.translate_matrix ( mymath::vec3f ( 5.0f, 0.0f, -2.0f ) );

the_pipeline.get_projection_matrix().copy_m4x4_data ( proj );
the_pipeline.get_model_view_matrix().copy_m4x4_data ( mv );

cube_mapping_shader.use_program();

//passing the modelview, projection matrices, and the texture
glUniformMatrix4fv ( glGetUniformLocation ( cube_mapping_shader.shader_program, cube_mapping_shader.resources[0].name.c_str() ), 1, false, mv );
glUniformMatrix4fv ( glGetUniformLocation ( cube_mapping_shader.shader_program, cube_mapping_shader.resources[1].name.c_str() ), 1, false, proj );
glUniform1i ( glGetUniformLocation ( cube_mapping_shader.shader_program, cube_mapping_shader.resources[2].name.c_str() ), 0 );

//bind the 3D cubemap texture
glBindTexture ( GL_TEXTURE_CUBE_MAP, cube_map_tex.tex_data );
glTexParameteri ( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri ( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri ( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
glTexParameteri ( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
glTexParameteri ( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE );

//draw sphere with VBOs and VAO
draw_meshes_vbo ( sphere );

cube_mapping_shader.return_to_fixed_program();

modelview_stack.pop_matrix();


the vertex shader:

/*
* cube_map.vs
*
*/
#version 330

uniform mat4 m4_mv, m4_p;

in vec4 v4_vertex;
in vec3 v3_normal;

out vec3 reflection_vec;

void main()
{
//reflecting the mv transformed normal vector about the mv transformed and normalized vertex
reflection_vec = (m4_mv * vec4(reflect((m4_mv * vec4(v3_normal, 0.0)).xyz, normalize((m4_mv * v4_vertex).xyz)), 0.0)).xyz;

//mvp transformation
gl_Position = m4_p * m4_mv * v4_vertex;
}


and the pixel shader:

/*
* cube_map.ps
*
*/
#version 330

uniform samplerCube cubemap;

in vec3 reflection_vec;

out vec4 v4_frag_color;

void main()
{
//just get the texel at reflection_vec
v4_frag_color = texture(cubemap, reflection_vec);
}


any ideas why it looks like that?

Best regards,
Yours3!f

Share this post


Link to post
Share on other sites
Advertisement
You should generate the reflection vector in the pixel shader if you want to get rid of the texture artifacts (the square grid look).

Share this post


Link to post
Share on other sites
It looks like an unsmoothed sphere (quads are not sharing the same normals). I would sugguest to check your model first and try to smooth it (max =smooth groups, blender = smooth object).

Share this post


Link to post
Share on other sites
thanks for the replies guys...

@karwosts
I guess you're not right, I checked it in OGL superbible 5th edition and in the example they calculate the reflection vector in the vertex shader.

@Ashaman73
I guess you're right, I checked it with immediate mode, and it displayed right. can you please upload somewhere a sphere with the right normals? (in an obj file)
I'm not good at all in blender...

Share this post


Link to post
Share on other sites
You can use my lib if you want. See link below. The function is called glhCreateSpheref2.

Share this post


Link to post
Share on other sites
Thanks V-man,

I tried it out, however since I'm on Linux I couldn't compile it, because it uses many windows specific stuff.
I googled a lot, and based on this article I could get a smooth sphere in Blender...
http://en.wikibooks.org/wiki/Blender_3D:_Noob_to_Pro/Detailing_Your_Simple_Person_1
as the title shows I'm a real noob in Blender :)

Thanks for the help!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement