aboutsummaryrefslogtreecommitdiff
path: root/src/main/resources/shaders/chunk.vert
blob: eb43942c1966e09f1439e41774641e0a7967921c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec2 aTexCoord;
layout (location = 2) in vec2 aBTexCoord;
layout (location = 3) in vec4 aColor;
layout (location = 4) in vec4 aMQPos; // if the first coordinate is 255, it means: disable megaquad processing for this quad

uniform mat4 modelView;
uniform mat4 proj;
uniform mat4 projInv;
uniform vec4 viewport;
uniform vec4 fogColor;
uniform vec2 fogStartEnd;

uniform vec3 playerPos;

out vec2 TexCoord;
out vec2 BTexCoord;
out vec4 Color;
out vec4 MQPos;
out vec4 Viewport;
out mat4 ProjInv;
out vec4 FogColor;
out vec2 FogStartEnd;
out float FogFactor; // -1 means: disable fog
flat out vec2 ProvokingTexCoord;

void main()
{
    gl_Position = proj * modelView * (vec4(aPos - playerPos, 1.0) + vec4(0, 0.12, 0, 0));
	TexCoord = aTexCoord;
	BTexCoord = aBTexCoord;
	Color = aColor;
	MQPos = aMQPos;
	Viewport = viewport;
	ProjInv = projInv;
	FogColor = fogColor;
	
	if(fogStartEnd.x >= 0 && fogStartEnd.y >= 0){
		float s = fogStartEnd.x;
		float e = fogStartEnd.y;
		vec4 eyePos = (modelView * (vec4(aPos - playerPos, 1.0) + vec4(0, 0.12, 0, 0)));
		
		float fogFactor = clamp((e - length(eyePos)) / (e - s), 0, 1);
		
		FogFactor = fogFactor;	
	} else {
		FogFactor = -1;
	}
	FogStartEnd = fogStartEnd;
	
	ProvokingTexCoord = aTexCoord;
}