Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Here is the code: 

float depthMultiplier = -((pos1.position.y + pos2.position.y) / (pos1.position.y + transform.position.y));

            vignette.color = new ColorParameter(new Color(vignetteColorTop.r * 1-depthMultiplier, vignetteColorTop.g * 1-depthMultiplier , vignetteColorTop.b*1-depthMultiplier));

            vignette.intensity = new ClampedFloatParameter(depthMultiplier, 0, 1);

(3 edits)

The code you provided has an issue in the second line where you calculate the Color for the vignette.color. The multiplication operation is incorrect due to the missing parentheses around 1 - depthMultiplier. Here’s the corrected version of the code:


float depthMultiplier = -((pos1.position.y + pos2.position.y) / (pos1.position.y + transform.position.y));

vignette.color = new ColorParameter(new Color(vignetteColorTop.r * (1 - depthMultiplier), vignetteColorTop.g * (1 - depthMultiplier), vignetteColorTop.b * (1 - depthMultiplier)));

vignette.intensity = new ClampedFloatParameter(depthMultiplier, 0, 1);


Explanation:

The code calculates the depthMultiplier based on the vertical positions of pos1, pos2, and the current transform (transform.position.y).

It then sets the vignette.color based on the vignetteColorTop with each RGB component multiplied by (1 - depthMultiplier). This effectively darkens the color based on the depthMultiplier value.

Finally, it sets the vignette.intensity to the depthMultiplier, clamped between 0 and 1.

With the parentheses added, the code should work as intended, applying the correct vignette effect based on the depthMultiplier value.

I actually saw that there was a missing parenthesis, but didn't think it would do anything. Thank you so much!