# Questions tagged [hlsl]

A proprietary shading language developed by Microsoft for use with the Microsoft Direct3D API.

622 questions
Filter by
Sorted by
Tagged with
1 vote
79 views

### How to calculate geometry term from "Multi-Scale Global Illumination in Quantum Break"?

In presentation "Multi-Scale Global Illumination in Quantum Break" from SIGGRAPH 2015, on slide 105, they present concept of geometry term, which is used to help with light leaks in volume ...
• 111
64 views

### 24bit float to RGB

There's solutions to convert float to RGBA but I would like to encode a float depth value in RGB format and save the three components in three separated unused alpha channels and recompose when needed....
• 37
92 views

### How do I cast a float4 to a float[4]?

I've a RGBA16F texturecube for 4 pointlights shadows rendered in one pass. Each color channel stores the object to light distance for one pointlight shadow (e.g red channel is for light 0 and so on). ...
• 37
36 views

### How do I offset a texture pointer in order to store an array of D3D11_SUBRESOURCE_DATA?

I'm attempting to load a sequence of frames from a GIF into a Texture2DArray using stbi_load_gif_from_memory which returns a ...
• 1,976
1 vote
184 views

I made a circle shader by following this tutorial: https://www.youtube.com/watch?v=Ww1GbfnBH_Q. It is simple flat circle shader. The problem is that there are visible jigged lines on the circle edges. ...
• 127
54 views

### Why can't I use the "degrees" character in HLSL comments?

I was in the process of creating a function in my compute shader that converts a 180° angle to a 360° CCW angle like this: ...
• 31
123 views

### How to modify the z depth value inside the vertex function of a surface shader?

I wrote the following surface shader. The idea is to increase the Z depth value of vertices, after projection. ...
• 3,132
30 views

### How to create good scratched film effect in UE4?

I am messing with 8mm old film effect post process for a while in unreal engine 4. I have set up the material, but the effect just looks so wrong. I have heard you can make scratched film effect with ...
102 views

### How inefficient is my ray-box-intersection algorithm?

One of the most critical parts of my raytracer is the calculation of a collision between ray-box which is done following way: ...
• 51
173 views

### Initializing a global variable array once for a shader without using CPU code to populate the array

I know I can initialize arrays via code written in C++, etc. to set arrays in a shader. What I want to know is if I can initialize the array in HLSL code instead. For example: ...
• 117
69 views

### How to generate a correct RGB + Luminance histogram?

I am trying to create a debug tool that would help me visualize an image RGB and luminance histogram. I have created a compute shader where I gather the histogram data ...
56 views

### ComputeBuffer Values messed up when calling the dispatch many times in a row

I'm having a RWStructuredBuffer called AffectedVertices give me random data instead of 1 simple value to resultAffectedVertices, ...
• 55
24 views

### Where is this quad pattern coming from? [duplicate]

I'm rendering a map generated from noise. For debugging purposes, I'm just using the normals as color. I'm not sure how good/correct my calculated normals are, either way, I'd expect a smooth colored ...
• 1,840
64 views

### Why are the rules for struct packing different for ConstantBuffer and StructuredBuffer?

For my Compute Shader, I got ...
• 13.2k
65 views

### What is wrong with my terrain lighting?

I've just implemented a simple algorithm to calculate terrain vertex normals and I'm using diffuse and ambient light currently, but for some reason the squares that make up my terrain are visible when ...
25 views

i want to read bone's weight but shader can't read data this is my vertex type ...
• 11
1 vote
95 views

### Generating Shader Includes via script at compile time

I'm experimenting with compute shaders in Unity. A pretty typical thing you wanna do is marshal a buffer of structs back and fourth between C# and HLSL land. Ordinarily you'd have to manually define ...
• 733
1 vote
49 views

### Faster Alternatives to Jacobi Pressure Solving in Navier Stokes Simulation

While Jacobi itself is quite simple it needs at least 10 iterations to produce acceptable results. However that results in a higher total time cost than the rest of the Navier Stokes Simulation ...
• 83
37 views

### Why my output image is not seamless?

I offset a region of an image but when I tried to restore it using same method it doesn't look right. here is my input and output: And this is the code I used to restore : ...
43 views

### In a shader, what is the meaning of l()?

For instance, l(2.000000) or l(1.000000, 1.000000, 1.000000, 1.000000). This is in HLSL. Example in use: ...
167 views

### Marching cube terrain generated by compute shader gives strange error

I'm creating my own terrain terrain system for Unity using marching cubes but I've run into a problem I'm stumped on. First I'll explain how it works: A compute shader creates an array of points ...
• 1
328 views

### How to evaluate a binary expression tree in HLSL without recursion or a stack?

I'm currently working on a dual contouring implementation for which I want to create procedural terrain based on layers of noise. Both, the terrain generation and the mesh creation via dual contouring ...
75 views

### How to synchronize reads and writes to a StructuredBuffer across warps in HLSL?

I'm currently trying to implement smooth voxel terrain (using dual contouring) with mesh generation happening on the GPU and I'm struggeling with chunked level of detail creation. My approach is as ...
94 views

### How to raycast octree for closest leaf node?

So I need to raycast a octree for closest leaf node as efficient as possible. I will be doing it on compute shader (hlsl), but I think it doesn't matter because first I need to understand the approach ...
60 views

### Moving the bulk of a recursive ray tracer function to the gpu, using DirectX12 not DirectX 12 DXR HLSL

So I'm wanting to generate images by ray tracing. I've done so, but the main ray function is recursive. I know one can make a non recursive function out of a recursive function using a stack, but is ...
• 479
1 vote
568 views

### How to sample a TextureCube texture

I'm converting old shader code to be a bit more modern. So far this works out great, but I'm having a though time figuring out how to convert shader code that works with cubic textures. In the old ...
• 10.2k
194 views

### Generate a 2D field-of-view cone

I have a bunch of randomly generated boids flying around on my screen, but I want a function that can give them a field-of-view where they can "see" other boids or obstacles. The code I ...
64 views

### How to include a FX shader to my game?

I have an old game source from 2004, the game runs DirectX9, and I want to improve the graphics. I downloaded NVIDIA FX Composer 2.5, and I created a “...
164 views

### Splitting up HLSL code into separate functions causes the number of needed temporary registers to increase

EDIT Per request I've provided a simple compute shader that reproduces the problem. The compute shader below is kind of a contrived example meant to compute the rolling average over an input ...
1 vote
157 views

### How to avoid banding with raymarched fog?

I have a raymarching shader for fog. It works well but It creates artifacts in the form of banding: I understand the problem: The step size is too large and the sample points above the ground are not ...
• 641
1 vote
401 views

### How to convert screen space to world space?

I have a shader that should do raymarching. But I have problems converting the fragment's position to a worldspace coordinate. This is my vertex shader: ...
• 641
88 views

### HLSL defined render states

As described in this article you can define render states such as ZFunc inside of the HLSL shader. You can also set these from application code. If you set the same state (e.g. ZFunc) in both ...
• 113
1k views

### How to write shaders that can be compiled for DirectX, OpenGL, and Vulkan

I recently finished writing the DirectX renderer for my game engine. Now I have an OpenGL, DirectX as well as a not yet finished Vulkan renderer. Well, the majority of the renderers work perfectly now ...
323 views

### HLSL Converting View Direction into Equiangular UVs

In Unity, I am attempting to create a custom skybox that use a single render texture to create a flat unmoving skybox (the render texture source will do it's own movement) and reflect off objects as ...
2k views

### How to create a spiral brightness gradient

I am stuck on creating a brightness gradient that looks as below(the values are continuous from the inner circle). What formulae can create such brightness gradient? So that when _Time is added to it, ...
• 253
104 views

### Is there a simpler way to simplify the if statement? [closed]

The code below generate angle and radius based brightness gradient. As you can see I need to use 3 if statement to define 3 circle, wonder is there a single code that can create nth circle ...
• 253
98 views

### Pass equations into shaders to define graphics - HLSL or other shaders

Is it possible with HLSL (or other popular shader languages) to pass instead of an image, an equation that would define the pixel color / position output by the shader? This would allow for more ...
180 views

• 253
134 views

### Peter Panning Depth Bias Problem

No matter how I experiment with RasterizerState Depth Values, I always get a detached shadow which is called peter panning. Ive even adjusted the near plane for the light camera. It always seems to ...
1 vote
60 views

### Rendering differences between ps_1_3 and ps_2_a

I am trying to update a shader from ps_1_3 inline assembly to ps_2_a HLSL. However the HLSL shader causes things to render ...
• 113
1 vote
92 views

### Setting an array in the HLSL shader

I have a array of six float4x4's in my shader. cbuffer pseudeocb { float4x4 Mypseudo[6]; }; I need to set these in my code. ...
1 vote
429 views

### Unity: Alpha and color issues with opaque projector/decal shader

I have been attempting to make a simple "overwrite" version of Unity's projector shader. I can either respect the color, or respect the transparency, but not both. I have simplified the ...
• 161
250 views

### Creating the Vertices and Triangle Indices for Voxel Generated Mesh

I am running into a problem with a compute shader I am writing to generate the vertices and triangle indices for a voxel generated mesh. Currently, I am creating an ...
• 121
170 views

### Floodfilling a texture in HLSL Compute shader

I have a very large texture which I want to fill with values representing "distance in units from a river tile". The texture is already seeded with these origin river points (meaning ...
• 1,386
351 views

### Hlsl Refract() not refracting rays correctly

I'm making a ray tracer in unity and I'm trying to model refraction, however when I use refract() in my shader it doesn't change the ray direction at all. here is a ...
75 views

### How do I store the texture coordinates for thousands of tiles in a tile mesh on the GPU and not just the most recent?

This is a follow-up to this question. The geometry shader is performing fantastically, but now I've lost the ability to display more than one tile type at once (the last one in the visible array is ...
• 1,976
209 views

### Geometry shader-generated tile mesh isn't any faster than CPU-generated version

For practice, I'm writing a Rogue-like. In order to speed up tile rendering I have a dynamic Mesh/MeshBuilder that collects all the vertices of the visible tiles' quads (4 vertices per tile: position, ...
• 1,976
64 views

### Geometry shader vertex position to point at camera

I have a shader that takes an array of points. At each point, a geometry shader creates a quad oriented towards the camera. This works fine when the camera and point are at around the same Y value, ...
• 610
1k views

### How to get neigbor pixel coordinates in Unity HLSL shader

I am writing Mandelbrot set shader for Unity. I wrote an Image Effect shader and it works. Unfortunately, each point "shimmers" on translate scale. This is because, for each shader call I ...
• 151