Skip to content

Commit 5ca8032

Browse files
committed
line segment shaders added
1 parent 34695c6 commit 5ca8032

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
}

0 commit comments

Comments
 (0)