change specific pixel color via fragment/pixel shader?(opengl) [closed] - opengl

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Is there any way to change specific pixel color via fragment/pixel shader? (like a uniform variable?)
To be specific, im trying to implement ray-traced shadows.

If by pixel you mean an actual pixel on the screen, then you can achieve that with multistage rendering. Render your scene to an FBO (to a texture), then render the quad onto a screen with that texture.
If the FBO texture size will be exactly the same as screen size, every invocation of the fragment shader will nicely correspond to the screen position.

Related

How to handle texture animation in OpenGL? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I started using OpenGL with SDL2 and GLEW not so long ago, and I got two questions:
How to pass a texture to GLSL's uniform sampler2D ? It seems to do it automatically when binded, but it confuses me.
And the main question here:
What's the best way to handle texture animation?
Should I do it by GL_TEXTURE_3D? By loading all frames into multiple GL_TEXTURE_2D? Is there a built-in way for animation?
glActiveTexture and glBindTexture calls in this order will bind a texture to the given sampler slot.
Use a spritesheet as a TEXTURE_2D, and change the texture coordinates for swapping the animation frames.

How to make low-res graphics with opengl? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I am writing using opengl in C and I want to make oldschool style graphics – like Star Fox for SNES. So I plan to have a 2D array (I'll figure out how, just talking pseudocode for now) of fragments that will represent the lower resolution (you can imagine just containing rbg color info). So I'm going to be writing my own code that makes the 3D world and rasterizes it into this 2D array (might try to get the GPU to help there). Does this even make sense? Are there better ways to make low-res 2D graphics using OpenGL?
Render scene to low-resolution FBO.
Stretch-blit FBO contents to screen using a textured quad or glBlitFramebuffer().

opengl instanced drawing - 3D Arrows [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have to draw millions of arrows. The information I have is as below.
location of each arrow
direction of each arrow (vector direction)
length if each arrow
With this information, can I use opengl instanced drawing to draw arrows.
I have gone through the instanced examples. In all those examples, they have explained matrix transformations for each instance etc... .
But, I am not clear, with the above data, whether it is possible to do or not.
Given that the arrow is a vector, you can just insert all your vector data into a uniform array** and use gl_InstanceID to look them up in your vertex shader and simply pass them over to gl_Position.
If you need to apply a transformation to the arrows (by looking at your data: translation for the location, rotation for the direction and scaling for the length), you would issue the instanced drawing statement on a single set of vertices (your base arrow), use a uniform array of matrices for the transformation and look those matrices up in a similar way in your vertex shader.
**Depending on how many instances you have though,the data may not fit into a uniform array. So you can look into using a Uniform block (which allows you to store more data than a simple uniform variable) and if that is also not enough, a GL_TEXTURE_BUFFER will do the trick.
Don't let the name fool you, GL_TEXTURE_BUFFER can hold arbitrary data, not just texture data.
Uniform block is backed by https://www.khronos.org/opengl/wiki/Uniform_Buffer_Object
For texture buffer, read out https://www.khronos.org/opengl/wiki/Buffer_Texture

OpenGL - How to show the occluded region of a sprite as a silhouette [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm making a 2D game with OpenGL, using textured quads to display 2D sprites. I'd like to create an effect whereby any character sprite that's partially hidden by a terrain sprite will have the occluded region visible as a solid-colored silhouette, as demonstrated by the pastoral scene in this image.
I'm really not sure how to achieve this. I'm guessing the solution will involve some trick with the fragment shader, but as for specifics I'm stumped. Can anyone point me in the right direction?
Here's what I've done in the past
Draw the world/terrain (everything you want the silhouette to show through)
Disable depth test
disable draw to depth buffer
Draw sprites in silhouette mode (a different shader or texture)
enable depth test
enable draw to depth buffer
draw sprites in normal mode
draw anything else that should go on top (like the HUD)
Explanation:
When you draw the first time (in silhouette mode) it will draw over everything, but not affect the depth buffer, so that when you draw the 2nd time you won't get z-fighting. When you draw the 2nd time, some of it will be behind the terrain, but where the silhouette has already been drawn.
You can do things like this using stenciling or depth buffering.
When rendering the wall make sure that it writes a different value to the stencil buffer than the background. Then render the cow twice, once passing the stencil test when not at the wall, and once otherwise. Use a different shader each time.

Million mesh programmatically? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a flat surface drawn with a single fullscreen GL_QUAD.
I want to deform this surface at each point specified by my GL_Texture2D, preferably through some kind of shader.
In my mind, black could correspond to flat and white could correspond to a hill.
I want to have about 4 million points on my terrain and update them at each step in my program.
How would I use a geometry shader to do this? Is a shader able to generate new veritices?
The simplest way would be to generate a large triangle strip grid, upload it to a VBO and draw it, using the vertex shader to alter just the up coordinate. The vertex shader can also generate normals from the heightmap (or supply a normal map), which then get passed to the fragment shader for lighting.
To avoid storing a huge amount of data for the vertices, use glVertexID to generate the vertex positions from scratch in the vertex shader. Don't bind any buffers, simply call glDrawArrays(GL_TRIANGLE_STRIP, 0, lots).
As GuyRT mentioned, a tessellation shader would be good too and allow you to vary the tessellation detail based on the camera's distance to the mesh. This would be more work though.