Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

Question Vertex output node - always in Object space?

Discussion in 'Shaders' started by OndrejP, Apr 1, 2023.

  1. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    278
    I'm new to Shader Graph. I have some shaders which use custom FOV (first person rendering) and I'm rewriting them into Shader Graph.

    Classic shaders return vertex position in clip space, however output of Shader Graph seems to be in Object Space (the Vertex Node). My calculation is done in clip space (using view space position + custom projection).

    Is there a way to output position in clip space? Or do I need to convert it back to Object space?
    It seems like waste of performance to convert back to object space...Shader graph has to internally convert to clip space anyway.

    I understand Object space might be required for some other things, like shadows.

    EDIT:
    It's simple Lit shader
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,072
    Short answer: No. There's no way to output anything but object space positions when using Shader Graph. You do have to convert back from clip space to object space, which has multiple draw backs, including cost, but also possible texture and surface warping in some setups.

    Long answer: Still no. But you can work around it a bit by using render features.


    There are some gotchas still with this setup, like the gun can stick through walls as it's not being "squished" in depth space like a lot of shader based approaches might.
     
    OndrejP likes this.
  3. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    278
    Thanks for the answer, I've written new shader (no shader graph), which uses same technique as the old one, but there are issue with it. Yes, I've used depth squishing in Built-in RP, but it causes more issues in URP.

    I'll take a look at the implementation using Render features, it seems also shadows work well with it.
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,072
    Yep. It has the nice side effect of actually rendering in the proper world space, and using the same shadow depth maps as the main camera (unlike when using two cameras to accomplish this in the BIRP). However it also has the same unfortunate side effects of casting and receiving shadows in world space, so if the weapon is close to another object in the scene or a wall it might cast shadows you don't want, and receive shadows that look wrong, and it'll stick through walls if too long. So you may still need to scale the weapon down, or want to use a custom shader anyways.