Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make this work under orthogonal camera? #1

Open
lee12321 opened this issue Jun 22, 2019 · 4 comments
Open

How to make this work under orthogonal camera? #1

lee12321 opened this issue Jun 22, 2019 · 4 comments

Comments

@lee12321
Copy link

Have tried to make some change in the code, but failed to get the foam right under orthogonal camera.

@vadermemo
Copy link

same here, bro. Any tip for us?

@udvaritibor
Copy link

Same here. Tried removing linearizing, etc, but messed up everything :D

@udvaritibor
Copy link

udvaritibor commented May 26, 2020

@lee12321 @vadermemo

I've managed to convert it partially.

Instead of always linearizing it (as it should be with a perspective camera):

float existingDepthLinear = LinearEyeDepth(existingDepth01);

Replace it with:

float existingDepthLinear = 0;

if (unity_OrthoParams.w > 0)
{
	// orthographic camera
#if defined(UNITY_REVERSED_Z)
	existingDepth01 = 1.0f - existingDepth01;
#endif
	existingDepthLinear = (existingDepth01 * _ProjectionParams.z) + _ProjectionParams.y;
}
else
{
	// perspective camera
	existingDepthLinear = LinearEyeDepth(existingDepth01);
}

Also, in Orthographic view, we can't use screenPosition.w, so in:

v2f vert (appdata v)
{
 	...
}

Insert this, so we will have a computed depth:

COMPUTE_EYEDEPTH(o.screenPosition.z);

And replace

float depthDifference = existingDepthLinear - i.screenPosition.w;

with:

float depthDifference = existingDepthLinear - i.screenPosition.z;

Cheers! :)

@udvaritibor
Copy link

udvaritibor commented Nov 28, 2020

@lee12321 @vadermemo I updated my code, because it had a bug.

On machines without REVERSED_Z it always had a depth of 0 due to some typo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants