IOS metal 编辑器 玻璃材质
程序员文章站
2022-11-08 21:55:50
ios metal 编辑器 玻璃材质
#include
float4 zfs(float zsl,float3 surfacenormal,float3 surfaceview,textu...
ios metal 编辑器 玻璃材质
#include float4 zfs(float zsl,float3 surfacenormal,float3 surfaceview,texturecube cubetexture,sampler cubesampler) { float4 finalcolorzs=float4(1.0,1.0,1.0,0.0); float4 finalcolorfs=float4(1.0,1.0,1.0,0.0); float4 finalcolor=float4(1.0,1.0,1.0,0.0); float3 vtexturecoord=float3(1.0,1.0,1.0); //texturecube cubetexture; const float maxh=0.7; const float minh=0.2; float sizeh=maxh-minh; float3 eyedirection=normalize(-surfaceview); float testvalue=abs(dot(eyedirection,surfacenormal)); if(testvalue>maxh) { vtexturecoord=refract(-eyedirection,surfacenormal,zsl); finalcolor=cubetexture.sample(cubesampler,vtexturecoord); }else if(testvalue<=maxh&&testvalue>=minh) { vtexturecoord=reflect(-eyedirection,surfacenormal); finalcolorfs=cubetexture.sample(cubesampler,vtexturecoord); vtexturecoord=refract(-eyedirection,surfacenormal,zsl); finalcolorzs=cubetexture.sample(cubesampler,vtexturecoord); float ratio=(testvalue-minh)/sizeh; finalcolor=finalcolorzs*ratio+(1.0-ratio)*finalcolorfs; }else { vtexturecoord=reflect(-eyedirection,surfacenormal); finalcolorfs=cubetexture.sample(cubesampler,vtexturecoord); } return finalcolor; } #pragma arguments texturecube cubetexture; #pragma transparent #pragma body constexpr sampler s(filter::linear,mip_filter::linear); _output.color.r=zfs(0.97,_surface.normal,_surface.view,cubetexture,s).r; _output.color.g=zfs(0.955,_surface.normal,_surface.view,cubetexture,s).g; _output.color.b=zfs(0.94,_surface.normal,_surface.view,cubetexture,s).b;
上一篇: iOS 复制一个UIView对象实现方法
下一篇: iOS开发中Cordoval运用技巧分析