Skip to content

Conversation

eh-unity
Copy link
Contributor

@eh-unity eh-unity commented Sep 13, 2021

Checklist for PR maker

  • Have you added a backport label (if needed)? For example, the need-backport-* label. After you backport the PR, the label changes to backported-*.
  • Have you updated the changelog? Each package has a CHANGELOG.md file.
  • Have you updated or added the documentation for your PR? When you add a new feature, change a property name, or change the behavior of a feature, it's best practice to include related documentation changes in the same PR. If you do add documentation, make sure to add the relevant Graphics Docs team member as a reviewer of the PR. If you are not sure which person to add, see the Docs team contacts sheet.
  • Have you added a graphic test for your PR (if needed)? When you add a new feature, or discover a bug that tests don't cover, please add a graphic test.

Purpose of this PR

Fix terrain grass shader.

Issue:
035_Shader_TerrainShaders test was unstable and often failed with white grass. Turns out the white was actually transparent black.

The issue was something like this:

  1. Background is cleared, alpha == 0.
  2. Terrain writes alpha 1, write Z buffer.
  3. Grass drawn on top of terrain and background, but does not write alpha. Writes z buffer.
  4. Sky rendered, writes alpha 1, but is occluded by Z i.e. the grass on background.
  5. Grass parts are left transparent alpha == 0.

Grass shaders had masked alpha writes, this PR removes those.
The issue then is that alpha on the edges of grass blades can make holes (alpha < 1) to a Render Texture target.
So instead alpha mask, the shaders write 1 to alpha always, since the shader isn't doing blending anyway, just discard.

For the 2nd case I added additional test that renders the terrain into a render texture and then that to a quad with another red quad behind that. So if the render texture has any "holes" (i.e. grass overwrote terrain alpha) those will show as red pixels.

Also removed the Shader Lab AlphaTest command from the shaders as it is not used on SRPs.


Testing status

Ran test locally. Added a new test for Terrain grass in Render Texture.

This will need some additional manual QA for terrain grass.


Comments to reviewers

Notes for the reviewers you have assigned.

@eh-unity eh-unity requested a review from a team September 13, 2021 15:02
@github-actions
Copy link

Hi! This comment will help you figure out which jobs to run before merging your PR. The suggestions are dynamic based on what files you have changed.
Link to Yamato: https://yamato.cds.internal.unity3d.com/jobs/902-Graphics
Search for your PR branch using the sidebar on the left, then add the following segment(s) to the end of the URL (you may need multiple tabs depending on how many packages you change)

URP
/.yamato%252Fall-urp.yml%2523PR_URP_trunk
With changes to URP packages, you should also run
/.yamato%252Fall-lightmapper.yml%2523PR_LightMapper_trunk

Depending on the scope of your PR, you may need to run more jobs than what has been suggested. Please speak to your lead or a Graphics SDET (#devs-graphics-automation) if you are unsure.

@eh-unity eh-unity marked this pull request as ready for review September 13, 2021 17:30
@eh-unity eh-unity requested a review from a team as a code owner September 13, 2021 17:30
ENDHLSL
}

/*Pass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these commented out sections just be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I will remove those.

Copy link
Contributor

@TimAidleyAtUnity TimAidleyAtUnity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

I guess there's a chance we will change behavior for someone once they upgrade, but I feel that's better than leaving it broken.

@phi-lira phi-lira merged commit fc5f5ec into master Sep 20, 2021
@phi-lira phi-lira deleted the universal/fix-terrain-alpha branch September 20, 2021 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants