Questions tagged [hlsl]
A proprietary shading language developed by Microsoft for use with the Microsoft Direct3D API.
649
questions
0
votes
0
answers
9
views
Can you append values to an appendbuffer and then immediately read from that same buffer?
I am looking to achieve the following: I have a compute shader that receives a Texture2D as input, where a small percentage of the pixels in the texture are white. The location of the white pixels are ...
0
votes
0
answers
29
views
Specular lighting does not appear
I'm struggling to add specular lighting on-top of diffuse lighting and not entirely sure where I'm going wrong. I've followed the instructions given in our lecture but it just doesn't seem to be ...
2
votes
0
answers
50
views
Simple shader to draw lights on a skyscraper
I have some basic shapes in the background of a scene that represent a small city. There is a stage where the scene becomes a nights scene. I would like to have the city come to life at night with ...
3
votes
1
answer
105
views
How would I generate mipmaps for a 3D texture in Unity (at runtime)?
I have been trying to create a voxel cone tracer for Unity (in Universal Render Pipeline 16).
I have this (unoptimized) C# code that turns the [CubeScale] area around 0,0,0 of the scene into a 3D ...
0
votes
0
answers
14
views
Finding highest point on displacement map returns bizarre results
I find the highest point of a displacement map sampled at 9 different UV coordinates that i pass in an array to the shader. Then if the result is more than 0.7 I output a red pixel at every UV ...
0
votes
0
answers
36
views
Convolution matrix based minimum distance calculation
I want to detect the minimum distance to each game object within a convolution matrix in a compute shader.
I know the code is a bit to read, but the logic itself is not too complicated. I am trying to ...
0
votes
1
answer
80
views
How to use gather offsets
I have this situation where I have parts of the same scene in each 4 half squares of a rendertarget rendered with the same view projection matrices. In my deferred pipeline I would like to sample with ...
0
votes
0
answers
20
views
Trouble trying to use multiple rendertargetviews and viewports at the same time
I have worked on the GSCubemap demo for DX11 to obtain rendering to multiple rendertargets and modified it to render to a single RTV with multiple viewports with SV_ViewportArrayIndex. I'm now trying ...
0
votes
1
answer
173
views
Iterating through every pixel in a shader - skipping pixels
I made the below shader to draw a mesh for every pixel on a texture, and color it with that pixel.
It iterates through the pixels, correctly drawing and coloring the mesh instances. However it skips ...
1
vote
1
answer
465
views
How to support Texture Tiling + Offset for custom shader
I've written a custom shader (with help) and I'm not sure why it does not have tiling & offset capabilities. What is the simplest way to add that feature to my shader?
current shader code
...
0
votes
2
answers
93
views
How to use unconventional texture format
I would like to use a texture that could have more than 4 channels.
I have seen a post where they use a single channel R8 texture to store string chars.
I'm thinking of using something like that with ...
0
votes
0
answers
92
views
How to calculate the world position of pixels in an HLSL script?
I want to make a simple ray marching loop in the fragment shader. I think the main issue is that I'm not giving the correct world position input.
Here is my current attempt:
...
0
votes
1
answer
32
views
Weird result whe nusing OMSetRenderTargetsAndUnorderedAccessViews
My render pass consist in four passes.
3 first have 2 rendertargets and two unordered access view.
RTV0 = RG88 //store normal.xy
RTV1 = R32 //store depth
UAV0 = R32UINT //store color1
UAV1 = R32UINT//...
0
votes
1
answer
71
views
Screen position in Deferred Shading
I am trying to implement a program in Direct3D 11 which uses techniques like deferred shading and shadowmapping, but when I create my gBuffers, the position looks strange. After researching a bit I ...
0
votes
0
answers
37
views
using texture as variable
I was trying to use a texture as a variable in my shader (DX11 VS/PS 5.0). Can't get it.
I have recently find this piece of code here where a texture is passed as a function parameter.
Is that ...
0
votes
1
answer
114
views
Noise in compute shader related to threadsPerGroup
I have been working on a metaball compute shader for roughly 3 months now, and the only issue I have to resolve is noise in the output Dest[id.xy]. I also asked GPT 4 about the crux of the issue and ...
0
votes
2
answers
209
views
How to convert from object space to clip space
I want to animate foliage with vertex animation but I have wrong output because I can't correctrly transform from object space to clip space, and my foliage goes off the model. How Can I convert in ...
0
votes
0
answers
124
views
How to deform mesh's actual vertices, based on shader waves code?
I am using a shader that is applying a visual deformation that looks like Gerstner waves.
It works great, but I need the mesh's actual vertices to deform based on these formulas as well.
How can this ...
1
vote
2
answers
287
views
Pack 4 textures into one channel
Can I pack 4 grayscale textures into one channel by converting the textures into uints and packing them?
...
1
vote
1
answer
176
views
D3D11 ERROR ("invalid arguments") from HLSL shader
I am using MonoGame 3.8.1.303 with Windows/DirectX.
I am just rendering a TriangleList using DrawIndexedPrimitives, but I am ...
0
votes
1
answer
177
views
Putting two R16_UNORM in a R32_UINT
With my hardware limitation for CS5 I'm using R32_UINT in my shaders to store compacted colors and normasl as 555 bits each. My packing is using uint3 and the result is of poor quality.
I'm planning ...
0
votes
1
answer
95
views
Looking for an advice on how to possibly boost my compute shader
I have 4 rendertargets R10G10B10A2 each being used to store color and normal in a compact double RGB 555 bits format. When I'm doing the lighting pass I'm obliged to have extra rendertargets because ...
0
votes
1
answer
200
views
Reliably addressing compute buffer when using large numbers of threads
I'm trying to move a 262,144 [2^18] points (stars) in a compute shader and am struggling to reliably address the data in a buffer.
I understand that there's a 3-dimensional array ...
0
votes
1
answer
97
views
Problems with normal recovery from storage as two floats and normal from depth buffer
In my app I’m producing for my deferred shading 4 layers of data to show up occluded parts of the scene during screen space reflection (SSR) pass. I need normal maps with bumpiness of these layers for ...
0
votes
1
answer
291
views
error X4532 Cannot map expression to gs_5_0 instruction set
Using DX11 I have this line starting with TC = txDiffuse in a geometry shader that generates the error message. Can someone explain me the problem or if it is not possible to sample in geometry shader ...
0
votes
0
answers
159
views
How to add inverted hull outline to desired objects in HLSL?
I am currently trying to edit a Vertex Shader of a game and want to add inverted hull outlines to the desired objects, but there are a lot of tutorials on the inverted hull for Unity, Blender, and ...
0
votes
1
answer
631
views
Difficulties in converting RGBA to float and back
I can't get my colors back.
What I'm using to encode/decode:
...
0
votes
2
answers
128
views
Shadowmapping in view space
UV coordinates for shadow mapping are usually calculated from world position. I want to make it compliant with my screen space reflection (SSR) pipeline which works in view space.
Is it possible to ...
0
votes
2
answers
433
views
0
votes
0
answers
231
views
How do I make a shader that simulates acrylic paint being smeared on a surface?
I know something about shaders, I have written some very basic shaders. This is the most advanced shader I have written so far.
It's been several days since I conceived the idea of trying to recreate ...
0
votes
1
answer
431
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....
0
votes
1
answer
1k
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). ...
0
votes
1
answer
169
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
vote
1
answer
1k
views
How to add antialiasing to my circle shader?
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. ...
0
votes
1
answer
236
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:
...
0
votes
1
answer
1k
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.
...
5
votes
0
answers
205
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:
...
0
votes
1
answer
940
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:
...
2
votes
1
answer
214
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
...
0
votes
0
answers
107
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, ...
2
votes
0
answers
27
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 ...
0
votes
1
answer
109
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 ...
0
votes
0
answers
41
views
shader can't read data except position, texcoord, normal
i want to read bone's weight but shader can't read data
this is my vertex type
...
1
vote
0
answers
276
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 ...
1
vote
0
answers
77
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 ...
0
votes
0
answers
43
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 :
...
0
votes
0
answers
108
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:
...
0
votes
0
answers
358
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 ...
2
votes
2
answers
848
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 ...
0
votes
1
answer
217
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 ...