Sign in to follow this  
Yours3!f

cube mapping in OGL 3.3

Recommended Posts

Yours3!f    1532
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:
[code]
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();
[/code]

the vertex shader:
[code]
/*
* 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;
}
[/code]

and the pixel shader:
[code]
/*
* 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);
}
[/code]

any ideas why it looks like that?

Best regards,
Yours3!f

Share this post


Link to post
Share on other sites
karwosts    840
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
Ashaman73    13715
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
Yours3!f    1532
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
Yours3!f    1532
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...
[url="http://en.wikibooks.org/wiki/Blender_3D:_Noob_to_Pro/Detailing_Your_Simple_Person_1"]http://en.wikibooks.org/wiki/Blender_3D:_Noob_to_Pro/Detailing_Your_Simple_Person_1[/url]
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this