凌雪
2018-10-10
来源 :网络
阅读 1353
评论 0
摘要:本文将带你了解IOS开发入门IOS metal 编辑器 玻璃材质,希望本文对大家学IOS有所帮助。
本文将带你了解IOS开发入门IOS metal 编辑器 玻璃材质,希望本文对大家学IOS有所帮助。
IOS metal 编辑器 玻璃材质
#include<metal_stdlib>
float4 zfs(float zsl,float3 surfaceNormal,float3 surfaceView,texturecube<float> 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<float> 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<float> 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;
</float></float></float></metal_stdlib>
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标移动开发之IOS频道!
喜欢 | 0
不喜欢 | 0
您输入的评论内容中包含违禁敏感词
我知道了

请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式AI+学习就业服务平台 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号