Skip to content

Commit 8eb2866

Browse files
committed
Added code for non-euclidean terrain transitions
- This is used for a music video currently in production using the shaderpack
1 parent 089efce commit 8eb2866

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

shaders/gbuffers_main.glsl

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ float GetSpecularity(vec2 coord) {
219219

220220

221221
#include "/../shaders/lib/Fragment/TerrainParallax.fsh"
222+
#include "/../shaders/lib/Misc/Euclid.glsl"
222223

223224

224225
#if defined gbuffers_water
@@ -238,7 +239,6 @@ void main() {
238239
vec3 normal = GetNormal(coord);
239240
float specularity = GetSpecularity(coord);
240241

241-
242242
#if !defined gbuffers_water
243243
float encodedMaterialIDs = EncodeMaterialIDs(materialIDs, vec4(0.0, 0.0, 0.0, 0.0));
244244

shaders/lib/Misc/Euclid.glsl

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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

Comments
 (0)