Vertex Shader/Pixel Shader/SRV problem - Blank screen

Started by
3 comments, last by KieronH 9 years, 3 months ago

First thing's first, this is my very first post here so I'm not really sure of how things work here so bear with me a little! I don't normally resort to forums but I've been stuck with this for a few days now with no success and it's driving me up the wall!

Okay so basically what I'm attempting to do is read some values from an SRV in a vertex shader. I am doing this without setting a vertex buffer or input layout. So they are both null. The data is just an array of float4s that hold a position of a particle.

Here is my vertex and pixel shader:

cbuffer ConstantBuffer : register(b0)
{
matrix World;
matrix View;
matrix Projection;
}
//--------------------------------------------------------------------------------------
// Vertex Shader
//--------------------------------------------------------------------------------------
struct VS_INPUT
{
uint id : SV_VERTEXID;
};
struct PS_INPUT
{
float4 Pos : SV_POSITION;
float4 Col : COLOUR;
};
struct particles
{
float4 position : POSITION;
};
StructuredBuffer<particles> particlesIn : register(t0);
PS_INPUT VS(VS_INPUT input)
{
PS_INPUT output = (PS_INPUT)0;
uint index = input.id;
particles p = particlesIn[index];
output.Pos = mul(p.position, World);
output.Pos = mul(output.Pos, View);
output.Pos = mul(output.Pos, Projection);
output.Col = float4(1.0f, 1.0f, 1.0f, 1.0f);
return output;
}
//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------
float4 PS(PS_INPUT input) : SV_Target
{
return input.Col;
//return float4(1.0f, 1.0f, 0.0f, 1.0f);
}
Now here's the thing - I pass a value of (0.0f,0.0f,0.0f,0.0f) into this and I get a white point in the centre of the screen. This is the correct behaviour. However, if I change any one of the x,y or z values (by any value it can be as small as 0.000001f or even smaller) I get a blank screen with no point whatsoever. Now I thought it might be to do with some of the matrices that I'm using, but I have tested it out with another program and they are fine. At this point I'm out of ideas, I've tried all sorts to get it working, including using the graphics debugger to look through values that are being passed through the vertex shader. To my surprise they were actually correct! (I think?) What I have posted is just the shaders. If I need to post any other code for you to look at please let me know. I'm desperate for new ideas to take this forward!
Thanks in advance!
Advertisement


I pass a value of (0.0f,0.0f,0.0f,0.0f)

You don't mention what view and projection you're using, but, if that is a position, don't you need to set w = 1?

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

we have code tags on this forum please use them when posting code it makes it a lot easier for us to deal with your code.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion


I pass a value of (0.0f,0.0f,0.0f,0.0f)

You don't mention what view and projection you're using, but, if that is a position, don't you need to set w = 1?

Sorry for not using the code tags, I'll start using them now.

I don't understand how it can anything to do with the view or projection I'm using though as I've tested this out (using input layout, vertex buffers and with the same view and projection) and it draws completely fine. I honestly think it's something to do with how I'm using the SRV in the vertex shader or how I'm using the SRV full stop. To follow up on what you said about shouldn't w = 1. I've tried that and again a value of (0.0f,0.0f,0.0f,1.0f) gives a point drawn in the centre of the screen. However if I was to change it to something like (0.0f, 0.1f, 0.0f, 1.0f) just as an example I get absolutely nothing on the screen.

Having looked through multiple examples that are attempting to do the same thing I am really struggling to find differences in how they are setting this up and using it.

Okay, so I've fixed it! Guess what? It was to do with the projection and view matrices. Basically from what I understand I wasn't setting them correctly. And from debugging the vertex shader I realised that it was losing some values for the matrices as it was going through. So I tore allof it out and wrote the camera part again. Now it works perfectly, that took much longer than it should have!

This topic is closed to new replies.

Advertisement