Jump to content
  • Advertisement
Sign in to follow this  
AxeGuywithanAxe

Screen Space Vector in world Space (Solved)

Recommended Posts

So I've been trying to implement Eric Bruneton's Atmospheric Scattering implementation, and I seem to be having an issue with the generation of the world space direction vector for the application phase. In his implementation he uses the inverse view projection matrix to project the view vector in the vertex shader to world space.

This is the debug view of my engine. Everything that is green is below the x-z plane, i,e the horizon , and everything about that line is red. As you can tell , the line is slanted. I wanted to know if anyone could give me any idea of what I'm doing wrong.

I've tried upwards of four different implementations of screen to world space direction projection, but this is my current code. I've also tried projecting to a frustum corner.

 

void DrawRectangle(in uint VertexID, out float4 OutPosition, out float2 OutUV)
{
	OutUV = float2((VertexID << 1) & 2, VertexID & 2);
	OutPosition = float4(OutUV * float2(2.0, -2.0) + float2(-1.0f, 1.0f), 0, 1);
}


void MainVertexShader(in uint VertexID : SV_VertexID,
					out float2 OutTexcoord : TEXCOORD0,
					out float4 OutScreenVector : TEXCOORD1,
					out float4 OutPosition : SV_POSITION)
{

	float4 OutSVPosition;

	// get the parameters
	DrawRectangle(VertexID,OutSVPosition,OutTexcoord);

	// set the out position 
	OutPosition = float4(OutSVPosition.xy,1.0f,1.0f);
	
	// construct the screen vector
	OutScreenVector = normalize(mul(View.InvViewProjection,float4(OutSVPosition.xy,1.0f,0.0f)));
}

 

 

 

SlantedHorizon.JPG

Edited by AxeGuywithanAxe

Share this post


Link to post
Share on other sites
Advertisement

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  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!