Search Unity

vert/frag shader implementation of Standard surface shader

Discussion in 'Shaders' started by leonzhx, May 19, 2021.

  1. leonzhx

    leonzhx

    Joined:
    Dec 6, 2016
    Posts:
    29
    Hello, is there a equivalent vert/frag shader implementation of standard surface shader?
    I remember I have ever saw this somewhere but didn't remember the URL.
     
  2. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,550
    Surface shaders compiles to vert/frag. The issue is that there are a lot of shader passes you would have to write if you actually want to replicate the surface shader and its support of both forward and deferred.

    If you want what is effectively a vert/frag shader, then you can just use vert/surf for the same effect without all the work of recreating those shader passes/variants. There's examples on this page of combining a vertex program with the surf: https://docs.unity3d.com/Manual/SL-SurfaceShaderExamples.html
     
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Or you can select a Surface Shader in the Project window and click on Show generated code in the inspector and you'll get the vertex fragment shader version of it the engine actually uses. However since Surface Shaders are shader generators, what shader code is in the original Surface Shader can sometimes significantly change the output vertex fragment shader.
     
  4. leonzhx

    leonzhx

    Joined:
    Dec 6, 2016
    Posts:
    29
    Thanks for the tips.
    I have tried to import a compiled surface shader which works well under Unity 3D project to URP project, but it can not be rendered either, is there any debugging message to troubleshoot which line of the shader has been wrong?

    thanks
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    No, because you can’t use shaders written for the built in rendering path’s lighting systems with the URP. Surface Shaders don’t work not because they’re not “vertex fragment shaders”, but because the shaders code they use was written for the built in rendering paths. URP requires different passes, and different functions & variables to be used to access the lighting data to use for shading.

    If you want a shader that works with the URP, you have to start with a shader that works with the URP. If you want something more Surface Shader like, use Shader Graph. Just like Surface Shaders, it’s a vertex fragment shader generator, and you can have it output the generated shader code which you can then modify as you wish.