Sign in to follow this  
KieronH

Vertex Shader/Pixel Shader/SRV problem - Blank screen

Recommended Posts

KieronH    146

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!

Share this post


Link to post
Share on other sites
Buckeye    10747


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?

Share this post


Link to post
Share on other sites
KieronH    146

 


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. 

Share this post


Link to post
Share on other sites
KieronH    146
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!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this