初次提交
This commit is contained in:
41
第14章 片元着色器的妙用/Sample14_1/assets/frag.sh
Normal file
41
第14章 片元着色器的妙用/Sample14_1/assets/frag.sh
Normal file
@@ -0,0 +1,41 @@
|
||||
precision mediump float;
|
||||
varying vec2 mcLongLat;//接收从顶点着色器过来的参数
|
||||
void main()
|
||||
{
|
||||
vec3 bColor=vec3(0.678,0.231,0.129);//砖块的颜色
|
||||
vec3 mColor=vec3(0.763,0.657,0.614);//间隔的颜色
|
||||
vec3 color;
|
||||
|
||||
//计算当前位于奇数还是偶数行
|
||||
int row=int(mod((mcLongLat.y+90.0)/12.0,2.0));
|
||||
//计算当前是否在此行的砖块垂直区间中的辅助变量
|
||||
float ny=mod(mcLongLat.y+90.0,12.0);
|
||||
//奇偶数行x偏移
|
||||
float oeoffset=0.0;
|
||||
//计算当前是否在此列的砖块水平区间中的辅助变量
|
||||
float nx;
|
||||
|
||||
if(ny>10.0)
|
||||
{//不在此行的砖块垂直区间中
|
||||
color=mColor;
|
||||
}
|
||||
else
|
||||
{//在此行的砖块垂直区间中
|
||||
if(row==1)
|
||||
{//若为奇数行则加上列偏移
|
||||
oeoffset=11.0;
|
||||
}
|
||||
//计算当前是否在此列的砖块水平区间中的辅助变量
|
||||
nx=mod(mcLongLat.x+oeoffset,22.0);
|
||||
if(nx>20.0)
|
||||
{//不在此列的砖块水平区间中
|
||||
color=mColor;
|
||||
}
|
||||
else
|
||||
{//在此列的砖块水平区间中
|
||||
color=bColor;
|
||||
}
|
||||
}
|
||||
//将计算出的颜色给此片元
|
||||
gl_FragColor=vec4(color,0);
|
||||
}
|
||||
11
第14章 片元着色器的妙用/Sample14_1/assets/vertex.sh
Normal file
11
第14章 片元着色器的妙用/Sample14_1/assets/vertex.sh
Normal file
@@ -0,0 +1,11 @@
|
||||
uniform mat4 uMVPMatrix; //总变换矩阵
|
||||
attribute vec3 aPosition; //顶点位置
|
||||
attribute vec2 aLongLat; //顶点经纬度
|
||||
varying vec2 mcLongLat;
|
||||
void main()
|
||||
{
|
||||
//根据总变换矩阵计算此次绘制此顶点位置
|
||||
gl_Position = uMVPMatrix * vec4(aPosition,1);
|
||||
//将顶点的经纬度传给片元着色器
|
||||
mcLongLat=aLongLat;
|
||||
}
|
||||
Reference in New Issue
Block a user