|
| 1 | +#if !defined EUCLID_GLSL |
| 2 | +#define EUCLID_GLSL |
| 3 | + |
| 4 | +float DistanceToPlane(vec3 point, vec3 p0, vec3 p1, vec3 p2) { |
| 5 | + vec3 normal = normalize(cross(p1 - p0, p2 - p0)); |
| 6 | + return dot(normal, point) - dot(normal, p0); |
| 7 | +} |
| 8 | + |
| 9 | +float DistanceToPlane(vec3 point, vec3 p1, vec3 p2) { |
| 10 | + vec3 normal = normalize(cross(p1, p2)); |
| 11 | + return dot(normal, point); |
| 12 | +} |
| 13 | + |
| 14 | +bool IsInsideFrustum(vec3 pos, vec3 center, float horizontalSpan, float verticalSpan) { |
| 15 | + vec3 topLeft = center + vec3(0.0, verticalSpan, -horizontalSpan ); |
| 16 | + vec3 topRight = center + vec3(0.0, verticalSpan, horizontalSpan ); |
| 17 | + vec3 botLeft = center + vec3(0.0, -verticalSpan, -horizontalSpan ); |
| 18 | + vec3 botRight = center + vec3(0.0, -verticalSpan, horizontalSpan ); |
| 19 | + |
| 20 | + vec3 camPos = cameraPosition + vec3(1000*0,0,0) + gbufferModelViewInverse[3].xyz; |
| 21 | + |
| 22 | + bool b1 = DistanceToPlane(pos, camPos, topLeft, topRight) < 0.0; |
| 23 | + bool b2 = DistanceToPlane(pos, camPos, topRight, botRight) < 0.0; |
| 24 | + bool b3 = DistanceToPlane(pos, camPos, botRight, botLeft) < 0.0; |
| 25 | + bool b4 = DistanceToPlane(pos, camPos, botLeft, topLeft) < 0.0; |
| 26 | + |
| 27 | + if (camPos.x < center.x) |
| 28 | + return !(b1||b2||b3||b4); |
| 29 | + else |
| 30 | + return !(b1&&b2&&b3&&b4); |
| 31 | +} |
| 32 | + |
| 33 | +/* Example: |
| 34 | +if (IsInsideFrustum(position[1]+cameraPosition+gbufferModelViewInverse[3].xyz, vec3(1177-1000,81.0,5.5), 0.5, 1.0)) { |
| 35 | + diffuse.rgb*= 0.0; |
| 36 | + diffuse.a *= 0.0; |
| 37 | +} |
| 38 | +*/ |
| 39 | + |
| 40 | +#endif |
0 commit comments