当前位置:网站首页>Shadertoy realizes simple compass
Shadertoy realizes simple compass
2022-06-22 02:01:00 【The end of the wind】
For the first time contact glsl, Wrote a simple version of the rotating compass demo, On the first code :
/**
*@param uv uv
*@param col color
*@param probe_l Probe length
*@param probe_w Probe width
*@param center center
*/
vec4 campass(vec2 uv,vec4 col,float probe_l,float probe_w,vec2 center){
float half_l=probe_l/float(2);
float half_w=probe_w/float(2);
float si=sin(iTime*.7);
float cs=cos(iTime*.7);
// Transformation matrix
mat2 trans=mat2(cs,si,-si,cs);
// probe 4 The vertices
vec2 dot1=vec2(center.x-half_l,0.);
vec2 dot2=vec2(0,center.y+half_w);
vec2 dot3=vec2(center.x+half_l,0.);
vec2 dot4=vec2(0.,center.y-half_w);
// Yes 4 Vertex matrix transformation
dot1=dot1*trans;
dot2=dot2*trans;
dot3=dot3*trans;
dot4=dot4*trans;
// Vector cross product ,uv The vector corresponding to each vertex line , Cross multiply the sides of a polygon , Cross product result z Positive value \ Same negative , To judge uv The coordinates are in the corresponding polygon
vec3 inner12=cross(vec3(uv-dot1,.0),vec3(dot2-dot1,0.));
vec3 inner23=cross(vec3(uv-dot2,0.),vec3(dot3-dot2,0.));
vec3 inner34=cross(vec3(uv-dot3,0.),vec3(dot4-dot3,0.));
vec3 inner41=cross(vec3(uv-dot4,0.),vec3(dot1-dot4,0.));
vec3 inner24=cross(vec3(uv-dot4,0.),vec3(dot4-dot2,0.));
// Judge the two ends of the probe , Fill in different colors
if((inner12.z>0.&&inner24.z>0.&&inner41.z>0.)||((inner12.z<0.&&inner24.z<0.&&inner41.z<0.))){
return col;
}
if((inner23.z>0.&&inner34.z>0.&&inner24.z<0.)||((inner23.z<0.&&inner34.z<0.&&inner24.z>0.))){
vec4 newcol=col*2.;
return newcol;
}
// draw a circle
float panel_r=length(uv-center);
if(panel_r<half_l+.001&&panel_r>half_l-.001){
return vec4(vec3(0.),1.);
}
return vec4(vec3(1.),1.);
}
void mainImage(out vec4 fragColor,in vec2 fragCoord)
{
// uv Range (-0.5~0.5)
vec2 uv=fragCoord/iResolution.xy-.5;
uv.y=uv.y*(iResolution.y/iResolution.x);
float cs=cos(iTime*.047),si=sin(iTime*.79);
vec4 col=vec4(cs,si,.0,.5);
col=campass(uv,col,.4,.05,vec2(.0,.0));
fragColor=col;
}
There seems to be nothing to say , Look directly at the renderings :

边栏推荐
- Zhongang Mining Co., Ltd.: fluorite is a scarce resource with enhanced attributes, and there may be a gap between supply and demand in the future
- Machine learning pytoch implementation case LSTM case (flight number prediction)
- 【随笔】昨天研究了一天 RN 生态的 Expo 的确牛逼,从开发构建到部署一条龙,很好使。
- 第298场力扣周赛个人题解
- 【第 06 章 MATLAB实现基于分水岭分割进行肺癌诊断】
- 2020 CSP-J1 CSP-S1 第1轮 初赛 答案解析及总结、视频等
- 程序员常用的组件、框架、开发工具下载链接大全
- NVIDIA written interview questions sorting DIY
- LeetCode+ 46 - 50
- 联发科技 --联发科技简介++附上笔经面经
猜你喜欢

第 18 章 基于GUI搭建通用视频处理工具matlab应用GUI实现

【第 02 章 基于形态学的权重自适应图像去噪技术-全套系统MATLAB智能驾驶深度学习】

Test APK exception control sensor attacker development

Mysql数据库轻松学09—数据分析师常用:数据查询语言DQL之多表查询

sql server递归查询
![[Chapter 10: a website digital verification code recognition based on moment invariants matlab deep learning practical application case]](/img/19/867c03660cb9127dbb967402d8ca8f.png)
[Chapter 10: a website digital verification code recognition based on moment invariants matlab deep learning practical application case]

Digital final notes

Commission contract on BSV

acwing 838. Heap sort (write a heap)

BSV上的委托合约(3)
随机推荐
Appium面试题
How to restore the IE browser auto jump edge
MBA-day18 消元法
acwing 836. 合并集合 (并查集)
第 03 章 基于多尺度形态学提取眼前节组织-全套系统MATLAB智能驾驶深度学习
第 19 章 基于语音识别的信号灯图像模拟控制技术
【第 14 章 基于主成分分析的图像压缩和重建--matlab深度学习实战案例】
数电期末笔记
digital signal processing
Five strokes first lesson fingering
Chapter 03 extraction of anterior segment tissue based on multi-scale morphology - full system matlab intelligent driving in-depth learning
Recommended by Alibaba, Tencent and Baidu Software Test Engineers - rapid prototype model of software test model
Copy in pytorch_ Summary of differences between (), detach (), data (), and clone () operations
光照相关 shader
Right alignment of MathType formula right number in word
阿里,腾讯,百度软件测试工程师推荐——软件测试模型之瀑布模型
2019 csp-j1 csp-s1 first round preliminary round answer analysis and summary, video, etc
新员工入职,了解工作信息
Chapter 08 handwritten digit recognition based on knowledge base matlab deep learning application practice
Ansible profile