Tagged Questions
1
vote
1answer
69 views
Passing multiple colors to a pixel shader in DirectX
I have a pixel shader that sets the output color based on the interaction of an input texture, sort of like:
if (case1)
{
output.Color = float4(0, 0, 0, 0);
}
else if (case2)
{
output.Color = ...
2
votes
2answers
170 views
Why does matrix multiplication lead to different result if it's done on CPU, compared to GPU(shader)?
If I'm calculating a "camera space" on the CPU, by multiplying the view with the projection matrix on the CPU , and afterwards multiplying the world to the result my vertices do not pass to the pixel ...
4
votes
1answer
197 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
1answer
186 views
Applying an outline effect to primitives
I am trying to draw an outline on a collection of quads in Direct3D. I have three intersecting quads on the same plane in the following configuration:
(The different colors here are just to ...
3
votes
1answer
181 views
Per Instance Textures, and Vertex And Pixel Shaders?
How do you implement per instance textures, vertex shaders, and pixel shaders?
Given:
1. Two different model templates in Vertex Buffer, Square & Triangle
2. Instance Buffer with [n] instances of ...
2
votes
1answer
84 views
Direct3D shader compilation fails with constant buffers
I've been particularly annoyed by a 'bug' for a couple days involving D3DCompile and vertex shaders with constant buffers. I'm assuming the bug is my fault (missing flag or small nuance of the poorly ...
2
votes
1answer
83 views
Nine Patch Images in DirectX
In Android development I found nine patch images very useful to draw images that have a fixed border. When the image is scaled the inner part scales, but the border stays at a fixed size.
I was ...
1
vote
2answers
129 views
Diffuse light direction
I'm learning a tutorial from Rastertek about diffuse light with DX 11, here's the shader code:
float4 LightPixelShader(PixelInputType input) : SV_TARGET
{
float4 textureColor;
float3 ...
3
votes
1answer
164 views
Why are some objects not rendering properly?
Here's a button I exported from Blender into a .x format:
Now here it is in the game with BasicEffect applied to everything:
And now with my custom shader:
And there's the problem. While the ...
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
496 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 ...
3
votes
1answer
502 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 ...
0
votes
1answer
115 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 ...
1
vote
1answer
1k 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
375 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 ...
2
votes
2answers
125 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 ...
2
votes
2answers
609 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
230 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
373 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
2answers
415 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 ...
4
votes
3answers
1k 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 ...
1
vote
1answer
650 views
downsampling algorithm
what are the steps to perform downsampling on a texture ?
I've got as far as rendering the scene to a render target, but I'm not sure as to how to then render that to a smaller texture in order to ...
11
votes
4answers
960 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 : ...
4
votes
3answers
2k 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 ...
6
votes
2answers
292 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.
3
votes
1answer
145 views
Instancing with empty data, or varying vertex counts?
I am new to game development, having only developed a few games before, in 2D space, but with 3D rendering.
I have implemented instancing before, but this is only my 2nd time doing it. I have a ...
1
vote
1answer
236 views
HLSL weird matrix behaviour
I have some problems using an int 3x3 matrix as the convolution filter to do edge detection. (I know int matrices are not very meaningful since there is only float on the gpu)
Here is the code:
...
7
votes
4answers
427 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 ...
2
votes
2answers
595 views
Compatibility between DirectX 9 and DirectX 10 shaders
I am a beginner to game development and as I am used to programming in C# I decided to go for XNA. I've been playing around with it for a while and now I am learning the basics of HLSL shaders, I have ...
13
votes
6answers
2k 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 ...
8
votes
3answers
846 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 ...

