Skip to main content
30 votes
Accepted

What are screen space derivatives and when would I use them?

First, it helps to know that GPUs always evaluate fragment/pixel shaders on 2x2 blocks of pixels at a time. (Even if only some of those pixels ultimately need to be drawn, while others are outside the ...
DMGregory's user avatar
  • 135k
17 votes
Accepted

How to create a spiral brightness gradient

It looks to me like you want something like this: ...
DMGregory's user avatar
  • 135k
8 votes
Accepted

How can I mark a pixel in the stencil buffer?

There are two ways to set the stencil buffer value in Direct3D 11, one of which is only available in Direct3D 11.3 (and Direct3D 12). I will split this answer into two parts accordingly. Direct3D 11 ...
ssell's user avatar
  • 196
8 votes
Accepted

Why does Unity use HLSL instead of GLSL?

As far as I know, Unity uses Cg (which is deprecated by NVIDIA since 2012, I have no idea why they still use it) as its shader language (which is really similar to HLSL) instead of HLSL or GLSL as ...
Greffin28's user avatar
  • 989
7 votes
Accepted

How does the following code generate a full screen quad?

it doesn't generate a quad, instead it generates a fullscreen triangle. The outputs end up as: ...
ratchet freak's user avatar
6 votes
Accepted

Need an example of a HLSL Compute Shader

There's little point in converting your example to DirectCompute. It has no need to share data between pixels, so you are actually much better off doing a global tone-map operator in a Pixel Shader. ...
Chuck Walbourn's user avatar
5 votes

How to force XNA to render model very far away as a light dot?

Problem is two-fold: Determine how many pixels the model will take when rendered Replace model with a dot Suggestions: Pick the cut-off distance by eye. So when the model is this big and this far - ...
Kromster's user avatar
  • 10.7k
5 votes
Accepted

Determine the z coordinate of a deformed plane based on uv (xy) coordinates

Your image can be interpreted a couple different ways so I will make a few assumptions up front: The "geometry" you are emulating is meant to look as if it has already been "projected" (if it was ...
Cobertos's user avatar
  • 1,644
5 votes
Accepted

Is there an HLSL equivalent to GLSL's "map" function?

Answer with best guess of what map could be Based on the link you posted, map should be provided by you and it should return the distance of the provided 3d ...
Bálint's user avatar
  • 14.9k
5 votes
Accepted

How can I roll up a plane with a vertex shader?

Here I'm going to assume your geometry is set up like so: It's a ribbon of quads extending from z = 0 to z = end The z = 0 line will be the outer lip of the roll, and z = end will be the part tucked ...
DMGregory's user avatar
  • 135k
4 votes
Accepted

HLSL texture sampler always returns white

The problem is this: the compiler optimizes the effect file. So in your code only ONE sampler is created. However in reality you are using TWO textures. The first one, being the Texture provided as ...
Felsir's user avatar
  • 4,067
4 votes

Special Texture Stretching without deformation

So, essentially what you're looking for is 9 Slice Scaling. However that's only good for stretching out a texture so the edges and corners remain undeformed (sort of). The corners are 1:1 in both ...
Draco18s no longer trusts SE's user avatar
4 votes
Accepted

HLSL MipMap sampling in pixel shader

Sample calculates the mip level to sample based on screen space derivatives of the texture coordinates provided. Derivatives of texture coordinates can be computed as follows: ...
János Turánszki's user avatar
4 votes

2D Blizzard/Snowstorm Effect

Making Snow by particle system as you mentioned in your question you need some noisy windblown. particle system have part that called noise that you can moving your particles based on noise. 2D Snow ...
Seyed Morteza Kamali's user avatar
4 votes

How to create a spiral brightness gradient

You can analytically generate the same shader effect. This isn't unity or HLSL code, but you should be able to translate this easily to HLSL, plus it runs in shader toy and you can play around with ...
Krupip's user avatar
  • 1,763
4 votes
Accepted

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

This problem is often solved through the use of a transpiler, a program that can translate a shader written in one language into another. HLSL2GLSL is one such example that was used in Unity up until ...
DMGregory's user avatar
  • 135k
4 votes
Accepted

Shader to give the effect of a 2D character covered in oil

I'd like to propose taking some inspiration from the 3D graphics / PBR world. From that perspective, the problem here is that your sprite image combines into a single color value, two different ...
Kevin Reid's user avatar
  • 5,498
3 votes
Accepted

HLSL Function Problem

If you use the latest version of Effects 11 using D3DX11CompileEffectFromFile, in the Debug configuration it dumps all the HLSL compiler error/warning output to the ...
Chuck Walbourn's user avatar
3 votes
Accepted

How do multiple shaders in a DirectX Engine work?

Might be misunderstanding your question but from the screenshot, it looks like you have a common library of functions to use with your three different shaders: BasicEffect [VS, PS] Brdf [VS, PS] ...
Haywire Spark's user avatar
3 votes

DirectX11, how do I manage and update multiple shader constant buffers?

There seems to be a lot of confusion around the topic of needing to re-bind constant buffers after updating them. As I'm learning about this myself I have seen a lot of topics and discussions with ...
octo's user avatar
  • 31
3 votes
Accepted

Passing Matrix to shader

Yes, there is no way to pass a float4x4 to an input description. By doing that you'd be passing a matrix for every vertex to your vertex shader. This is bad practice unless you need to bind a ...
Honeybunch's user avatar
  • 1,383
3 votes

Identify shading language in Trove

I can't comment since I don't have enough rep yet. As UnholySheep said in the comments to your question, looking at the .common files you can find out that this is indeed a custom shader language. ...
RelicBloodvayne's user avatar
3 votes
Accepted

Single pass separable gaussian blur problem

I'm not an expert in compute shaders, but it looks like the memory barriers you're using there say: "Ensure all current writes in progress finish before proceeding to the next step" ...while I ...
DMGregory's user avatar
  • 135k
3 votes
Accepted

Why do these DirectXMath functions seem like they return column-major matrics?

You posted a column-major version of the translation matrix for (1,1,-1): 1.0 0.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 0.0 1.0 -1.0 0.0 0.0 0.0 1.0 ...
Chuck Walbourn's user avatar
3 votes

What does declaring a const float within a function do? (CGFX)

A const value is never changed after it is initialized. By declaring a const the compiler can do certain optimizations, like calculating the const value at compile time instead of at runtime and ...
Fuzzy Logic's user avatar
  • 1,758
3 votes

Sampled texture from bitmap font produces blue glow

So in true programmer fashion, I solved the issue after being frustrated with it forever. BITMAPINFO stores in ARGB format, not RGBA like I was expected. The solution is just changing the alpha ...
Kyle Elliott's user avatar
3 votes
Accepted

Constant Buffer Alignment issues

Review the HLSL cbuffer packing rules here: https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-packing-rules HLSL packing rules are similar to performing a #pragma pack 4 ...
Maximus Minimus's user avatar
3 votes
Accepted

Sending light data from Vertex Shader to Pixel Shader?

It's valid, but you have a limited number of interpolators between the two shader stages, and depending how much data you're sending you may bump into that limit. You'll almost certainly need to split ...
Maximus Minimus's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible