Hello friends, I'm trying let the player draw lines from one point to another like the game “The Witness”.
This system would also also draw lines without user input. A good way of seeing it would be like health bars that fill up but are more than just straight rectangles, they take lefts, rights…you know like paths?
But I'd like mine to be part of a UI and not in perspective projection. Not sure if that makes sense. I've never done this before but wanted to know if you all have any suggestions or if my approaches are way off:
Approach 1: I thought of batching up a bunch of a vertex points (DynamicDraw) that will get rendered as GL_LINES in one single draw call. Afterwards I could give it a nice effect in the fragment shader?
Approach 2: Same as Approach 1 but using quads.
Approach 3: Jump out of the window if I don't figure it out. Just kidding :P
Thank you very much for your interaction, I had a feeling that seemed like the right thing.
taby said:
Do you have the code for an orthographic projection shader program?
I do actually, let me share it with you. It's nothing out of the ordinary so please don't laugh. :D
This is vertex shader. For the MVP, I'm passing a mat4 which is only the model matrix. I tried passing a projection matrix, but I didn't get it to work. The way you see it below, it's working okay
#version 330 core
layout (location = 0) in vec3 vertex_position;
layout (location = 2) in vec2 uv_position;
out vec2 uv;
uniform mat4 model;
uniform mat4 sprite_matrix;
void main () {
uv = (sprite_matrix * vec4(uv_position, 0, 1)).xy;
gl_Position = model * vec4(vertex_position.xy, 0.0, 1.0);
}
And now the fragment shader, I'm just using a color or a texture.
You know that you can set alpha transparency in a shader like any other value when calculating the final output on screen. This way you can for example blend alpha conditionally from the center of a texture to have it fade out to the edges or just give a threshold value that determines which pixels should be visible in the end. The same can be done for your board, just render a quad all over the area in which you want to draw the lines and either use a blend mask or a collection of points in which the texture should be visible.
Instead of a texture blending, you could also set the original texture's color for certain points so that the white lines are “drawn directly to the base texture” of the game board. It's the same as drawing a heat map or something like in SimCity
You know that you can set alpha transparency in a shader like any other value when calculating the final output on screen. This way you can for example blend alpha conditionally from the center of a texture to have it fade out to the edges or just give a threshold value that determines which pixels should be visible in the end. The same can be done for your board, just render a quad all over the area in which you want to draw the lines and either use a blend mask or a collection of points in which the texture should be visible.
Instead of a texture blending, you could also set the original texture's color for certain points so that the white lines are “drawn directly to the base texture” of the game board. It's the same as drawing a heat map or something like in SimCity
Thank you very much for these suggestions! I need to wrap my mind around it and give it a few tries, but I'm sure I'll get it. Thanks again.
taby said:
Hmm. Perhaps I'm not doing things right, but here is my code in any case:
#version 400
layout(location = 0) in vec3 position;
layout(location = 1) in vec2 texcoord;
out vec2 ftexcoord;
void main()
{
ftexcoord = texcoord;
gl_Position = vec4(position, 1.0);
}
Hey thanks for the samples! This is perfect so I can learn quicker, I'll 100% try to implement this into my project. Thanks again for taking the time for writing some code, time is very valuable, so I appreciate it. Salute.
NightCreature83 said:
You know you can just attache RenderDoc or Intels GPA and see what that drawcall looks like in that game right?
Hey NightCreature, thanks for replying to my thread! You know, I use RenderDoc to debug my own work, but it never occurred to me to try it out with another gamer XD. Now I'm curious. But you're right, maybe it's a good way to see how all this is done. Thanks!
@8Observer8 Good one! Thanks for sharing, I'm actually still working on this so this is also very helpful. Thank you very much for sharing your code with me. Salute!