当前位置:网站首页>双面显示的shader
双面显示的shader
2022-04-23 06:27:00 【老少年】
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "Custom/TwoFaceTransparent" {
Properties{
_Color("Color Tint", Color) = (1, 1, 1, 1)
_MainTex("Main Tex", 2D) = "white" {}
_AlphaScale("Alpha Scale", Range(0, 1)) = 1
}
SubShader{
Tags {"Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent"}
Pass {
Tags { "LightMode" = "ForwardBase" }
// First pass renders only back faces
Cull Front
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Lighting.cginc"
fixed4 _Color;
sampler2D _MainTex;
float4 _MainTex_ST;
fixed _AlphaScale;
struct a2v {
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 texcoord : TEXCOORD0;
};
struct v2f {
float4 pos : SV_POSITION;
float3 worldNormal : TEXCOORD0;
float3 worldPos : TEXCOORD1;
float2 uv : TEXCOORD2;
};
v2f vert(a2v v) {
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.worldNormal = UnityObjectToWorldNormal(v.normal);
o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
return o;
}
fixed4 frag(v2f i) : SV_Target {
fixed3 worldNormal = normalize(i.worldNormal);
fixed3 worldLightDir = normalize(UnityWorldSpaceLightDir(i.worldPos));
fixed4 texColor = tex2D(_MainTex, i.uv);
fixed3 albedo = texColor.rgb * _Color.rgb;
fixed3 ambient = UNITY_LIGHTMODEL_AMBIENT.xyz * albedo;
fixed3 diffuse = _LightColor0.rgb * albedo * max(0, dot(worldNormal, worldLightDir));
return fixed4(ambient + diffuse, texColor.a * _AlphaScale);
}
ENDCG
}
Pass {
Tags { "LightMode" = "ForwardBase" }
// Second pass renders only front faces
Cull Back
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Lighting.cginc"
fixed4 _Color;
sampler2D _MainTex;
float4 _MainTex_ST;
fixed _AlphaScale;
struct a2v {
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 texcoord : TEXCOORD0;
};
struct v2f {
float4 pos : SV_POSITION;
float3 worldNormal : TEXCOORD0;
float3 worldPos : TEXCOORD1;
float2 uv : TEXCOORD2;
};
v2f vert(a2v v) {
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.worldNormal = UnityObjectToWorldNormal(v.normal);
o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
return o;
}
fixed4 frag(v2f i) : SV_Target {
fixed3 worldNormal = normalize(i.worldNormal);
fixed3 worldLightDir = normalize(UnityWorldSpaceLightDir(i.worldPos));
fixed4 texColor = tex2D(_MainTex, i.uv);
fixed3 albedo = texColor.rgb * _Color.rgb;
fixed3 ambient = UNITY_LIGHTMODEL_AMBIENT.xyz * albedo;
fixed3 diffuse = _LightColor0.rgb * albedo * max(0, dot(worldNormal, worldLightDir));
return fixed4(ambient + diffuse, texColor.a * _AlphaScale);
}
ENDCG
}
}
FallBack "Transparent/VertexLit"
}
版权声明
本文为[老少年]所创,转载请带上原文链接,感谢
https://blog.csdn.net/laoshaonian/article/details/86506466
边栏推荐
- 12. Constraints
- 4.多表查询
- VR、AR、MR的区别与应用,以及对AR技术的一些实现原理
- js之预解析
- What are the total number of all courses of Mr. Tang Xiaoyang, who is very popular in CSDN (question mark)
- Use of typescript dictionary
- 反思 | Android 音视频缓存机制的系统性设计
- 如何判断点是否在多边形内(包含复杂多边形或者多边形数量很多的情况)
- 'NPM' is not an internal or external command, nor is it a runnable program or batch file
- 事件系统(二)多播事件
猜你喜欢
Reflection on the systematic design of Android audio and video caching mechanism
SAP PI/PO rfc2RESTful 發布rfc接口為RESTful示例(Proxy間接法)
SAP pi / PO rfc2restful publishing RFC interface is a restful example (proxy indirect method)
SAP ECC连接SAP PI系统配置
Authorization server (simple construction of authorization server)
Ogldev reading notes
SAP PI/PO rfc2Soap 发布rfc接口为ws示例
Nacos / sentinel gateway current limiting and grouping (code)
js之节点操作,为什么要学习节点操作
中间人环境mitmproxy搭建
随机推荐
Xamarin版的C# SVG路径解析器
BTree、B+Tree和HASH索引
.NET 5 的新功能 What‘s new in .NET 5
SAP PI/PO功能运行状态监控检查
Authorization server (simple construction of authorization server)
SAP 03-AMDP CDS Table Function using ‘WITH‘ Clause(Join子查询内容)
canvas学习第一篇
Learn to use search engines
Configure NPM
js之DOM事件
系统与软件安全研究(四)
promise all的实现
ABAP 实现发布RESTful服务供外部调用示例
instanceof的实现原理
公共依赖模块common的处理
自己封装unity的Debug函数
CSDN很火的汤小洋老师全部课程总共有哪些(问号问号问号)
int a = 1存放在哪
Use of typescript dictionary
c#读取INI文件和向ini文件写入数据