🎉 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

taby said:

After some serious deliberation today, I decided to try using a different library. It's nothing personal. The library that I am using supports multiple models, layers, etc.

https://github.com/jpaver/opengametools

That's not a problem. . . My code is still in an early phase of development, and obviously doesn't support all the options yet. So I'm glad you found something which does support all those options.

Right now, my code does what I need it to, I'll import single models from Magica, and then do more complex things once I have them in my game. However, being able to deal with multiple objects and layers is definitely a good thing! So, if I don't take the time to modify my own code, I might take a look at that other library myself.

Advertisement

taby said:
Thanks for the idea. I tried it out, but it doesn't quite work. However, I tried this, and it works: const float uv_index = float(colour_index - 1) / 255.0f;

I see the color palette has 256 colors, so i assume the colour_index goes from 0 to 255? It does not start from 1?
If so, a -1 for the first color should break your math. I would test this with making a model using the first and last colors of the palette.

Yes sir JoeJ, the 0th colour is a sentinel value for an off voxel. The remaining 255 colours are actual colours. The value will not be negative because I've already done continue; long before I actually use the colour.

Hi Warp9. I look forward to trying out your library again in the future. Please keep everyone here informed of your progress! ?

The code is in a non-working state. It generates reflections of the knight, but the self-reflections for the game board are off a little bit. The code is at: https://github.com/sjhalayka/obj_ogl4

I've tried a couple of methods now, but I can't seem to get self-reflections working on the game board.

Method 1 was to scale the view matrix by (1, -1, 1), flipping it upside down.

Method 2 was to leave the camera as it is, and draw everything upside down using scale by (1, -1, 1).

Neither works LOL.

There is a 3rd option, which is more complex, which involves keeping track of the triangles that go with each 32x32 location on the game board. Then I draw each of those mini-meshes one by one. It makes for a large number of draw calls.

OK. It's time to set some limitations. I say that the game board is made up of 32x32-sized cells, and that there is a maximum of 16x16 cells. That's 512x512 big altogether. Sound reasonable?

taby said:
Method 1 was to scale the view matrix by (1, -1, 1), flipping it upside down. Method 2 was to leave the camera as it is, and draw everything upside down using scale by (1, -1, 1).

I think a working approach should be:
Translate the model matrix down twice the distance to the clipping plane and apply the flip.
But not sure.

taby said:
I draw each of those mini-meshes one by one. It makes for a large number of draw calls.

You could use a ‘custom clipping plane’ to cut off the mesh above the reflection plane. So no need to change the geometry, and one draw call should do.
Not sure how OpenGL calls this. Maybe it's an extension, but guess not. Different GPUs might support different numbers of extra planes, but you only need one.
Another, less efficient option would be to discard fragments in pixel shader.

taby said:
That's 512x512 big altogether. Sound reasonable?

Only you know what size for a level or world you want for your game. ; )

Try as I might, I cannot get it working. I'm going to take another approach at it. I've already started along the path.

I've set the level as being 128x128x128, with cell sizes of 16x16. It's like Q-Bert. ?

I kind of sort of am heading in the right direction. It sort of works! The relevant lines of code are:

model = translate(model, vec3(0, -board_mesh.get_y_extent(x, y)*2, 0));
model = scale(model, vec3(1, -1, 1));
Sort of working

This topic is closed to new replies.

Advertisement