2
\$\begingroup\$

I want to edit the Standard shader provided by Unity in order to change the alpha value of a fragment (pixel) according to given parameters I pass to the shader.

For now, thanks to this link, I have been able to :

  1. Retrieve the standard shader,
  2. Retrieve a custom Core.cginc I included in the DEFERRED pass of the custom shader,
  3. Create a custom Editor script to handle the Shader and my custom parameters,
  4. Selecte Fade as the rendering mode of the shader to handle transparency, using the custom editor script,
  5. Create a custom file replacing UnityStandardInput.cginc and changed the references in the Core.cginc file.

But now, I can't seem to figure where to change the alpha value of the fragment. I've tried a ton of possibilities in the Core.cginc file. Changing the color and the map of the Albedo works, but I can't find where the final alpha value is set.

I've browsed the files in the CGIncludes folder in the builtin shaders of Unity.

  • UnityStandardCore.cginc : Already tried many possibilities (including the returned value of Alpha declared in UnityStandardInput.cginc
  • CustomInput.cginc : Alpha function, no effect

Since the files are huge, I don't feel it will be useful to copy-paste them here.

Thanks for your help in advance.

\$\endgroup\$
1
\$\begingroup\$

I have been able to solve it myself. In the end, you will need at least 6 files :

  • Shader file itself
  • Core.cginc
  • CoreForward.cginc
  • CoreForwardSimple.cginc
  • Input.cginc
  • Meta.cginc

In all these files, replace all the references to the UnityStandardXXX by your custom files. Don't miss any !

Then, in the Core.cginc file, I've edited the FragmentSetup function to change the value of the alpha variable : half alpha = Alpha(i_tex.xy) ;

\$\endgroup\$
  • \$\begingroup\$ 4.x shaders were so much easier to play with \$\endgroup\$ – Draco18s no longer trusts SE Jul 5 '17 at 13:31
  • \$\begingroup\$ That's the price to pay for PBR I guess ! But it's a pain, for sure. \$\endgroup\$ – Hellium Jul 5 '17 at 13:49
  • \$\begingroup\$ Must be. And now I use Shader Forge for all my shader needs (totally worth the money). \$\endgroup\$ – Draco18s no longer trusts SE Jul 5 '17 at 13:52

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.