Unity, accessing vertex colors in surface shader

Source: Internet
Author: User

Ref:custom Data Computed per-vertex:http://docs.unity3d.com/manual/sl-surfaceshaderexamples.html
Shader "Custom/mystandard_vertexcolor" {
Properties {
_color ("Color", color) = (1,1,1,1)
_maintex ("Albedo (RGB)", 2D) = "White" {}
_glossiness ("Smoothness", Range (0,1)) = 0.5
_metallic ("Metallic", Range (0,1)) = 0.0
}
Subshader {
Tags {"Rendertype" = "Transparent" "Queue" = "Transparent"}
LOD 200

Cgprogram
Physically based standard lighting model, and enable shadows on all light types
#pragma surface surf standard fullforwardshadows Alpha:fade Vertex:vert

Use Shader Model 3.0 target, to get nicer looking lighting
#pragma target 3.0

Sampler2d _maintex;

struct Input {
FLOAT2 Uv_maintex;
Fixed4 My_vertcolor;
};

Half _glossiness;
Half _metallic;
Fixed4 _color;


void Vert (InOut appdata_full V, out Input o) {

Unity_initialize_output (input,o);//ref:http://forum.unity3d.com/threads/what-does-unity_initialize_output-do.186109/
O.my_vertcolor=v.color;
}


void Surf (Input in, InOut surfaceoutputstandard o) {
Albedo comes from a texture tinted by color
Fixed4 C = tex2d (_maintex, In.uv_maintex) * _COLOR*IN.MY_VERTCOLOR;
O.albedo = C.rgb;
Metallic and smoothness come from slider variables
O.metallic = _metallic;
o.smoothness = _glossiness;
O.alpha = C.A;
}
Endcg
}
FallBack "Diffuse"
}

Unity, accessing vertex colors in surface shader

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.