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

learn more… | top users | synonyms

37
votes
6answers
15k views

What are the pros and cons of HLSL vs GLSL vs cg? [closed]

What are the pros / cons of the three?
36
votes
1answer
3k views

How AAA games use this texture in the tone-mapping shader?

I found that Battlefield 3 as well as Saint's Row the Third use this texture in their final tone-mapping stage. Can anyone share a link to an article about how this texture is used? UPDATE: As ...
20
votes
2answers
4k views

How do I create a wide-angle / fisheye lens with HLSL?

What are the concepts that need to be implemented in order to achieve the effect of a wide angle lens of varying extremities? Pseudocode and specific explanation referring to the various stages of ...
20
votes
2answers
1k views

Weird white outline around model

I'm working on a game in XNA 4 and I recently switched to a deferred shading implementation following this guide. A strange white outline is showing up on my models now and I'm not sure whats causing ...
18
votes
12answers
6k views

What are some good resources for learning HLSL?

The last time I tried learning HLSL, I made a few shaders and mostly understood what I was doing, but I still felt like I was stumbling in the dark. Most of what I learned I got from various blog ...
18
votes
3answers
2k views

How can I create a lighting effect like this?

This is the most beautiful 2d lighting I have ever seen, and I'd like to perform lighting like this too. How do I do it? I don't care about the physics or how the particles are simulated - I only ...
16
votes
7answers
895 views

Spawning units in a world made by Perlin noise?

There's some issues that I've come across in my Perlin noise-based game. Take a look at the attached screenshot below. The white areas you see are walls, and the black areas are walkable. The ...
15
votes
2answers
3k views

Best way to mask 2D sprites in XNA?

I currently am trying to mask some sprites. Rather than explaining it in words, I've made up some example pictures: The area to mask (in white) Now, the red sprite that needs to be cropped. The ...
14
votes
4answers
3k views

how does HDR work?

I'm trying to understand what HDR is and how it works. I understand the basic concepts and have an slight idea of how it is implemented with D3D/hlsl. However it's still pretty foggy. Say I'm ...
14
votes
1answer
582 views

Rendering oily/polluted water?

Any shader wizards out there have an idea of how to achieve an oily/polluted water effect, similar to this: Ideally, the water would not be uniformly oily, but instead the oil could be generated ...
14
votes
6answers
3k views

Modern Shader Book?

I'm interested in learning about Shaders: What are they, when/for what would I use them, and how to use them. (Specifically I'm interested in Water and Bloom effects, but I know close to 0 about ...
12
votes
3answers
1k views

HLSL Translucent Plastic Shader

I'm trying to produce a shader to replicate a white plastic object with a colored light inside. Either by having a shader that will be translucent and if I put a light inside the object the light will ...
12
votes
1answer
268 views

Accounting for waves when doing planar reflections

I've been studying Nvidia's examples from the SDK, in particular the Island11 project and I've found something curious about a piece of HLSL code which corrects the reflections up and down depending ...
11
votes
4answers
1k views

How does an HLSL shader actually end up affecting the render output?

I understand the syntax of HLSL, for example let's pretend I have this as my HLSL: struct VOut { float4 position : SV_POSITION; float4 color : COLOR; }; VOut VShader(float4 position : ...
9
votes
4answers
1k views

Avoid if statements in DirectX 10 shaders?

I have heard that if statements should be avoid in shaders, because both parts of the statements will be execute, and than the wrong will be dropped (which harms the performance). It's still a ...
9
votes
2answers
4k views

Random number hlsl

How do you generate a random number in HLSL? I'm asking because I want to try gpu ray tracing. You need to generate random directions in a pixel shader. So I want randFloat(), where the result is a ...
9
votes
1answer
6k views

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

Alright, I'm having a hard time grasping how constant buffers are bound to a pipeline stage and updated. I understand that DirectX11 can have up to 15 shader-constant buffers per stage and each buffer ...
9
votes
3answers
638 views

How can I create a glitter effect?

I am trying to create a glittering effect for my realtime shader but I don't know how. Here is one example, and another example. What technique can I use to implement this?
9
votes
1answer
3k views

Wave ripple effect?

I've been working on a tower-defense game for some time now, and so far I am really satisfied with the results. However, there's one thing I'd like to add. I've seen a video of GeoDefense for Windows ...
8
votes
3answers
1k views

Very slow direct3D texture sampling

So I'm writing a small game using Direct3D 9 and I'm using multitexturing for the terrain. All I'm doing is sampling 3 textures and a blend map and getting the overall color from the three textures ...
8
votes
1answer
285 views

Fast lighting with multiple lights

How can I implement fast lighting with multiple lights? I don't want to restrain the player, he can place an unlimited number and possibly overlapping (point) lights into the level. The problem is ...
8
votes
1answer
493 views

2D Water top surface profile

I am trying to create the effect of the water surface thickness with a vertex-fragment shader. I am in a 3D game environment but It's a scroll view so a "2D" view. Here is a good tutorial of creating ...
7
votes
4answers
478 views

What types of effects or shaders would you teach in a rendering class? [closed]

I am looking for a list of topics that would be fun to learn and not too complicated to implement with a prototyping tool like FX Composer or Rendermonkey for an intermediate class of real-time ...
7
votes
2answers
1k views

HLSL - Creating Shadows in 2D

The way that I create shadows is by the following technique: http://www.catalinzima.com/2010/07/my-technique-for-the-shader-based-dynamic-2d-shadows/ But I have questions to HLSL. The way that I ...
7
votes
3answers
2k views

Rotating a vector by another vector in shader

I have a terrain surface with a normal for each point on the terrain. I have a second detail normal map to be applied to the terrain. These normals are in 3-space. The Y value of both normals is ...
6
votes
1answer
696 views

XNA HLSL - what happens if I grab a pixel outside a texture?

I'm using the tex2D function of HLSL, and I am wondering what will happen if I try to grab a pixel from a pixel coordinate outside of my texture (as an example 1.1). Will it clamp? Will it repeat the ...
6
votes
4answers
2k views

HLSL: Using instance float input to select texture index, possible?

I'm writing a game for the xbox360 using XNA. I would like to draw several models with a single DrawInstancedPrimitives call. Each model will use a different texture. To do this, I would like to ...
6
votes
1answer
406 views

Changing water color based on depth

I'm looking to make a water shader that colors the water based on its depth. Up until now my water shader that I've used has basically been extremely reflective and only looked somewhat blue because ...
6
votes
2answers
800 views

Rendering collections of light sources

I have a small test environment where small point lights are scattered. Players should able to collect them. The collectible lights are rendered using a simple billboard technique where two triangles ...
6
votes
2answers
1k views

Electricity effect using XNA and Shaders

I'm looking for a shader or sample that does an electricity or lines-of-force effect between two points that can be used with XNA 3.1.
6
votes
2answers
344 views

Does it make sense to include an index for linelists?

Does it make sense to include an index by using DrawIndexedPrimitives, when using linelists performance wise? I could imagine it would be easy for the GPU to generate such indexes anyway.
6
votes
1answer
528 views

Do I need to rewrite my HLSL shaders when porting from XNA to MonoGame?

I'm looking at porting an XNA project I have to monogame, but I have a fair number of HLSL shaders. It seems that Monogame for PC uses OpenGL as the rendering backend, and I'd rather not have to ...
6
votes
1answer
109 views

Tessellation vs Geometry Shader

Correct me if I'm wrong, but both the Geometry Shader and the Tessellation Shader jobs are to generate vertices in the Graphic Pipeline. What I would like to know is how they are different and when ...
6
votes
1answer
541 views

Partial Shader Signatures HLSL D3D11 C++

I had been debugging a problem I was having in a single shader file with 2 functions in it. I'm using DirectX 11, vs_5_0 and ps_5_0. I have stripped it down to its basic components to understand what ...
6
votes
1answer
152 views

XNA Deferred + Forward, Depth Problem?

Im working with my deferred engine in XNA 4.0 and Im combining it with a forwardpipeline to support semi-transparency and other "forward only" effects. Let me describe what I do: Render GBuffer ...
5
votes
2answers
899 views

Different number of lights => different shader

I have a shader that computes lighting for each light. PointLight PointLights[10]; uniform const float NumPointLights; for(int i = 0; i < NumPointLights; i++) { lightVec = ...
5
votes
3answers
581 views

Finding out what pixel on the screen the fragment falls on

In my 2D game, I render tiles. I want to do lighting without needing an extra buffer the size of the screen. Either in glsl or hlsl, what could I feed to the shader each time I render a bitmap so ...
5
votes
1answer
1k views

What does ddx (hlsl) actually do?

I'm a bit confused. The official documentation (http://msdn.microsoft.com/en-us/library/windows/desktop/bb509588(v=vs.85).aspx) says that ddx(input) is the partial derivative of the input with ...
5
votes
1answer
402 views

HLSL Circle all white

I have been trying to get my shader code (HLSL) to draw a simple circle but after a day and a half I am getting nowhere. It seems people are using the x^2 + y^2 = r^2 and remap texcoords but I only ...
5
votes
1answer
240 views

What light attenuation function does UDK use?

I'm a big fan of the light attenuation in UDK. Traditionally I've always used the constant-linear-quadratic falloff function to control how "soft" the falloff is, which gives three values to play ...
5
votes
1answer
368 views

What does HLSL's tex2D return at (0,0)?

I'm trying to understand the mapping of texels to pixels, especially in the context of pixel shaders. I already found out the following: When I define a standard quad with vertices at integer ...
5
votes
2answers
595 views

What range of values can HLSL's tex2D function return?

When using the tex2d function in a HLSL shader, as so: float height = tex2D(heightMap, IN.texCoord).r; What range of values can be returned to the height variable? Is it always a number between ...
5
votes
1answer
2k views

How do I use screen-space derivatives to antialias a parametric shape in a pixel shader?

In Valve's Alpha Tested Magnification paper, it mentions using "per-pixel screen-space derivatives" for doing anti-aliasing. My understanding is that this is the ddx and ddy intrinsic functions in ...
5
votes
2answers
656 views

Spin/Rotational Blur

How do I perform a circular/rotational/spin blur on an image - using DirectX9.0 and HLSL? For example:
5
votes
1answer
692 views

Perlin noise - copying the algorithm on the CPU?

I have successfully made a Perlin noise algorithm on the GPU. It works as expected, and generates great results. Now, as part of the physics calculations in my game, I need to replicate the exact same ...
5
votes
1answer
453 views

Dealing with alpha for 2D per pixel lighting

Right now I've got a simple light shader. Every bitmap I draw goes through it to make up the scene. I only draw quads. texture tex; sampler2D s = sampler_state { texture = <tex>; ...
5
votes
1answer
211 views

HLSL - Voxel texturing

I'm currently trying to develop a Voxel Engine using Direct3D 9 and C++. To keep the memory usage low, i'm only passing the position, the orientation and the offset of the current voxels texture in ...
4
votes
3answers
3k views

Inverting matrix in HLSL

I've got an object in HLSL and I'm using hardware instancing to render multiple copies. But I've come a bit of a cropper when it comes to the vertex normals. Currently I am not using normal mapping ...
4
votes
1answer
403 views

What happens to data between vertex shader and pixel shader?

Short version: What can happen to the output of a vertex shader that leads to no(or very few) pixels being drawn, especially in relation to a perspective matrix. Long version: My problem refers to ...
4
votes
3answers
2k views

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 ...