HLSL is a proprietary shading language developed by Microsoft for use with the Microsoft Direct3D API.
3
votes
2answers
172 views
Which will be faster? Switching shaders or ignore that some cases don't need full code?
I have two types of 2d objects:
In first case (for about 70% of objects), I need that code in the shader:
float2 texCoord = input.TexCoord + textureCoord.xy
But in the second case I have to use:
...
0
votes
0answers
96 views
How to efficiently render resizable GUI elements in DirectX?
I wonder what would be most efficient way to render the GUI elements.
When we're talking about constant-size elements (that can still be moving), the textures' atlas seems to be good.
But what with ...
1
vote
1answer
106 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
499 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 ...
1
vote
1answer
245 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 ...
1
vote
1answer
143 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
307 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
186 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 ...
1
vote
1answer
186 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 ...
1
vote
0answers
277 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 ...
2
votes
2answers
432 views
HLSL: how to get/set effectvariable to an array of structs with Direct3D10
HLSL Code:
//Lights
struct Light
{
float3 pos;
float3 dir;
int type;
} m_aLights[3];
How can I get/set an effectvariable to m_aLights with Direct3D10?
Thanks
5
votes
1answer
305 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 ...
0
votes
1answer
675 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 ...
13
votes
2answers
1k 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 ...
0
votes
1answer
105 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. ...
2
votes
1answer
132 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
173 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
104 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 ...
3
votes
1answer
257 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 ...
2
votes
1answer
180 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 ...
4
votes
1answer
245 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
214 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
1answer
242 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 ...
2
votes
2answers
327 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 ...
0
votes
1answer
336 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
424 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>;
...
15
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 ...
5
votes
3answers
315 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 ...
4
votes
1answer
738 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
198 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
117 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
113 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
515 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
542 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 ...
2
votes
2answers
417 views
How do I keep a triangle strip between geometry shader invocations?
I'm using a small geometry shader to build a "ribbon" from a set of points. For each point, I create 4 vertices that represent a section of the ribbon:
[maxvertexcount(4)]
void GS( point GS_Input ...
1
vote
3answers
283 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 ...
1
vote
0answers
254 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 ...
16
votes
11answers
3k 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 ...
6
votes
2answers
2k 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
414 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
243 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 ...
2
votes
1answer
225 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 ...
13
votes
4answers
2k 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 ...
2
votes
1answer
363 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
515 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
385 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 - ...
0
votes
0answers
166 views
What's a good way to organize samplers for HLSL?
According to MSDN, I can have 4096 samplers per context. That's a lot, considering there's only a handful of common sampler states.
That tempts me to initialize an array containing a whole bunch of ...
1
vote
1answer
430 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 ...
0
votes
2answers
205 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 ...

