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

learn more… | top users | synonyms

5
votes
3answers
586 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
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 ...
1
vote
0answers
249 views

Full screen shader causes performance hit

I basically want to have a shader run that can do something like toon shading, or grayscale the whole screen, or radial lighting. To do this, I create a new bitmap each time the display resizes that ...
0
votes
1answer
146 views

How would I write a shader that supports 2 different texture coordinates?

Hi I am not very good with writing shaders. How would I make a shader that simply supports 2 texture coordinates so I can load up 2 different textures to be used at the same time but on different ...
0
votes
1answer
150 views

My blur gets ugly when radius too high

I have the following h and v blur: Horz texture tex; sampler2D s = sampler_state { texture = <tex>; }; int tWidth; int tHeight; float blurSize = 9.0; float4 ...
2
votes
2answers
1k views

My hlsl shader cannot unroll a loop?

I have this shader: texture tex; sampler2D s = sampler_state { texture = <tex>; }; int tWidth = 1; int tHeight = 1; int blurLength = 3; float4 ps_main(VS_OUTPUT ...
1
vote
1answer
649 views

how to modify shadow mapping in “3D Graphics with XNA Game Studio 4.0”? [closed]

So I've been following the tutorials from the book Sean James's "3D Graphics with XNA Game Studio 4.0", and have been doing fine until i reached the shadow mapping part. in this book it creates point ...
1
vote
1answer
900 views

Pixel Shader, YUV-RGB Conversion failing

I am tasked with playing back a video hthat comes in in a YUV format as an overlay in a larger game. I am not a specialist in Direct3d, so I am struggling. I managed to get a shader working and am ...
0
votes
2answers
682 views

How to make HLSL effect just for lighting without texture mapping?

I created an effect and just want to use lightning but in default effect that XNA create we should do texture mapping or the model appears 'RED', because of this lines of code in the effect file: ...
1
vote
3answers
570 views

Writing a shader once without using CG?

Is there a tool that can convert a fragment shader from hlsl to glsl or glsl to hlsl? I do not want to use cg since it is not able to work on mobile platforms. Is there a tool that can make it so I ...
0
votes
1answer
470 views

Sampler referencing in HLSL - Sampler parameter must come from a literal expression

The following method works fine when referencing a sampler in HLSL float3 P = lightScreenPos; sampler ShadowSampler = DPFrontShadowSampler; float depth; if (alpha >= 0.5f) { // Reference ...
1
vote
0answers
387 views

XNA HLSL: Skinned Model Deforming Wrong

I am creating a basic XNA recreation of Minecraft. My current problem is that my "Steve" model, which is skinned with an armature using vertex groups to deform, is showing up disfigured beyond all ...
2
votes
0answers
1k views

Why is my deferred lighting implementation so expensive?

I've implemented deferred lighting and I tried to put about 20-26 lights on the viewable space of my map, and it brings down the FPS from 61 to 28-31. It also makes my VGA temperature to go from 68°C ...
1
vote
1answer
835 views

2D Mask antialiasing in xna hlsl

I have two texture2d , one of these is a mask texture and have 2kind color and i use that for mask (filter) second texture2D something like float4 tex = tex2D(sprite, texCoord); float4 bitMask ...
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 ...
2
votes
1answer
618 views

Help understanding HLSL - newbie questions

Just starting out with HLSL, please bare with me :) There are times I'm a little confused by the syntax for instance in the pixel shader of an example I am following we have the following input and ...
1
vote
1answer
384 views

Write alpha channel into SurfaceFormat.Single rendertarget in XNA/HLSL

I need to initialize a rendertarget ('SurfaceFormat.Single' format) drawing sprites into it. I would like the alpha channel of the sprite to be written into the rendertarget, so that regardless of ...
4
votes
2answers
1k views

XNA 4.0 - Normal mapping shader - strange texture artifacts

I recently started using custom shader. Shader can do diffuse and specular lighting and normal mapping. But normal mapping is causing really ugly artifacts (some sort of pixeling noise) for textures ...
2
votes
1answer
351 views

Does the standard lighting equation ever allow objects to be brighter than their textures?

It occurred to me that the standard lighting setup you see in all the tutorials doesn't allow lights to actually make an object appear brighter than its texture. The light value is always clamped ...
2
votes
1answer
651 views

Adding VFACE semantic causes overlapping output semantics error

My pixel shader input is a follows struct VertexShaderOut { float4 Position : POSITION0; float2 TextureCoordinates : TEXCOORD0; float4 PositionClone : ...
2
votes
1answer
769 views

Omni-directional shadow mapping

What is a good/the best way to fill a cube map with depth values that are going to give me the least amount of trouble with floating point imprecision? To get up and running I'm just writing the raw ...
2
votes
1answer
519 views

Using SurfaceFormat.Single and HLSL for GPGPU with XNA

I'm trying to implement a so-called ping-pong technique in XNA; you basically have two RenderTarget2D A and B and at each iteration you use one as texture and the other as target - and vice versa - ...
1
vote
1answer
725 views

Need to combine a color, mask, and sprite layer in a shader

My task: to display a sprite using different team colors. I have a sprte graphic, part of which has to be displayed as a team color. The color isn't 'flat', i.e. it shades from brighter to darker. I ...
2
votes
1answer
367 views

How do you create a cbuffer or global variable that is gpu modifiable?

I'm implementing tonemapping in a pixel shader, for hdr lighting. The vertex shader outputs vertices with colors. I need to find the max color and save it in a global. However when I try and write ...
3
votes
1answer
3k views

SV_POSITION in pixel shader

What are the uses for SV_POSITION in the pixel shader? Previously this was the POSITION semantic and it wasn't readable in the pixel shader, but now that it is, what can it be used for? In an SM2 ...
4
votes
1answer
767 views

Bitwise operators in DX9 ps_2_0 shader

I've got the following code in a shader: // v & y are both uints nPixel = v; nPixel << 8; nPixel |= y; and this gives me the following error in compilation: shader.fx(80,10): error ...
0
votes
1answer
2k views

Changing the culling mode in the HLSL effect

I'm writing a cel-shading effect in HLSL and Direct3D 11, and I need to be able to flip the culling mode on the outline pass of the effect. I know you do this in XNA by setting CullMode to CW or CCW ...
2
votes
2answers
143 views

Distance to a sphere, in Screen Space

Is it possible to find the distance of a pixel to a rendered sphere, in screen space? All my naive solutions for just using the 2D screen distances are failing because of the warping that occurs ...
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 ...
2
votes
1answer
605 views

Can you store negative numbers with XNA HLSL?

I am trying to make a ripple effect with a HLSL shader, it works so far but I need to output negative numbers and that won't work for the calculations. Is there some way to do this with the ...
4
votes
2answers
364 views

Is it possible in HLSL to use bitfields?

I have in memory a representation of my 2d GameMap (think of a Scorched Earth like landscape). The map is made up of MapElements, a MapElement is made up of 64 bits defined like struct MapElement { ...
1
vote
1answer
1k views

Problem with HLSL :TextureCoordinate0 is missing

I'm trying to create a very simple game, and am working with HLSL. I got this error in my draw method: The current vertex declaration does not include all the elements required by the current ...
2
votes
3answers
5k views

Hue, saturation, brightness, contrast effect in hlsl

I am new to pixel shader, and I am trying to write a simple brightness, contrast, hue, saturation effect. I have written a shader for it but I doubt that my shader is not providing me correct result, ...
0
votes
1answer
753 views

CG/CGFX to GLSL

So, I'm making the painful move from my beloved XNA to OpenTK, and I'm stuck: Since I've got a LOT of existing shaders written in HLSL, NVidia's CG compiler seems like a natural way to minimize the ...
1
vote
1answer
142 views

How to mix effects together?

Lets say I have got terrain effect, contains multitexturing, light. Now water effect. It must be different, but must be also affected by light. Other one, player effect, must also be affected by ...
0
votes
2answers
224 views

DX11 - Weird shader behavior with and without branching

I have found problem in my shader code, which I dont´t know how to solve. I want to rewrite this code without "ifs" tmp = evaluate and result is 0 or 1 (nothing else) if (tmp == 1) val = X1; if (tmp ...
1
vote
1answer
533 views

Writing to multiple RenderTarget2D's from HLSL shader

I need to write to two render targets: one for colour and another for depth+normal (for post-processing). I have a problem, though. Both targets seem to be getting the value output by COLOR0, while ...
3
votes
1answer
1k views

*DX11, HLSL* - Colour as 4 floats or one UINT

With the DX11 pipeline, would it be much quicker for the vertex buffer to pass one single UINT with one byte per channel to the input assembler, as opposed to three floats? Then the vertex shader ...
2
votes
2answers
385 views

How would I create an HLSL effect like an animated “working” image?

I want to create the effect in the image in HLSL specifically get a block of pixels to move from a specified start point to an end point, so that it can go across the entire screen, but I don't have a ...
2
votes
1answer
944 views

Shader optimization - Cg/HLSL pseudo and via multiplication

HLSL/Cg do not allow texture fetching inside conditional blocks. To get around this I am first checking a variable and performing some computations, afterwards I set a float flag to 0.0 or 1.0, ...
3
votes
1answer
668 views

Shadow-mapping xna

I've been trying to implement shadows in my game and I've been following quite a few tutorials online, mainly Riemers, but I'm always getting the same 2 errors when I'm drawing my models and setting ...
2
votes
1answer
262 views

Shader and Custom Vertex Format Errors

I am creating an editor of sorts that allow you to create 3D voxel models. I just got started and have ran into a few errors. Here is what it is producing: I think the problem has to do with the ...
1
vote
2answers
194 views

How (if possible) would I change the BasicEffect Matrix mid draw

Say, for example, I have a list of enemies. Each enemy is a textured quad which is the stored in a singular shared VertexBuffer and IndexBuffer with the buffer usage set to BufferUsage.WriteOnly ...
4
votes
4answers
697 views

Enconding/Decoding bit value in Texture Alpha Channel

I am Rendering to a SurfaceFormat.Color. (R8G8B8A8) The alpha of this format has 8 bits and I want to be able to use those 8 bits as a bit field. For example, in one pass of my render, I want to save ...
2
votes
2answers
794 views

Is the output from D3DCompile specific to one GPU, or not?

In Direct3D 11 there is a two-stage shader compilation process; you first pass the HLSL source code into D3DCompile, which outputs a "blob" of bytecode. You then take this blob and call ...
3
votes
2answers
1k views

Why can't I get a bool packed and aligned into a D3D constant buffer?

Alright, I'm having a hard time getting a bool packed and aligned into a hlsl constant buffer and I'm not sure why. Here is the buffer in hlsl cbuffer MaterialBuffer : register(b1) { float3 ...
1
vote
1answer
272 views

screen coordinate not working with pixel values

I have a very simple effect file shown below. I am using this to draw 2D lines, however it is not behaving how I expected and I can't seem to get my head round why. If I draw a line that goes from ...
1
vote
1answer
592 views

Sampling from Normal Map and Diffuse Map in Pixel Shader

I'm having some issue changing a basic lighting shader to take a normal texture and a diffuse texture for a model and then using the normal texture for lighting. The code is very simple and i can't ...
2
votes
1answer
457 views

How can I export models from 3DX Max into XNA?

I am looking for a way to import my 3D models (including materials and shaders) from 3D Studio Max to XNA. For example, if I have a model with diffuse, bump, reflection textures and values (through ...
3
votes
1answer
2k views

Some assistance with selective 2D Bloom in XNA

I'm in need of some assistance, as I've been at this for 2 days now and have gotten almost nowhere. I'm trying to use the XNA Bloom sample's component to apply bloom only to my UI text. (The only ...