1
\$\begingroup\$

So for a simple surface shader, you can use vertex modifier:

    void vert (inout appdata_full v) {
        v.vertex.xyz += v.normal * _Amount;
    }

I was thinking the same would work as vertex shader:

    // vertex shader
    VectexOutput vert (VectexInput i) {
        // init output
        VectexOutput o;
        UNITY_INITIALIZE_OUTPUT(VectexOutput, o);

        // vertex extrusion
        i.vertex.xyz += i.normal * _Multiplier;

        // world space normal
        half3 normal = UnityObjectToWorldNormal(i.normal);

        // standard diffuse lighting
        half nl = max(0, dot(normal, _WorldSpaceLightPos0.xyz));

        // input to output
        o.vertex = UnityObjectToClipPos(i.vertex);
        o.color = i.color;
        o.diff = nl * _LightColor0;
        o.diff.rgb += ShadeSH9(half4(normal, 1));
        o.uv = TRANSFORM_TEX(i.uv, _MainTex);

        return o;
    }

But it doesn't, and since surface shader is compiled to vertex/fragment shader, I am wondering what am I missing?

\$\endgroup\$
2
  • \$\begingroup\$ There is also an example so very similar to mine (and works), I just could not figure out why mine doesn't work. \$\endgroup\$
    – bitinn
    Commented Nov 21, 2016 at 11:06
  • 1
    \$\begingroup\$ For future reference, when describing something that "doesn't work" it's very helpful to describe the precise way in which it does not work. Eg. Does it have no effect? Does it have a particular effect different from what you intended? (How does it differ?) Does it generate an error message or crash your program? (What error message/debug info?) etc. I gather from context here "doesn't work" means no effect at all, but it's good to be explicit about that. \$\endgroup\$
    – DMGregory
    Commented Nov 22, 2016 at 6:03

1 Answer 1

1
\$\begingroup\$

The answer is simple:

I declared _Multiplier incorrectly in the SubShader block.

It should have been uniform float _Multiplier, but I wrote uniform float4 _Multiplier;

Interesting part is: no error will be produced, because float4 _Multiplier defaults to (0,0,0,0), so i.vertex.xyz += i.normal * _Multiplier; result in zero float3, hence no change in vertex position.

\$\endgroup\$
1
  • \$\begingroup\$ Don't forget to mark your answer "Accepted" the next tome you're back. ;) Otherwise the Community user keeps bumping the question for new attention periodically. \$\endgroup\$
    – DMGregory
    Commented Aug 23, 2017 at 12:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .