Unity3D双面渲染
来源:互联网 发布:七天网络评卷 编辑:程序博客网 时间:2024/04/24 06:52
那个其实黑简单,只要把背面剔除关了就可以了,官网有标准shader的实现,然后改下就可以了。
这里只改alpha测试的shader,如果要改alpha混合的shader类似。
内建shader路径是Transparent/Cutout/VertexLit和Transparent/Cutout/Diffuse,两个里面在pass里面把Cull Off加起就可以了,然后shader的路径名要改下,不然会覆盖掉内建shader。
另外我遇到的一点问题是,Diffuse那个shader在pc上是正常的,在手机上不正常,VertexList在手机上是正常的。
这个跟硬件有关系,不过好在u3d的shader对硬件平台的处理上还可以比较方便。
在使用的时候那种需要渲染背面的和不需要渲染背面的要分材质,不然效率有影响。
附上改过后的shader:
AlphaTest.shader
Shader "Custom/AlphaTest" {Properties {_Color ("Main Color", Color) = (1,1,1,1)_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5}SubShader {Pass{Cull Off}Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}LOD 200CGPROGRAM#pragma surface surf Lambert alphatest:_Cutoffsampler2D _MainTex;fixed4 _Color;struct Input {float2 uv_MainTex;};void surf (Input IN, inout SurfaceOutput o) {fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;o.Albedo = c.rgb;o.Alpha = c.a;}ENDCG}FallBack "Custom/AlphaVerList"}
AlphaVerList.shader
Shader "Custom/AlphaVerList" {Properties {_Color ("Main Color", Color) = (1,1,1,1)_SpecColor ("Spec Color", Color) = (1,1,1,0)_Emission ("Emissive Color", Color) = (0,0,0,0)_Shininess ("Shininess", Range (0.1, 1)) = 0.7_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5}// 2/3 texture stage GPUsSubShader {Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}LOD 100// Non-lightmappedPass {Tags { "LightMode" = "Vertex" }Alphatest Greater [_Cutoff]AlphaToMask TrueColorMask RGBMaterial {Diffuse [_Color]Ambient [_Color]Shininess [_Shininess]Specular [_SpecColor]Emission [_Emission]}Cull OffLighting OnSeparateSpecular OnSetTexture [_MainTex] {Combine texture * primary DOUBLE, texture * primary } }// Lightmapped, encoded as dLDRPass {Tags { "LightMode" = "VertexLM" }Alphatest Greater [_Cutoff]AlphaToMask TrueColorMask RGBCull OffBindChannels {Bind "Vertex", vertexBind "normal", normalBind "texcoord1", texcoord0 // lightmap uses 2nd uvBind "texcoord", texcoord1 // main uses 1st uv}SetTexture [unity_Lightmap] {matrix [unity_LightmapMatrix]constantColor [_Color]combine texture * constant}SetTexture [_MainTex] {combine texture * previous DOUBLE, texture * primary}}// Lightmapped, encoded as RGBMPass {Tags { "LightMode" = "VertexLMRGBM" }Alphatest Greater [_Cutoff]AlphaToMask TrueColorMask RGBCull OffBindChannels {Bind "Vertex", vertexBind "normal", normalBind "texcoord1", texcoord0 // lightmap uses 2nd uvBind "texcoord1", texcoord1 // unusedBind "texcoord", texcoord2 // main uses 1st uv}SetTexture [unity_Lightmap] {matrix [unity_LightmapMatrix]combine texture * texture alpha DOUBLE}SetTexture [unity_Lightmap] {constantColor [_Color]combine previous * constant}SetTexture [_MainTex] {combine texture * previous QUAD, texture * primary}}// Pass to render object as a shadow casterPass {Name "Caster"Tags { "LightMode" = "ShadowCaster" }Offset 1, 1Cull OffFog {Mode Off}ZWrite On ZTest LEqual Cull OffCGPROGRAM#pragma vertex vert#pragma fragment frag#pragma multi_compile_shadowcaster#pragma fragmentoption ARB_precision_hint_fastest#include "UnityCG.cginc"struct v2f { V2F_SHADOW_CASTER;float2 uv : TEXCOORD1;};uniform float4 _MainTex_ST;v2f vert( appdata_base v ){v2f o;TRANSFER_SHADOW_CASTER(o)o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);return o;}uniform sampler2D _MainTex;uniform fixed _Cutoff;uniform fixed4 _Color;float4 frag( v2f i ) : COLOR{fixed4 texcol = tex2D( _MainTex, i.uv );clip( texcol.a*_Color.a - _Cutoff );SHADOW_CASTER_FRAGMENT(i)}ENDCG}// Pass to render object as a shadow collectorPass {Name "ShadowCollector"Tags { "LightMode" = "ShadowCollector" }Cull OffFog {Mode Off}ZWrite On ZTest LEqualCGPROGRAM#pragma vertex vert#pragma fragment frag#pragma fragmentoption ARB_precision_hint_fastest#pragma multi_compile_shadowcollector#define SHADOW_COLLECTOR_PASS#include "UnityCG.cginc"struct v2f {V2F_SHADOW_COLLECTOR;float2 uv : TEXCOORD5;};uniform float4 _MainTex_ST;v2f vert (appdata_base v){v2f o;TRANSFER_SHADOW_COLLECTOR(o)o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);return o;}uniform sampler2D _MainTex;uniform fixed _Cutoff;uniform fixed4 _Color;fixed4 frag (v2f i) : COLOR{fixed4 texcol = tex2D( _MainTex, i.uv );clip( texcol.a*_Color.a - _Cutoff );SHADOW_COLLECTOR_FRAGMENT(i)}ENDCG}}// 1 texture stage GPUsSubShader {Tags {"IgnoreProjector"="True" "RenderType"="TransparentCutout"}LOD 100Pass {Tags { "LightMode" = "Always" }Alphatest Greater [_Cutoff]AlphaToMask TrueColorMask RGBMaterial {Diffuse [_Color]Ambient [_Color]Shininess [_Shininess]Specular [_SpecColor]Emission [_Emission]}Cull OffLighting OnSeparateSpecular OnSetTexture [_MainTex] {Combine texture * primary DOUBLE, texture * primary }}}}
- Unity3D双面渲染
- unity3d 双面渲染shader的编写
- 双面渲染shader
- 双面渲染shader
- Unity3d 双面材质
- GLSL-双面渲染技术(Two-sided rendering)
- unity双面渲染shader的编写
- OpenGL 4.0 用GLSL实现双面渲染
- OpenGL 4.0 用GLSL实现双面渲染
- Unity3D教程:模型产生双面法线效果
- UNITY3D shader代码例子<二> 双面显示
- Away3D中DAE模型无法双面渲染的解决方案
- 【OpenGL】GLSL-双面渲染技术(Two-sided rendering)
- 现代OpenGL+Qt学习笔记之八:GLSL双面渲染
- 【Unity3D学习笔记】unity5.x中的双面材质shader实现
- 【Unity3d学习笔记】unity制作双面材质shader
- Unity3D渲染优化技巧
- Unity3D选择性渲染技术
- git:如何用git-am来合并git format-patch生成的patch
- java基础语法1
- C#中FileSystemWatcher控件实现文件监控
- 怎么在arcgis地图管理器里面把小部件的背景颜色和整个管理器的颜色分开
- 批处理教程
- Unity3D双面渲染
- 为什么你应该写博客
- 2012年08月23日
- 打造自己的LINQ Provider(上):Expression Tree揭秘
- centos5.8 安装asterisk 和freeiris
- 如何去掉listview黑边问题
- System.Linq.Expressions.Expression 的 320个方法、2个构造函数和3个属性
- Windows下环境变量设置
- c++封装ping程序类