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\$
  • \$\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 Nov 21 '16 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 Nov 22 '16 at 6:03
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\$
  • \$\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 Aug 23 '17 at 12:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.