🎉 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

I was seriously going to do that after lunch lol. Great minds think alike lol

Advertisement

Thanks again! I got rid of the black outline in the reflection.

I'm still having trouble with not doing reflections if the normal is compared against something else, in order to overwrite the specularity map with black. If I can get this working, then the upper tiles can be reflective too.

The relevant portion of the point.fs.glsl file is:

	if(specular_only == 1)
	{
		FragColor = texture(specularTexture, fs_in.TexCoords);

//		This is driving me nuts...		
//		vec3 n =  normalize(fs_in.untransformed_position);
//		vec3 n2 = normalize(viewPos - vec3(0, 0, 0)); // Use this as an example position

//		if(dot(n, n2) > -0.9)
//			FragColor = vec4(0, 0, 0, 1);
	
		return;
	}

P.S. The whole code and media are at: https://github.com/sjhalayka/obj_ogl4

An example of what I want to get rid of is:

taby said:
vec3 n2 = normalize(viewPos - vec3(0, 0, 0));

Probably you don't need a view vector at all for this. You only need to check if the fragment normal in world space is matching the planer reflection direction, which is up in the actual case.

Yes right… only do it when the normal is up. That’s genius, man!

Yep, here we go:


	if(specular_only == 1)
	{
		FragColor = texture(specularTexture, fs_in.TexCoords);
		
		vec3 n =  fs_in.untransformed_normal;
		vec3 n2 = vec3(0, 1, 0); // Use this as an example position

		if(dot(n, n2) < 0.95)
			FragColor = vec4(0, 0, 0, 1);
	
		return;
	}

Yeah, looks great.

I guess there should be some simple hack to offset the reflection depending on height a bit. But i have no precise idea how. ; )

Yeah, I’m thinking that scale by -1 on y axis, then translate upward. I’m thinking that the mesh height has something to do with it. Things will be clearer with time.

Thanks so much for all of your help!

taby said:
Yeah, I’m thinking that scale by -1 on y axis, then translate upward. I’m thinking that the mesh height has something to do with it. Things will be clearer with time.

For such case it would be helpful to have a reference. Once you see ground truth, it should be easier to get an idea and then proof its error.

So maybe it's worth you implement a second reflection plane just to get this reference.

I'm working on using procedural methods to generate the base of the level. Of course, I'm having trouble. ?

https://github.com/sjhalayka/vox_writer

This topic is closed to new replies.

Advertisement