fragment-shader

Drawing a triangle in OpenGL fragment shader

我们两清 提交于 2020-11-29 23:42:40
问题 I'm trying to draw a triangle using an OpenGL fragment shader. I succeeded in drawing a circle but I have a problem with handling the equation/logic or the code to draw a triangle. draw_triangle(vec2 v1 , vec2 v2, vec2 v3) Here is the fragment shader: #version 330 core out vec4 frag_color; void draw_circle(vec2 shift_val, int radius,int color) { vec2 res = vec2(1280,720); vec2 norm_cord = gl_FragCoord.xy; float dist = length(norm_cord - (res*shift_val)); if( dist < radius ) { if( color ==1 )

Draw a simple dotted line or dashed line in OpenGL GLES20 android using fragment shader and GL_LINE_STRIP

こ雲淡風輕ζ 提交于 2020-11-29 03:31:10
问题 I went through different sources and seen that we could draw a dotted line using a fragment shader. Because I am new to OpenGL I couldn't able to understand. Can anyone share some code sample that plot dotted or dashed line using fragment shader and GL_LINE_STRIP in Android. References: Dashed line in OpenGL3? Dotted back edges of object 回答1: Line stipple is not supported in OpenGL ES. If you use OpenGL ES 1.00, then you can use the approach which is presented in the answers to OpenGL ES -

CPU to GPU normal mapping

大憨熊 提交于 2020-06-27 18:32:06
问题 I'm creating a terrain mesh, and following this SO answer I'm trying to migrate my CPU computed normals to a shader based version, in order to improve performances by reducing my mesh resolution and using a normal map computed in the fragment shader. I'm using MapBox height map for the terrain data. Tiles look like this: And elevation at each pixel is given by the following formula: const elevation = -10000.0 + ((red * 256.0 * 256.0 + green * 256.0 + blue) * 0.1); My original code first

Why is writing to a buffer from within a fragment shader disallowed in Metal?

社会主义新天地 提交于 2020-06-24 07:04:10
问题 As stated in the Metal Shading Language Guide: Writes to a buffer or a texture are disallowed from a fragment function. I understand that this is the case, but I'm curious as to why. Being able to write to a buffer from within a fragment shader is incredibly useful ; I understand that it is likely more complex on the hardware end to not know ahead of time the end location of memory writes for a particular thread, which you don't always know with raw buffer writes, but this is a capability

Intersect a ray with a triangle in GLSL C++

徘徊边缘 提交于 2020-05-27 12:29:12
问题 I am trying to make a ray intersection with a triangle in the fragment shader, if it colide i will paint a black dot in the texture, if not colide i will paint the texture color. But it do not have effect, I do not know nothing more to do to resolve it. It is the Shader of the ground and have the coords of a geometry coming from vertex, this geometry will be draw after the ground shader. The color is coming too from the vertex shader, and the light point is a vec3 with a point in the space, I

OpenGL Convert NV12 to RGB24 using shader [closed]

こ雲淡風輕ζ 提交于 2020-02-25 01:24:19
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 days ago . I tried to write an application to display YUV image in OpenGL. I was successfully converted YUV to RGB in C++ using this snippet (source) static long int crv_tab[256]; static long int cbu_tab[256]; static long int cgu_tab[256]; static long int cgv_tab[256]; static long int tab_76309[256]; static unsigned char

OpenGL Convert NV12 to RGB24 using shader [closed]

对着背影说爱祢 提交于 2020-02-25 01:23:08
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 days ago . I tried to write an application to display YUV image in OpenGL. I was successfully converted YUV to RGB in C++ using this snippet (source) static long int crv_tab[256]; static long int cbu_tab[256]; static long int cgu_tab[256]; static long int cgv_tab[256]; static long int tab_76309[256]; static unsigned char