🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

OpenGL 4 reflections

Started by
110 comments, last by taby 1 year, 7 months ago

Nice shot.

taby said:
I kind of sort of am heading in the right direction. It sort of works!

To me the problem is that seemingly it works better than it should work.
The reflections on the lowest level are correct.
But the reflections on the next higher two levels seem correct too, at some spots at least. Although they should be off.

If you're confused too, for whatever reasons, i would edit the scene to filter out false conclusions. Make every block a different color, avoid repetition. Also turn off shadows because they can look similar to reflections. Visualize where the reflection plane is.

I'm personally confused the most about this:

How can it be both those reflections are correct, although the reflecting surfaces are at different height.

You should figure out. Maybe you can save gaming by making 2000 bucks GPUs obsolete. \:D/

Advertisement

LOL. Yes it is confusing. I'm sure that I'll figure it out eventually. If I can make it work, then yes, it would be lookin reaaal nice.

Here's a screenshot without shadows. It seems that the undesired effect is exacerbated by y height.

Really looks awesome. Like glass.

Now tell me: Do you render multiple times to get the reflections? Like for each height level?

Yes I divided the board up into 8x8 mini meshes.

Oh, no, I only do one pass for specularity and one for regular.

P.S. It is reflecting in the wrong plane. I need to do some kind of translations so that it uses the right plane. I'll figure it out sooner or later LOL

P.P.S. This is driving me nuts! LOL

taby said:
Oh, no, I only do one pass for specularity and one for regular.

Then this is the most astonishing case of ‘bug or feature’ i've ever seen.
Be sure to keep backups.

Cool man! Well im making slight progress. I’ve backed up yesterday, and now that I’m stuck on these lines of code, I haven’t had to submit the files.

it will work, I’m sure of it! Thanks for your comments, man!

P.S. The code is at: https://github.com/sjhalayka/obj_ogl4

The relevant code is:


float height = distance(board_mesh.get_y_min(), board_mesh.get_y_min(x, y));
float normalized_height = height / board_mesh.get_y_extent();

model = translate(model, vec3(0, -board_mesh.get_y_extent(x, y) * 2, 0));

model = scale(model, vec3(1, -1, 1));

taby said:
Yes I divided the board up into 8x8 mini meshes.

Ah… now i might get it…

So you draw each ‘column’ of the scene individually, and you set up a mirrored transform for each? (I thought the whole board is just one mesh and transform.)
And you also do this for the character, assuming the reflection plane is right below its feet?

Yes. Mystery solved, at least for me : )

And this is your problem?:

The column in the middle is actually reflected on two surfaces.
But both surfaces have a different height. And you can only pick one. On the red side it's correct, on the blue side it's wrong.

Is it like that?

JoeJ said:

taby said:
Yes I divided the board up into 8x8 mini meshes.

Ah… now i might get it…

So you draw each ‘column’ of the scene individually, and you set up a mirrored transform for each? (I thought the whole board is just one mesh and transform.)
And you also do this for the character, assuming the reflection plane is right below its feet?

Yes. I tried multiple ways of doing it with one big mesh, and so I thought that I'd try to do it using multiple small meshes. Doesn't matter if the character is standing on firm ground, the reflection will always happen under its feet. Kind of a hack?

Yes. Mystery solved, at least for me : )

And this is your problem?:

The column in the middle is actually reflected on two surfaces.
But both surfaces have a different height. And you can only pick one. On the red side it's correct, on the blue side it's wrong.

Is it like that?

You very well might have it right. I'm going to try a bit more things today – I'm convinced that simple transformations is the key to this problem. If I can't figure it out today, then it'll have to wait while I work on other stuff. ?

The code, now, is:


float height = distance(board_mesh.get_y_min(), board_mesh.get_y_min(x, y));
float normalized_height = height / board_mesh.get_y_extent();

model = translate(model, vec3(0, -board_mesh.get_y_extent(x, y) * 2, 0));

model = translate(model, vec3(0, y_offset * normalized_height * board_mesh.get_y_extent() / 2, 0));

model = scale(model, vec3(1, -1, 1));

It’s not a total loss. character reflections still work. kind of a hack. Next up is texture projection.

P.S. Right now it's reflecting on the wrong plane. I mean, if you know how to reflect on an arbitrary y height, then it's totally possible to get the neighbouring cells' height too. That way you can sample and average the heights. Would this help?

This topic is closed to new replies.

Advertisement