Add threshold geometry shader, refactor vertex and fragment shaders

This commit is contained in:
Dan Paulat 2023-08-18 00:30:27 -05:00
parent 5e1b1a5ba6
commit 69f93d6faf
9 changed files with 83 additions and 14 deletions

View file

@ -1,5 +1,5 @@
#version 330 core #version 330 core
in vec4 color; smooth in vec4 color;
layout (location = 0) out vec4 fragColor; layout (location = 0) out vec4 fragColor;

View file

@ -4,7 +4,7 @@ layout (location = 1) in vec4 aColor;
uniform mat4 uMVPMatrix; uniform mat4 uMVPMatrix;
out vec4 color; smooth out vec4 color;
void main() void main()
{ {

View file

@ -16,7 +16,7 @@ uniform mat4 uMapMatrix;
uniform vec2 uMapScreenCoord; uniform vec2 uMapScreenCoord;
smooth out vec2 texCoord; smooth out vec2 texCoord;
flat out vec4 modulate; smooth out vec4 color;
vec2 latLngToScreenCoordinate(in vec2 latLng) vec2 latLngToScreenCoordinate(in vec2 latLng)
{ {
@ -31,7 +31,7 @@ void main()
{ {
// Pass the texture coordinate and color modulate to the fragment shader // Pass the texture coordinate and color modulate to the fragment shader
texCoord = aTexCoord; texCoord = aTexCoord;
modulate = aModulate; color = aModulate;
vec2 p = latLngToScreenCoordinate(aLatLong) - uMapScreenCoord; vec2 p = latLngToScreenCoordinate(aLatLong) - uMapScreenCoord;

View file

@ -12,13 +12,21 @@ layout (location = 1) in vec2 aXYOffset;
layout (location = 2) in vec2 aTexCoord; layout (location = 2) in vec2 aTexCoord;
layout (location = 3) in vec4 aModulate; layout (location = 3) in vec4 aModulate;
layout (location = 4) in float aAngleDeg; layout (location = 4) in float aAngleDeg;
layout (location = 5) in int aThreshold;
uniform mat4 uMVPMatrix; uniform mat4 uMVPMatrix;
uniform mat4 uMapMatrix; uniform mat4 uMapMatrix;
uniform vec2 uMapScreenCoord; uniform vec2 uMapScreenCoord;
out VertexData
{
int threshold;
vec2 texCoord;
vec4 color;
} vsOut;
smooth out vec2 texCoord; smooth out vec2 texCoord;
flat out vec4 modulate; smooth out vec4 color;
vec2 latLngToScreenCoordinate(in vec2 latLng) vec2 latLngToScreenCoordinate(in vec2 latLng)
{ {
@ -31,9 +39,15 @@ vec2 latLngToScreenCoordinate(in vec2 latLng)
void main() void main()
{ {
// Pass the texture coordinate and color modulate to the fragment shader // Pass the threshold to the geometry shader
vsOut.threshold = aThreshold;
// Pass the texture coordinate and color modulate to the geometry and
// fragment shaders
vsOut.texCoord = aTexCoord;
vsOut.color = aModulate;
texCoord = aTexCoord; texCoord = aTexCoord;
modulate = aModulate; color = aModulate;
vec2 p = latLngToScreenCoordinate(aLatLong) - uMapScreenCoord; vec2 p = latLngToScreenCoordinate(aLatLong) - uMapScreenCoord;

View file

@ -3,16 +3,28 @@
layout (location = 0) in vec2 aScreenCoord; layout (location = 0) in vec2 aScreenCoord;
layout (location = 1) in vec2 aXYOffset; layout (location = 1) in vec2 aXYOffset;
layout (location = 2) in vec4 aColor; layout (location = 2) in vec4 aColor;
layout (location = 3) in int aThreshold;
uniform mat4 uMVPMatrix; uniform mat4 uMVPMatrix;
uniform mat4 uMapMatrix; uniform mat4 uMapMatrix;
uniform vec2 uMapScreenCoord; uniform vec2 uMapScreenCoord;
out vec4 color; out VertexData
{
int threshold;
vec2 texCoord;
vec4 color;
} vsOut;
smooth out vec4 color;
void main() void main()
{ {
// Pass the color to the fragment shader // Pass the threshold and color to the geometry shader
vsOut.threshold = aThreshold;
// Pass the color to the geometry and fragment shaders
vsOut.color = aColor;
color = aColor; color = aColor;
vec2 p = aScreenCoord - uMapScreenCoord; vec2 p = aScreenCoord - uMapScreenCoord;

View file

@ -6,11 +6,11 @@ precision mediump float;
uniform sampler2D uTexture; uniform sampler2D uTexture;
smooth in vec2 texCoord; smooth in vec2 texCoord;
flat in vec4 modulate; smooth in vec4 color;
layout (location = 0) out vec4 fragColor; layout (location = 0) out vec4 fragColor;
void main() void main()
{ {
fragColor = texture(uTexture, texCoord) * modulate; fragColor = texture(uTexture, texCoord) * color;
} }

41
scwx-qt/gl/threshold.geom Normal file
View file

@ -0,0 +1,41 @@
#version 330 core
layout (triangles) in;
layout (triangle_strip, max_vertices = 3) out;
uniform float uMapDistance;
in VertexData
{
int threshold;
vec2 texCoord;
vec4 color;
} gsIn[];
smooth out vec2 texCoord;
smooth out vec4 color;
void main()
{
if (gsIn[0].threshold <= 0 || // If Threshold: 0 was specified, no threshold
gsIn[0].threshold >= uMapDistance || // If Threshold is above current map distance
gsIn[0].threshold >= 999) // If Threshold: 999 was specified (or greater), no threshold
{
gl_Position = gl_in[0].gl_Position;
texCoord = gsIn[0].texCoord;
color = gsIn[0].color;
EmitVertex();
gl_Position = gl_in[1].gl_Position;
texCoord = gsIn[1].texCoord;
color = gsIn[1].color;
EmitVertex();
gl_Position = gl_in[2].gl_Position;
texCoord = gsIn[2].texCoord;
color = gsIn[2].color;
EmitVertex();
EndPrimitive();
}
}

View file

@ -252,7 +252,8 @@ set(SHADER_FILES gl/color.frag
gl/text.vert gl/text.vert
gl/texture1d.frag gl/texture1d.frag
gl/texture1d.vert gl/texture1d.vert
gl/texture2d.frag) gl/texture2d.frag
gl/threshold.geom)
set(CMAKE_FILES scwx-qt.cmake) set(CMAKE_FILES scwx-qt.cmake)

View file

@ -12,6 +12,7 @@
<file>gl/texture1d.frag</file> <file>gl/texture1d.frag</file>
<file>gl/texture1d.vert</file> <file>gl/texture1d.vert</file>
<file>gl/texture2d.frag</file> <file>gl/texture2d.frag</file>
<file>gl/threshold.geom</file>
<file>res/config/radar_sites.json</file> <file>res/config/radar_sites.json</file>
<file>res/fonts/din1451alt.ttf</file> <file>res/fonts/din1451alt.ttf</file>
<file>res/fonts/din1451alt_g.ttf</file> <file>res/fonts/din1451alt_g.ttf</file>