File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed
Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+ #version 330
2+
3+ uniform bool IsFogged;
4+ uniform float FogMin;
5+ uniform float FogMax;
6+ uniform vec4 CameraEye;
7+ uniform vec4 FogColor;
8+
9+ in VertexData{
10+ vec4 mColor;
11+ vec4 mVertex; // to calculate distance to camera eye
12+ } VertexIn;
13+
14+ float getFogFactor(float d)
15+ {
16+ if (d>= FogMax) return 1 ;
17+ if (d<= FogMin) return 0 ;
18+
19+ return 1 - (FogMax - d) / (FogMax - FogMin);
20+ }
21+
22+ void main(void )
23+ {
24+ vec4 color = VertexIn.mColor;
25+ if (IsFogged){
26+ float d = distance (CameraEye, VertexIn.mVertex);
27+ float alpha = getFogFactor(d);
28+ color = mix (color, FogColor, alpha);
29+ }
30+
31+ gl_FragColor = color;
32+ // vec4(VertexIn.mColor.rgb, alpha);
33+ }
Original file line number Diff line number Diff line change 1+ #version 330
2+
3+ uniform mat4 ModelViewProjectionMatrix;
4+ uniform mat4 CanvasMatrix;
5+
6+ layout (location = 0 ) in vec4 Vertex;
7+ layout (location = 1 ) in vec4 Color;
8+
9+ out VertexData{
10+ vec4 mColor;
11+ vec4 mVertex; // to calculate distance to camera eye
12+ } VertexOut;
13+
14+ void main(void )
15+ {
16+ VertexOut.mColor = Color;
17+ VertexOut.mVertex = CanvasMatrix * Vertex;
18+ gl_Position = ModelViewProjectionMatrix * Vertex;
19+ }
You can’t perform that action at this time.
0 commit comments