-
Notifications
You must be signed in to change notification settings - Fork 839
Creating a new LODFade node that exposes the LODFade values #6468
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
Conversation
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. Shader Graph 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. |
Hey Ben-- were you looking to take this PR out of draft, or were you going to bundle this node with a few others in a bigger PR later? |
I created this before I fully understood how the feature worked. In HDRP, there's a just a check box that enables the LOD fading feature for the material. And URP has a plan to implement it in a similar way. This node exposes the LOD fade values to the graph, but I'm not sure that's going to be useful if people can just turn it on and use it as a feature without requiring graph implementation. |
If we were willing to support such a node for the CROSS Fade feature, then we should do the following step. Look at cross fade PR for URP: users will need an option to say they want to use the shader graph version. And in the code calling the pattern function : So it imply:
Overall my personal opinion is that we could do proper support by adding a "cross lod pattern" input on master node and restrict this LOD fade node to be used only with it. Add an automatic switch to use shader graph path instead of regular one if we detect there is an input in this field. BUT is it worth it? Do we really want do offer such an option? This could prevent any futher optimization of the LOD cross fade system were we could move it to a uniform stencil pass (like unreal) that don't rely on having individual variant. So from my point of view we should not expose "internal" parameters of the system. My two cents :) |
public virtual void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode) | ||
{ | ||
sb.AppendLine(string.Format("$precision {0} = unity_LODFade.x;", GetVariableNameForSlot(OutputSlotFadeId))); | ||
sb.AppendLine(string.Format("$precision {0} = unity_LODFade.y;", GetVariableNameForSlot(OutputSlotQuantizedId))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we know where unity_LODFade is defined? Is it always set/defined for all unity shaders?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unity_LODFade is define in the UnityPerDraw.
This is currently a good question. I guess it is always define in the context of shader graph (even for procedural geometry) as the other values like unity_SHAr. Doesn't mean the content of the value will make sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have a way to guarantee that this node will handle situations where it isn't present-- but that's a separate problem. LGTM.
public virtual void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode) | ||
{ | ||
sb.AppendLine(string.Format("$precision {0} = unity_LODFade.x;", GetVariableNameForSlot(OutputSlotFadeId))); | ||
sb.AppendLine(string.Format("$precision {0} = unity_LODFade.y;", GetVariableNameForSlot(OutputSlotQuantizedId))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have a way to guarantee that this node will handle situations where it isn't present-- but that's a separate problem. LGTM.
I'm going to close this and not add it. My biggest issue with it is that the incoming data is packed in a somewhat non-intuitive way, so it's fairly complex to set up a graph to unpack it correctly to be able to use it. When users can just check a box and get great results, I don't see much point to giving them this and confusing them. I don't think there is a lot of benefit to being able to create custom cross fading effects. |
Hi ben |
I can send it to you on slack, but I don't know who you are. |
sorry yes i just sent you my contact info to your Unity forum profile :) |
Please read the Contributing guide before making a PR.
Checklist for PR maker
need-backport-*
label. After you backport the PR, the label changes tobackported-*
.CHANGELOG.md
file.Purpose of this PR
Exposes the LODFade parameters to Shader Graph, which would otherwise only be available using a custom code node.
Testing status
Created sample shader graph assets in both HDRP and URP and varified that the correct LOD Fade data is being passed from the new node into the graph.
Comments to reviewers
There is a bit of a debate about whether or not this node is actually needed. HDRP has a check box "Support LOD CrossFade" in the graph inspector. With this box checked, LOD cross fading is implemented "under the hood" and no implementation is required in Shader Graph. URP also has this feature on the road map to implement. This means that exposing this data for the Shader Graph would only be useful to those who want to create a custom implementation of the lod cross fading feature. The presence of the node may confuse new users, who, seeing it, might assume that lod cross fading requires the feature to be implemented in Shader Graph rather than just simply checking the box to turn it on.
Here's a video that shows how to implement the feature without this node - using the custom code node instead:
https://www.youtube.com/watch?v=lcHXSELuwXY
Here is Amplify's version of the node:
http://wiki.amplify.pt/index.php?title=Unity_Products:Amplify_Shader_Editor/LOD_Fade
Here's a subgraph I created with an implementation of LOD cross-fading
