So, I tried to change the color and intensity of a Unity URP Vignette, but they disable every time I do (this is Octalian). I looked through every script, and nothing was modifying it. Could someone please help me?
that one has my post processing blending code, it’s in https://github.com/Octr/BLACKTHORN-DAY4/blob/main/Assets/_Game/Scripts/PPManager.cs
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);
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:
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);
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.
Make sure the vignette variable is referencing the correct Vignette component and it’s enabled in the Inspector.
Check that the vignetteColorTop values are within the [0, 1] range for all RGB components.
Verify that the post-processing stack or package is correctly set up in the project, including the Post-Processing Volume, profile, and layer.
Check if there are any error messages in the Unity Console that might give clues about what’s going wrong.
Test with default values for vignetteColorTop and without the vignette.intensity line to isolate potential issues.
Ensure that the depthMultiplier value is calculated correctly and has meaningful values based on the scene setup.
If you still can’t find the issue after rechecking the above points, it might be helpful to provide more context or share additional relevant parts of the code or the Unity project. This way, it would be easier to identify any potential issues that are not apparent in the code snippet alone.