@@ -6,26 +6,39 @@ export let showBlock_webgl2 = {
6
6
in vec3 position;
7
7
in vec4 color;
8
8
in vec3 textureCoord;
9
- uniform mat4 mvpMatrix;
10
- out vec4 vColor;
11
- out vec3 vTextureCoord;
9
+ // uniform mat4 mMatrix;
10
+ // uniform mat4 vMatrix;
11
+ // uniform mat4 pMatrix;
12
+ uniform mat4 mvMatrix;
13
+ uniform mat4 mvpMatrix;
14
+ out vec4 vColor;
15
+ out vec3 vTextureCoord;
16
+ out vec3 vPos;
12
17
void main(void) {
13
18
vColor = color;
14
19
vTextureCoord = textureCoord;
15
- gl_Position = mvpMatrix * vec4(position, 1.0);
20
+ vec4 pos = vec4(position, 1.0);
21
+ vPos = (mvMatrix * pos).xyz;
22
+ gl_Position = mvpMatrix * pos;
16
23
}` ,
17
24
frag : `#version 300 es
18
25
precision highp int;
19
26
precision highp float;
20
27
precision highp sampler2DArray;
21
28
uniform sampler2DArray blockTex;
22
- in vec4 vColor;
23
- in vec3 vTextureCoord;
29
+ uniform vec4 fogColor;
30
+ uniform float fogNear;
31
+ uniform float fogFar;
32
+ in vec4 vColor;
33
+ in vec3 vTextureCoord;
34
+ in vec3 vPos;
24
35
out vec4 fragmentColor;
25
36
void main(void){
26
37
vec4 smpColor = texture(blockTex, vTextureCoord);
27
38
if (smpColor.a <= 0.3) discard;
28
- fragmentColor = vColor * smpColor;
39
+ float fogDistance = length(vPos);
40
+ float fogAmount = smoothstep(fogNear, fogFar, fogDistance);
41
+ fragmentColor = mix(vColor * smpColor, fogColor, fogAmount);
29
42
}`
30
43
} ;
31
44
@@ -40,13 +53,20 @@ export let showBlock = {
40
53
attribute vec3 position;
41
54
attribute vec4 color;
42
55
attribute vec3 textureCoord;
43
- uniform mat4 mvpMatrix;
44
- varying vec4 vColor;
45
- varying vec3 vTextureCoord;
56
+ // uniform mat4 mMatrix;
57
+ // uniform mat4 vMatrix;
58
+ // uniform mat4 pMatrix;
59
+ uniform mat4 mvMatrix;
60
+ uniform mat4 mvpMatrix;
61
+ varying vec4 vColor;
62
+ varying vec3 vTextureCoord;
63
+ varying vec3 vPos;
46
64
void main(void) {
47
65
vColor = color;
48
66
vTextureCoord = textureCoord;
49
- gl_Position = mvpMatrix * vec4(position, 1.0);
67
+ vec4 pos = vec4(position, 1.0);
68
+ vPos = (mvMatrix * pos).xyz;
69
+ gl_Position = mvpMatrix * pos;
50
70
}` ,
51
71
// fs中的vColor是vs中传进来的
52
72
// precision指定精确度 此为精密度中的float
@@ -57,12 +77,18 @@ export let showBlock = {
57
77
precision mediump float;
58
78
#endif
59
79
uniform sampler2D blockTex;
60
- varying vec4 vColor;
61
- varying vec3 vTextureCoord;
80
+ uniform vec4 fogColor;
81
+ uniform float fogNear;
82
+ uniform float fogFar;
83
+ varying vec4 vColor;
84
+ varying vec3 vTextureCoord;
85
+ varying vec3 vPos;
62
86
void main(void){
63
87
vec4 smpColor = texture2D(blockTex, vTextureCoord.xy);
64
88
if (smpColor.a <= 0.3) discard;
65
- gl_FragColor = vColor * smpColor;
89
+ float fogDistance = length(vPos);
90
+ float fogAmount = smoothstep(fogNear, fogFar, fogDistance);
91
+ gl_FragColor = mix(vColor * smpColor, fogColor, fogAmount);
66
92
}`
67
93
} ;
68
94
0 commit comments