The 2024 Developer Survey results are live! See the results

For all questions related to shaders, i.e. the programmable part of the GPU pipeline. For language-specific shader questions, see also the [glsl] and [hlsl] tags.

272 questions
Filter by
Sorted by
Tagged with
15 views

### Approximation/Trick for rendering wormholes as simple objects

Is there a know trick/approximation used to render a simple wormhole effect such as this one: https://www.shadertoy.com/view/4dccRr I was thinking of some formula given: An outer effect radius, Ro ...
• 101
31 views

### How to achieve smooth max of two coordinates in a shader

I am trying to achieve a border effect to a square tile on a xz plane. I am using max of coordinates x and z to achieve that. Here is my ShaderLab code: ...
1 vote
63 views

### Why does lv = fract(uv*2) result in grid like pattern?

Here is a shader in GLSL that visualizes the normalized pixel coordinates (from 0 to 1): ...
• 141
31 views

### How does this wormhole effect shader create a distortion?

Below is the code for a simple wormhole effect shader made in shadertoy.com. I understand everything else except: ...
• 141
1 vote
43 views

### How to create a more photorealistic ocean?

Photorealism has many elements. Take, for instance, the figure 1 below, a shot from Dune Part One movie. Figure 1 The process of production of a image such as this one, is laborious and involve more ...
• 111
1 vote
46 views

### Vertices are mapped to UV coordinates, but how does the shader access the UV data?

So in every mesh, the vertices can have UVs, and UVs are a way to store data for each vertex. Basically, at the time of rendering, when the shader runs, it's a way to check some arbitrary data for ...
• 141
30 views

### Rotating shader UV around camera position in world space

I have a tiled XZ world comprised of separate meshes. Additionally, I've implemented a water shader that draws patterns based on world space coordinates. Furthermore, I have a camera that can both ...
34 views

### How can I compute a rectangles outline using a unit square in the vertex shader?

I'm trying to draw the outline of a rectangle (8 x vertices, 24 x indices, counterclockwise winding) using a unit rectangle and normals, with the model matrix scaling the outline thickness in the ...
• 125
37 views

### Is there a way to force a closest hit shader?

I want to add a debug feature to my ray tracer (runs in both Vulkan and OptiX). For that, I'd like to switch all objects to use a specific closest hit shader. Can I do this? I have only found the ...
• 1,566
48 views

### Shader ported from shadertoy does not behave in the same way

I tried porting the main "Image" shader here this. My results are somewhat similar apart from the fact that "IRES" does not seem to behave in the same way as it does in Shadertoy. ...
• 101
148 views

### Average luminence and auto exposure algorithm not seeming to work properly

I've been working on adding HDR rendering, auto exposure, and tone-mapping to my rendering engine, following this blog post for doing auto exposure and it sequel as well as a few side resources for ...
62 views

### Pixilate/Quantize UV coordinates in world space?

The effect I'm trying to achieve is to have it so that the texture is pixilated/quantized, but the "grid," stays aligned to world coordinates even as the object with it's own UV coordinates ...
1 vote
35 views

### Why does my implementation of a sinusoidally time-varying color work so slowly?

I've been following TheCherno's OpenGL tutorials and I got to the point where I could render a square by using an index buffer. Now I wanted to vary the color of the square by using \frac{\sin(t) + ...
• 111
147 views

### What kind of code would it take to visualize just 1 3d gaussian in Godot?

I'm trying to create the simplest possible implementation of the gaussian visualization code from this paper in Godot, https://repo-sam.inria.fr/fungraph/3d-gaussian-splatting/ but I just don't even ...
• 103
102 views

### How do I tell what kind of shader an hlsl shader is by looking at the code?

How do I tell what kind of shader this is: https://github.com/aras-p/UnityGaussianSplatting/blob/main/package/Shaders/GaussianSplatting.hlsl Among these options: vs – vertex shader ps – pixel shader ...
• 103
141 views

### How to correctly handle rendering of ~600000, arbitrary colored 2D squares with WebGL?

Information I have to render a map, that is rendered as a 2d collection of squares of different color, separated by white lines horizontally and vertically. There may be ~600000 squares surrounded by ...
1 vote
78 views

### How to avoid declaring sampler outside of statement?

How can I avoid having to declare the sampler outside of the if statement in this shader code sample? ...
• 125
1 vote
74 views

### Need help understanding this simplification/optimization for a very basic GLSL shader

i'm currently following a tutorial on youtube to get started with computer graphics (shaders) and it contains the following GLSL code: ...
• 113
1 vote
183 views

### Conditionally sample from texture in shader

I'm building a little 2D graphics library in Rust/WGPU as a means to learn graphics programming. I want to draw an outline around a shape and specify the outline's color. All of my shapes have a ...
• 125
1 vote
756 views

### How to calculate ray-origin and ray-direction in vertex shader working universally for any projection and using interpolators for performance

I have been reading and watching many raymarching tutorials, but almost all of them are only working in the perspective projection. Almost all assume, that to calculate the ray direction, you just ...
• 111
57 views

### How to interpolate alpha from CURRENT_ALPHA to TARGET_ALPHA for each pixel in shader language? (Godot/GLSL)

I want to make "trails" of objects on my shader that appear and disappear gradually. I am getting pixels (for fragment shader) where objects are from uniform texture. Basically, I have my ...
• 373
1 vote
373 views

### is there an universal way to set a uniform?

so I'm working on a game engine. It's partially python and c++. One part that is currently a pain point is setting the uniforms for shaders. Currently I have to define a behavior for all 50+ methods ...
106 views

### How to scale down noise frequency?

I'm making a space game and so far what I have is a system to generate spheres with noise on them, making them planets. I make a sphere, create noise data, write that data to an image file, and then ...
• 11
1 vote
54 views

### Curved world effect shader for heterogeneous mesh faces

I have a voxel based game, similar to Minecraft and want to apply the "curved world effect" like described here. As I was using a per 1x1 face quad renderer, applying the effect went well, ...
• 113
219 views

### Relative coordinates -- cumulative sum

I have a vertex shader happily producing all the vertices I want for a 2D plot. Now I want to also render a plot of the same data, but each point relative to the previous one, like SVG Paths using <...
• 11
1 vote
50 views

### BlinnPhong sphere edges look worse than Phong. Am I doing it wrong? (code and pictures included)

First of all, I am completely new to this so please excuse me if this is a dumb question. I am following the book Real-Time 3D Rendering with DirectX and HLSL, for now implementing shaders in Nvidia ...
• 11
1 vote
202 views

### Having trouble rendering entire sphere

I'm working on a program where I need to draw spheres. The method I'm using is creating an octahedron And using tessellation shaders to subdivide it into a sphere, however there is a patch of the ...
• 11
160 views

### Rendering light balls: Where to do perspective calculations?

After rewatching Bisqwit's starfield renderer video, I've decided to try to rewrite the program in order to learn more about compute shaders and shader programming in general. My knowledge at this ...
• 109
500 views

### Raytracing in OpenGL or Vulkan?

I was looking at this glass ball rendering with an image inside of it (zoom out to see the glass ball), and noticed that it looks like they simulate the refraction of light as it crosses from inside ...
• 159
1 vote
41 views

### Query the size of an array of non-basic types using interface query in OpenGL

Consider the following code in an OpenGL shader: ...
• 113
1 vote
197 views

### Best way for rendering Voronoi diagram from Delaunay graph mesh

I have a set of points, which I triangulate to a Delaunay graph to make a mesh. Every mesh vertex has a unique colour, and I can render it without any problem. But I want Voronoi rendering to be ...
1 vote
26 views

### How can I see the whole shader's text content, with all the prepended code by Three.js, when using ShaderMaterial or RawShaderMaterial (r148)?

I know that Three.js prepends the shader text you provide with some code that includes definitions etc. I am not a big fan of "magic" and I would like to be able to see the final text ...
69 views

### Output to more than one canvas texture in processing with shader OpenGL

as the question suggests im looking to output to more than one canvas element in processing to speed up the calculations and limit shader draw calls. It has to be as simple as possible to be ...
1 vote
141 views

### Is there a good rule of thumb for the optimal / maximum number of instances to draw in a single call?

So let's say I want to draw a lot of textured quads to the framebuffer. In each shader invocation, I will bind an array of indicies, an array of positions, and an array of textures to index into. ...
• 179
1 vote
232 views

### What are the main concepts behind building the plasma effect with GSLS?

By the plasma effect I mean an animation that looks like this: I have seen some codes, like these https://www.shadertoy.com/view/Xst3zN https://www.shadertoy.com/view/4tdGWX and messed with the code ...
• 31
1 vote
36 views

### How to make elevated parts of a steep plane seem darker than the lower surface? [GLSL]

I made a plane in THREEjs using Mesh, PlaneGeometry and ShaderMaterial. It's a very simple/basic form. I applied a simple phormula to make the plain more steep. Now I'm trying to make the lower ...
• 111
1 vote
106 views

### What is the best way to display complex number "images"?

I may be getting some details wrong (e.g. colour space vs. colour model), so please bear with me: I want to represent "images" consisting of complex numbers i.e. for each "pixel" ...
1 vote
313 views

### Has general purpose GPU computing been used before compute shaders were available?

Today we have tools such as Nvidia's CUDA and OpenCL to perform general purpose computing on the GPU (GPGPU). Seeing that traditional shaders are specifically used for generating graphics by filling a ...
107 views

### How does swizzling works in ARB shaders?

I am trying to understand some shader code written in ARB. I am mostly using this to understand it. However the doc doesn't explain (or I missed it) how vector operands are transformed into scalars, ...
• 161
77 views

I have a projection calculation which maps points from 3D space to pixel (image) space, and I want to use it as instead of the standard MVP projections in a vertex shader. In the image below the lower ...
1 vote
213 views

### Rendering multiple camera transforms of the same geometry at once

Currently I have a basic (OpenGL 3.3) rendering scheme using a simple depth vertex shader to generate shadow maps for a scene. I don't care about having a large number of lights in the scene so it is ...
• 111
449 views

### Model matrix for batch renderer as uniform or vertex attribute?

Where should the model matrix be uploaded to the GPU in a batch renderer? All the tutorials I've ever seen use a uniform for this, but that's not with batch rendering. Since the uniform is only ...
• 125
96 views

### GLSL, Fragment Shader: How to separate functions (like noise, transform...) to reuse in different projects

I'm a total newbie to coding and recently got interested into generative art. This is my problem: I have to copy all of the functions I need (and there are a lot) in every single fragment file I'm ...
1 vote
945 views

Suppose that someone implemented rendering for a video game using entirely GPGPU apis, like compute shaders or CUDA. Would it be possible to achieve the same performance as standard graphics pipelines ...
• 113
360 views

### Unity - custom shadow from sun

due to some features in materials I need to create my own directional shadow map. Everything seems to work ok, until the moment where I compare depths. First I add camera component to directional ...
• 596
1 vote
292 views

### SSAO with reconstructed depths yields strip artifacts

I wrote an ssao algorithm with compute shaders and view-position-reconstruction from the depth buffer. It works great for objects near by but results in strip or banding artifacts for large planes ...
312 views

267 views

### Painter's algorithm test 2 and test 3?

TEST #2: Surface S is completely behind the overlapping surface relative to the viewing position. S1 is completely behind/inside the overlapping surface S2 How to check these conditions? i) Set the ...
• 211