Code
/*
/*
author : Jave.Lin
date : 2018-07-23
Testing texture, tintColor, filterAlpha(TTF) img shader
This is Simplest shader which have texture and tint color, and filter alpha, for ui(2d/3d)
*/
Shader "Testing/UI-TTF"
{
Properties
{
_MainTex ("Sprite Texture", 2D) = "white" {}
_TintColor ("Tint", Color) = (1,1,1,1)
_FilterAlpha ("FilterAlpha", range(0.0, 1.0)) = 0.0
}
SubShader
{
Tags
{
"Queue" = "Transparent"
}
Cull Off
Blend SrcAlpha OneMinusSrcAlpha
Pass
{
Name "Default"
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
uniform sampler2D _MainTex;
uniform fixed4 _MainTex_ST; // scale and translate(offset)
uniform fixed4 _TintColor;
uniform fixed _FilterAlpha;
struct appdata_my
{
float4 vertex : POSITION0;
fixed2 texcoord : TEXCOORD0;
};
struct v2f
{
float4 vertex : POSITION0;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
v2f vert(appdata_my v)
{
v2f o;
// method1 : to homogeneous coordinates
// UnityObjectToViewPos prototype:
// Tranforms position from object to camera space
/*
inline float3 UnityObjectToViewPos( in float3 pos )
{
return mul(UNITY_MATRIX_V, mul(unity_ObjectToWorld, float4(pos, 1.0))).xyz;
}
*/
//o.vertex.xyz = UnityObjectToViewPos(v.vertex); // mv
// UnityViewToClipPos prototype:
// Tranforms position from view to homogeneous space
/*
inline float4 UnityViewToClipPos( in float3 pos )
{
return mul(UNITY_MATRIX_P, float4(pos, 1.0));
}
*/
//o.vertex = UnityViewToClipPos(o.vertex.xyz); // p
// method2 : to homogeneous coordinates
// UnityObjectToClipPos prototype:
// using UnityObjectToClipPos more efficient
/*
// Tranforms position from object to homogeneous space
inline float4 UnityObjectToClipPos(in float3 pos)
{
// More efficient than computing M*VP matrix product
return mul(UNITY_MATRIX_VP, mul(unity_ObjectToWorld, float4(pos, 1.0)));
}
inline float4 UnityObjectToClipPos(float4 pos) // overload for float4; avoids "implicit truncation" warning for existing shaders
{
return UnityObjectToClipPos(pos.xyz);
}
*/
o.vertex = UnityObjectToClipPos(v.vertex);
o.color = _TintColor;
/*
// TRANSFORM_TEX prototype:
// Transforms 2D UV by scale/bias property
#define TRANSFORM_TEX(tex,name) (tex.xy * name##_ST.xy + name##_ST.zw)
*/
o.texcoord.xy = TRANSFORM_TEX(v.texcoord, _MainTex); // apply scale and offset
return o;
}
fixed4 frag(v2f IN) : COLOR
{
// tex 2d mapping by filtering
fixed4 texColor = tex2D(_MainTex, IN.texcoord.xy);
if (texColor.a
关注
打赏
最近更新
- 深拷贝和浅拷贝的区别(重点)
- 【Vue】走进Vue框架世界
- 【云服务器】项目部署—搭建网站—vue电商后台管理系统
- 【React介绍】 一文带你深入React
- 【React】React组件实例的三大属性之state,props,refs(你学废了吗)
- 【脚手架VueCLI】从零开始,创建一个VUE项目
- 【React】深入理解React组件生命周期----图文详解(含代码)
- 【React】DOM的Diffing算法是什么?以及DOM中key的作用----经典面试题
- 【React】1_使用React脚手架创建项目步骤--------详解(含项目结构说明)
- 【React】2_如何使用react脚手架写一个简单的页面?