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

learn more… | top users | synonyms

1
vote
1answer
133 views

Texture the quad with different parts of texture

I have a 2D quad. Let say it's position is (5,10) and size is (7,11). I want to texture it with one texture, but using three different parts of it. I want to texture the part of quad from x = 5 to x ...
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 ...
2
votes
1answer
711 views

Low-level GPU code and Shader Compilation

Bear with me, because I will raise several questions at once. I still feel, though, that overall this can be treated as one question that may be answered succinctly. I recently dove into solidifying ...
4
votes
1answer
2k views

In HLSL pixel shader , why is SV_POSITION different to other semantics?

In my HLSL pixel shader, SV_POSITION seems to have different values to any other semantic I use. I don't understand why this is. Can you please explain it? For example, I am using a triangle with the ...
1
vote
1answer
218 views

Confusion on HLSL Samplers. Can I Set Samplers Inside Functions?

I'm trying to create a system where I can instance a quad to the screen, however I've run into a problem. Like I said, I'm trying to instance the quad, so I'm trying to use the same geometry several ...
1
vote
2answers
543 views

HLSL Pixel Shader that does palette swap

I have implemented a simple pixel shader which can replace a particular colour in a sprite with another colour. It looks something like this: sampler input : register(s0); float4 ...
1
vote
2answers
263 views

Doubling the DPI with a shader?

I'm developing a game where the map is generated with Perlin Noise, but on the CPU. I am generating some perlin noise onto a texture with a small size, and then I stretch it out to the whole screen to ...
5
votes
2answers
705 views

Rain drops on screen

I am trying to make simple rain drop effect on screen.Something like this http://fc00.deviantart.net/fs20/f/2007/302/5/6/Rain_drops_by_rockraikar.png My idea is to: Create small drop shaped normal ...
1
vote
0answers
552 views

Need help transforming DirectX 9 skybox hlsl shader to DirectX 11

I am in the middle of implementing a skybox to my game. I have been following this tutorial http://rbwhitaker.wikidot.com/skyboxes-2. I am using MonoGame as a framework and in order to support both ...
1
vote
1answer
229 views

XNA Shader Texture Memory

I was wondering about texture optimization in XNA 4.0. Will the the contentmanager send the texturedata to the GPU directly when the texture gets loaded or do I send the texture data to the GPU when ...
6
votes
1answer
588 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 ...
16
votes
2answers
4k 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 ...
2
votes
1answer
185 views

Why is my shadowmap all white?

I was trying out a shadowmap. But all my shadow is white. I think there is some problem with my homogeneous component. Can anybody help me? The rest of my code is written in xna Here is the hlsl code ...
1
vote
0answers
235 views

Outline Shader Effect for Orthogonal Geometry in XNA

I just recently started learning the art of shading, but I can't give an outline width to 2D, concave geometry when restrained to a single vertex/pixel shader technique (thanks to XNA). the shape I ...
0
votes
1answer
142 views

HLSL problem with divide by homogeneous component

When I try to divide my position.z by my position.w in HLSL I get as result always 1.0f or higher. Is this a common problem for some reason? When I divide my position.x or y by the w this works fine. ...
4
votes
1answer
687 views

Pass large array to pixel shader

I am trying to write a Pixelshader for a curve effect in Direct2d. A curve effect maps each color channel value to a different value by using a look up table. For this effect I would need to pass 3 ...
4
votes
1answer
312 views

A Quick HLSL Question (How to modify some HLSL code)

Thanks for wanting to help! I'm trying to create a circular, repeating ring (that moves outward) on a texture. I've achieved this, to a degree, with the following code: float distance = ...
0
votes
1answer
118 views

how to create texture for modelmesh?

Is there a possibiltiy to create a texture from a meshpart in xna. By getting a flat version of the mesh. So I can create a texture for it and edit that texture(via rendertarget)? I need to get the ...
1
vote
1answer
330 views

Heightmap in Shader not working

I'm trying to implement GPU-based geometry clipmapping and have problems to apply a simple heightmap to my terrain. For the heightmap I use a simple texture with the surface format "single". I've ...
0
votes
1answer
584 views

Shadows shimmer when camera moves

I've implemented shadow maps in my simple block engine as an exercise. I'm using one directional light and using the view volume to create the shadow matrices. I'm experiencing some problems with the ...
5
votes
1answer
471 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
3answers
659 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
255 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
148 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
153 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
668 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
987 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
702 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
595 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
510 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
402 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
869 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
652 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
411 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
385 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
707 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
811 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
546 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
821 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
389 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
855 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
146 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 ...