这节课的主要目的是对uv进行操作,实现一些动画的效果,实际就是采样的动画
struct texDistort
{float2 texScale(float2 uv, float2 scale){float2 texScale = (uv - 0.5) * scale + 0.5;return texScale;}float2 texRotate(float2 uv, float angle){float2x2 rotationMatrix = float2x2(cos(angle), sin(angle),-sin(angle), cos(angle));return mul(uv - 0.5, rotationMatrix) + 0.5;}float2 texDistortion(float2 uv, float time){float angle = atan2(uv.y - 0.5, uv.x - 0.5);float radius = length(uv - 0.5);float distortion = 4 * sin(3 * radius + 2 * time);return texRotate(uv, distortion);}
};
主要的变化公式,这里主要注意hlsl中因为是列优先存储所以右乘会更加的快速。这里列举了三种变化方式
缩放
旋转
记得转为弧度制radians()
动态旋转
struct texDistort
{float2 texScale(float2 uv, float2 scale){float2 texScale = (uv - 0.5) * scale + 0.5;return texScale;}float2 texRotate(float2 uv, float angle){float2x2 rotationMatrix = float2x2(cos(angle), sin(angle),-sin(angle), cos(angle));return mul(uv - 0.5, rotationMatrix) + 0.5;}float2 texDistortion(float2 uv, float time){float angle = atan2(uv.y - 0.5, uv.x - 0.5);float radius = length(uv - 0.5);float distortion = 4 * sin(3 * radius + 2 * time);return texRotate(uv, distortion);}
} tex;
float4 color = Texture2DSample(texObject, texObjectSampler, tex.texDistortion(uv, time));
return color;
更多的变化
struct texDistort
{float2 texScale(float2 uv, float2 scale){float2 texScale = (uv - 0.5) * scale + 0.5;return texScale;}float2 texRotate(float2 uv, float angle){float2x2 rotationMatrix = float2x2(cos(angle), sin(angle),-sin(angle), cos(angle));return mul(uv - 0.5, rotationMatrix) + 0.5;}float2 texDistortion(float2 uv, float time){float angle = atan2(uv.y - 0.5, uv.x - 0.5);float radius = length(uv - 0.5);float distortion = 4 * sin(3 * radius + 2 * time);float primDist = sin(6.0 * angle) * distortion;return texRotate(uv, primDist);}
} tex;
float4 color = Texture2DSample(texObject, texObjectSampler, tex.texDistortion(uv, time));
return color;
深度视觉
深度视觉这里实际就是利用了,uv的偏移,形成的深度误差,当在黑色区域的时候,会向非黑区域偏移,形成了深度的效果