Questions tagged [hlsl]

HLSL(High Level Shader Language) is a proprietary shading language developed by Microsoft for use with the Microsoft Direct3D API

HLSL is a C-like language developed by Microsoft and it's used in Direct3D API to define shaders. HLSL is used by Direct3D 9, and is required by the unified shader model in Direct3D 10+.

HLSL can be used to define pixel shaders, vertex shaders, geometry shaders, compute shaders, tessellation shaders, raytracing shaders and mesh shaders. It is analogous to for OpenGL.

Vulkan SDK and DirectX Shader Compiler also supports compiling HLSL shaders into SPIR-V, enabling its use in Vulkan applications.

Resources

1642 questions
3
votes
1 answer

Texture2D Array as Render Target in HLSL Pixel Shader

Currently I need a couple of textures' worth of per-pixel data from my rendering pass (normals, depth and colour). Instead of running three passes with shaders that are essentially the same (WorldViewPos multiplication, etc.) but each outputting a…
Nick Udell
  • 2,420
  • 5
  • 44
  • 83
3
votes
0 answers

Float3 array values are different in compute shader than what I sent them to be as from C# script in unity?

So I am using a compute shader in unity to find groups of vertices that overlap (are the same as) other groups of vertices in a Vector3[]. I have a List < List < int > > called faces. Each List in the faces list is a group of indexes that points to…
SpicyMelon
  • 41
  • 1
  • 6
3
votes
1 answer

What is the difference between a constant buffer and a read only structured buffer?

I would like to know which resource type is the best to use in order to hold as many elements as possible for data that will be static and not change for the duration of a draw call. The only difference I can tell between a constant buffer and a…
mbl
  • 805
  • 11
  • 18
3
votes
1 answer

How do I set the value of a HLSL uniform variable with SlimDX?

I haven't been able to find the documentation for this, but it's probably pretty simple. I have a pixel shader which needs variables to be updated. The only thing I've come close with is the ConstantTable, but it's under Direct3D9 and not…
jnm2
  • 7,960
  • 5
  • 61
  • 99
3
votes
1 answer

Algorithm for struct/class data alignment and padding?

I can't seem to find any information on how to calculate padding within a struct or a class within C, C++. In HLSL there are data structures called "Constant Variables" and they are very much like C structs with #pragma pack (4) enabled. Here is a…
Sent1nel
  • 509
  • 1
  • 7
  • 21
3
votes
2 answers

How do you get the output of a HLSL computation?

I would basically like to screen capture a GPU result into a bitmap file using .NET. I would probably use XNA and my workflow would be something like: Call an effect with custom input data Have the effect run a per-pixel process Get the result from…
JoshNaro
  • 2,047
  • 2
  • 20
  • 40
3
votes
1 answer

In HLSL, how to set all values of array?

Is there a way to set all values of an array after initialization with a single line of code? For example, I can do this: int array[4] = { 1, 2, 3, 4 }. However, later on I cannot simply write: array = {4, 3, 2, 1}; to set the array to something…
Pink Wolf
  • 76
  • 1
  • 7
3
votes
2 answers

Loading and using an HLSL shader?

I've been looking everywhere and all I can find are tutorials on writing the shaders. None of them showed me how to incorporate them into my scene. So essentially: Given an hlsl shader, if I were to have a function called drawTexturedQuad() and I…
jmasterx
  • 52,639
  • 96
  • 311
  • 557
3
votes
2 answers

How to compile HLSL shaders with Vulkan?

I'm current learning Vulkan API, it's time to create pipeline, I chose HLSL because in the future I want to reuse shaders in DirectX and when I get an RTX GPU I intend to bring ray tracing, I'm new in HLSL, I wrote a simple vertex shader: float4…
Ives TI
  • 137
  • 2
  • 9
3
votes
1 answer

Direct3D 11 - HLSL - Get vertex-index ID

In Direct3D 11, I have a vertex that is used for multiple triangles. In other words, the same vertex is referenced by multiple indices. In my HLSL vertex shader, I want to know which INDEX is being processed. Is there a way to do this? Something…
3
votes
1 answer

EXECUTION ERROR #362: DEVICE_DRAW_POSITION_NOT_PRESENT

I am trying to draw a cube in DirectX. However, I am getting the following error message; D3D11 ERROR: ID3D11DeviceContext::DrawIndexed: Rasterization Unit is enabled (PixelShader is not NULL or Depth/Stencil test is enabled and RasterizedStream is…
yasar
  • 13,158
  • 28
  • 95
  • 160
3
votes
1 answer

DirectX 11 - Point light shadowing

I'm struggling to implement point light shadows using cube shadow maps in DirectX 11. I've searched around and there only really seems to be tutorials in OpenGL or earlier versions of DirectX. I've setup a shadow map texture using…
Jonathan
  • 91
  • 1
  • 8
3
votes
2 answers

Implementing a SpinLock in a HLSL DirectCompute shader

I try to implement a spin lock in a compute shader. But my implementation it doesn't seems to lock anything. Here is how I implement the spin lock: void LockAcquire() { uint Value = 1; [allow_uav_condition] while (Value) { …
fpiette
  • 11,983
  • 1
  • 24
  • 46
3
votes
1 answer

Why I can't use tex2D inside a loop in Unity ShaderLab?

I am trying to do something like while (currentLayerDepth < currentDepth) { currentUV -= step; currentDepth = tex2D(_HeightTex,currentUV).a; currentLayerDepth += eachLayer; } It logged a error Shader error in…
OtakuFitness
  • 542
  • 7
  • 20
3
votes
2 answers

DXR: How to identify the geometry instance of the bottom level AS inside the closest hit shader

I have multiple geometries (D3D12_RAYTRACING_GEOMETRY_DESC) inside of a single DXR bottom level acceleration structure (BLAS). How can I determine which of those was hit inside of a closest hit shader? The following HLSL intrinsics do something…
Felix Brüll
  • 367
  • 2
  • 13