Jump to content
  • Advertisement
Sign in to follow this  
Vincent_M

Funky Reflection Results

This topic is 2642 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

I have a scene with a basic skybox and, a couple of cameras, and an environment-mapped pillar that is spinning. I can verify that my cubemap is turning out just fine as you can tell in the image where I render a small skybox with my environment map applied to it. The only problem is that environment mapping it to the pillar isn't turning out well at all.

Here's the GLSL i'm using:

// VERTEX SHADER

precision mediump float;

precision lowp int;




uniform mat4 u_pvmMat;

uniform vec3 u_cameraPosition;

uniform mat3 u_vmMat;







attribute vec4 a_position;

attribute vec3 a_normal;




varying vec3 v_envCoord;







void main()

{

// find basic output

gl_Position = u_pvmMat * a_position;




vec3 eyeDir = normalize(a_position.xyz - u_cameraPosition);

v_envCoord = u_vmMat * reflect(eyeDir, a_normal);

}










// FRAGMENT SHADER

precision mediump float;

precision lowp int;







uniform samplerCube envMap;;

varying vec3 v_envCoord;




void main()

{

gl_FragColor = textureCube(envMap, v_envCoord);

}




Now, for my uniforms... I believe I'm transforming them correctly. My "u_vmMat" is my view-model matrix that I've gotten by multiplying my view and model matrices together. Then, I multiply my world-space "u_cameraPosition" by the inverse of my view-model matrix.

Attached is an image of what my scene looks like.

Share this post


Link to post
Share on other sites
Advertisement
Hidden
dont multiply the position by modelviewprojection, just modelview, camera position is in world, keep your vertex position in world.

Share this post


Link to post
Do a pass and output the fragment as a_normal and eyeDir, and see what is wrong.

this should be subtracted the other way around.
[color=#1C2837][size=2][color=#000000] vec3 eyeDir [color=#666600]=[color=#000000] normalize[color=#666600]([color=#000000]a_position[color=#666600].[color=#000000]xyz [color=#666600]-[color=#000000] u_cameraPosition[color=#666600]);

Share this post


Link to post
Share on other sites
[color=#1C2837][size=2]Do a pass and output the fragment as a_normal and eyeDir, and see what is wrong.

this should be subtracted the other way around.
[color=#1C2837][size=2][color=#000000]vec3 eyeDir [color=#666600]=[color=#000000] normalize[color=#666600]([color=#000000]a_position[color=#666600].[color=#000000]xyz [color=#666600]-[color=#000000] u_cameraPosition[color=#666600]);[/quote]

How do I output values from shaders? All I know is that it's a gl_FragColor trick, but haven't found any code on that.

I tried switching that line to:
[color=#1C2837][size=2][color=#1C2837][size=2][color=#000000]vec3 eyeDir [color=#666600]=[color=#000000] normalize[color=#666600](u_cameraPosition - [color=#000000]a_position[color=#666600].[color=#000000]xyz[color=#666600]);[/quote]

It gave me different results, but they weren't correct. Do you think the issue could be my normals?

Share this post


Link to post
Share on other sites

Can you describe the problem, other than "isn't turning out well"?


That's as descriptive as I can describe it in words, unfortunately. The cubemap looks distorted on my pillar as if it's scrunched together. To better illustrate the issue, I posted a screenshot in my original post. It's the image with the skybox in it right beneath the topic post.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!