当前位置:网站首页>Double sided shader
Double sided shader
2022-04-23 07:47:00 【youth who behaves like an adult】
// 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"
}
版权声明
本文为[youth who behaves like an adult]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230626191487.html
边栏推荐
- new的实现
- js之DOM学习获取元素
- SAP PI/PO rfc2RESTful 发布rfc接口为RESTful示例(Proxy间接法)
- electron-builder打包报错:proxyconnect tcp: dial tcp :0: connectex
- Django uses MySQL database to solve error reporting
- 7. sub query
- TimelineWindow
- How to judge whether a point is within a polygon (including complex polygons or a large number of polygons)
- Solutions to common problems in visualization (VII) solutions to drawing scale setting
- MySQL8.0 安装/卸载 教程【Window10版】
猜你喜欢
Redis connection error err auth < password > called without any password configured for the default user
int a = 1存放在哪
Solutions to common problems in visualization (VII) solutions to drawing scale setting
将指定路径下的所有SVG文件导出成PNG等格式的图片(缩略图或原图大小)
SAP pi / PO rfc2restful publishing RFC interface is a restful example (proxy indirect method)
Authorization server (simple construction of authorization server)
SAP 导出Excel文件打开显示:“xxx“的文件格式和扩展名不匹配。文件可能已损坏或不安全。除非您信任其来源,否则请勿打开。是否仍要打开它?
ogldev-读书笔记
Page dynamic display time (upgraded version)
H5 local storage data sessionstorage, localstorage
随机推荐
数组扁平化
electron-builder打包报错:proxyconnect tcp: dial tcp :0: connectex
ogldev-读书笔记
超级宝典&编程指南(红蓝宝书)-读书笔记
系统与软件安全研究(三)
Common DOS commands
js之自定义属性以及H5中如何判断自定义属性
Thorough inquiry -- understanding and analysis of cocos2d source code
FUEL: Fast UAV Exploration using Incremental Frontier Structure and Hierarchical Planning
系统与软件安全研究(五)
NodeJS(六) 子进程操作
Learn to use search engines
How to judge whether a point is within a polygon (including complex polygons or a large number of polygons)
'NPM' is not an internal or external command, nor is it a runnable program or batch file
[self motivation series] what really hinders you?
Simple random roll call lottery (written under JS)
typescript字典的使用
Django uses MySQL database to solve error reporting
踩坑日记:Unable to process Jar entry [module-info.class]
基于NLP的软件安全研究(一)