Funky Reflection Results

Started by
4 comments, last by Vincent_M 12 years, 6 months ago
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.
Advertisement
Any ideas. I've been stuck on this all day and the Khronos SDKshows a working example, but I can seem to duplicate results.
dont multiply the position by modelviewprojection, just modelview, camera position is in world, keep your vertex position in world.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

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]);

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

[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?
Can you describe the problem, other than "isn't turning out well"?

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.

This topic is closed to new replies.

Advertisement