|
资源信息 Asset Information
资源名称: | 圆润变平的shader smooth to flat unity (发帖教程) |
版本: | 无 (版本) |
资源等级: | 1 |
资源格式: | .unitypackage (链接失效请点击帖子右下方举报通知管理员) |
资源大小: | 1kb (默认:MB) |
下载地址: | 无 (购买积分) |
- Shader "Custom/Geometry/FlatShading"
- {
- Properties
- {
- _Color("Color", Color) = (1,1,1,1)
- _MainTex("Albedo", 2D) = "white" {}
- }
-
- SubShader
- {
-
- Tags{ "Queue"="Geometry" "RenderType"= "Opaque" "LightMode" = "ForwardBase" }
-
- Pass
- {
- CGPROGRAM
-
- #include "UnityCG.cginc"
- #pragma vertex vert
- #pragma geometry geom
- #pragma fragment frag
-
- float4 _Color;
- sampler2D _MainTex;
-
- struct v2g
- {
- float4 pos : SV_POSITION;
- float2 uv : TEXCOORD0;
- float3 vertex : TEXCOORD1;
- };
-
- struct g2f
- {
- float4 pos : SV_POSITION;
- float2 uv : TEXCOORD0;
- float light : TEXCOORD1;
- };
-
- v2g vert(appdata_full v)
- {
- v2g o;
- o.vertex = v.vertex;
- o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
- o.uv = v.texcoord;
- return o;
- }
-
- [maxvertexcount(3)]
- void geom(triangle v2g IN[3], inout TriangleStream<g2f> triStream)
- {
- g2f o;
-
- // Compute the normal
- float3 vecA = IN[1].vertex - IN[0].vertex;
- float3 vecB = IN[2].vertex - IN[0].vertex;
- float3 normal = cross(vecA, vecB);
- normal = normalize(mul(normal, (float3x3) unity_WorldToObject));
-
- // Compute diffuse light
- float3 lightDir = normalize(_WorldSpaceLightPos0.xyz);
- o.light = max(0., dot(normal, lightDir));
-
- // Compute barycentric uv
- o.uv = (IN[0].uv + IN[1].uv + IN[2].uv) / 3;
-
- for(int i = 0; i < 3; i++)
- {
- o.pos = IN[i].pos;
- triStream.Append(o);
- }
- }
-
- half4 frag(g2f i) : COLOR
- {
- float4 col = tex2D(_MainTex, i.uv);
- col.rgb *= i.light * _Color;
- return col;
- }
-
- ENDCG
- }
- }
- Fallback "Diffuse"
- }
复制代码 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
×
|