Whats the most efficient way to write this code?
Asked Answered
T

2

0

I'm not sure what the correct way to write this is:


 vec3 plane_a_point_1 = vec3(0.791629, 0.901993, 0.380778);
	vec3 plane_a_normal = vec3(0.3298,0.81282,-0.48016);
	vec3 vector_from_plane_a_point_1_to_p = p - plane_a_point_1;
	float plane_a_result = dot(vector_from_plane_a_point_1_to_p, plane_a_normal);
	
	vec3 plane_b_point_1 = vec3(0.827042, 0.776654, 0.506066);
	vec3 plane_b_normal = vec3(0.3298,0.81281,-0.48017);
	vec3 vector_from_plane_b_point_1_to_p = p - plane_b_point_1;
	float plane_b_result = dot(vector_from_plane_b_point_1_to_p, plane_b_normal);

	vec3 plane_c_point_1 = vec3(0.130028, 0.61924, 0.447717);
	vec3 plane_c_normal = vec3(0.32981,0.81281,-0.48018);
	vec3 vector_from_plane_c_point_1_to_p = p - plane_c_point_1;
	float plane_c_result = dot(vector_from_plane_c_point_1_to_p, plane_c_normal);

		if (overlap_plane_a_result > -0.001 && overlap_plane_a_result < 0.001) {
			discard;
		}
		else if (overlap_plane_b_result > -0.001 && overlap_plane_b_result < 0.001) {
			discard;
		}
		else if (overlap_plane_c_result > -0.001 && overlap_plane_c_result < 0.001) {
			discard;
		}

I actually tons of these planes that I'm hiding. I'm just wondering if there is a way to optimize this code? Maybe I shouldn't use if else?

Titre answered 24/5, 2022 at 18:22 Comment(0)
F
0

What is it you are trying to accomplish?

Foredate answered 24/5, 2022 at 21:39 Comment(0)
T
0

I've gota voxel game with a fixed camera. Every voxel is a billboard. But the billboards are larger than the cells so they clip into lower cells (although from the fixed camera perspective they appear to fit into the cells). So every cell has a mix of voxels that are above or below it and when I hide the ones above it I need to go into the lower cell and hide the parts that clip down into it. So for every billboard I calculate its normal and a point on the billboard then use the dot product to figure out if a the current pixel being drawn falls on the same plane that the billboard inhabits. Then I hide every pixel that falls on those planes. Unfortunately this code is rather slow and it seems I will likely have to rewrite this feature in the voxel engine itself rather than the shader...

edit actually it runs fast enough. It was something else that was lagging me. But I do wonder if there is a more optimal way to write it.

I did notice that if I replace discard; with ALPHA = 0.0; it does seem to run a bit faster.

Titre answered 25/5, 2022 at 18:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.