unity shader实现玻璃折射效果
程序员文章站
2023-02-19 15:09:29
本文实例为大家分享了unity shader实现玻璃折射的具体代码,供大家参考,具体内容如下shader "unlit/render_reflect"{ properties { _maintex (...
本文实例为大家分享了unity shader实现玻璃折射的具体代码,供大家参考,具体内容如下
shader "unlit/render_reflect" { properties { _maintex ("texture", 2d) = "white" {} } subshader { tags {"queue" = "transparent" "rendertype"="opaque" } lod 100 grabpass{"_screentex"} pass { cgprogram #pragma vertex vert #pragma fragment frag // make fog work #pragma multi_compile_fog #include "unitycg.cginc" #include "lighting.cginc" #include "autolight.cginc" struct appdata { float4 vertex : position; float2 uv : texcoord0; }; struct v2f { float4 uv : texcoord0; float2 uv2 : texcoord1; float4 vertex : sv_position; }; sampler2d _maintex; float4 _maintex_st; sampler2d _screentex; v2f vert (appdata v) { v2f o; o.vertex = unityobjecttoclippos(v.vertex); o.uv2 = transform_tex(v.uv, _maintex); o.uv = computegrabscreenpos(o.vertex); //o.uv.x = 1 - o.uv.x; return o; } fixed4 frag (v2f i) : sv_target { // sample the texture i.uv.xy += float2(0.1,0.1); fixed4 fra = tex2d(_screentex, i.uv.xy/i.uv.w); fixed4 fle = tex2d(_maintex, i.uv2); // apply fog return lerp(fra, fle, 0.2); } endcg } } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。