初次提交
This commit is contained in:
27
第13章 顶点着色器的妙用/Sample13_3/assets/frag_landform.sh
Normal file
27
第13章 顶点着色器的妙用/Sample13_3/assets/frag_landform.sh
Normal file
@@ -0,0 +1,27 @@
|
||||
precision mediump float;
|
||||
varying vec2 vTextureCoord; //接收纹理坐标参数
|
||||
varying float vertexHeight;//接受顶点的高度值
|
||||
uniform sampler2D sTextureSand;//纹理内容数据 ----沙滩
|
||||
uniform sampler2D sTextureGrass;//纹理内容数据-----草地
|
||||
void main()
|
||||
{
|
||||
float height1=15.0;
|
||||
float height2=25.0;
|
||||
vec4 finalSand=texture2D(sTextureSand, vTextureCoord);//沙滩
|
||||
vec4 finalGrass=texture2D(sTextureGrass, vTextureCoord); //草地
|
||||
if(vertexHeight<height1)//绘制沙滩
|
||||
{
|
||||
gl_FragColor = finalSand;
|
||||
}
|
||||
else if(vertexHeight<height2)//绘制草地和沙滩混合层
|
||||
{
|
||||
float ratio=(vertexHeight-height1)/(height2-height1);
|
||||
finalSand *=(1.0-ratio);
|
||||
finalGrass *=ratio;
|
||||
gl_FragColor =finalGrass+ finalSand;
|
||||
}
|
||||
else//绘制草地
|
||||
{
|
||||
gl_FragColor = finalGrass;
|
||||
}
|
||||
}
|
||||
7
第13章 顶点着色器的妙用/Sample13_3/assets/frag_leaves.sh
Normal file
7
第13章 顶点着色器的妙用/Sample13_3/assets/frag_leaves.sh
Normal file
@@ -0,0 +1,7 @@
|
||||
precision mediump float;
|
||||
varying vec2 vTextureCoord; //接收从顶点着色器过来的参数
|
||||
uniform sampler2D sTexture;//纹理内容数据
|
||||
void main()
|
||||
{
|
||||
gl_FragColor=texture2D(sTexture, vTextureCoord);
|
||||
}
|
||||
9
第13章 顶点着色器的妙用/Sample13_3/assets/frag_tex.sh
Normal file
9
第13章 顶点着色器的妙用/Sample13_3/assets/frag_tex.sh
Normal file
@@ -0,0 +1,9 @@
|
||||
precision mediump float;
|
||||
varying vec2 vTextureCoord; //接收从顶点着色器过来的参数
|
||||
uniform sampler2D sTexture;//纹理内容数据
|
||||
varying vec3 vVertexCoord;
|
||||
void main()
|
||||
{
|
||||
//给此片元从纹理中采样出颜色值
|
||||
gl_FragColor = texture2D(sTexture, vTextureCoord);
|
||||
}
|
||||
8
第13章 顶点着色器的妙用/Sample13_3/assets/frag_tree.sh
Normal file
8
第13章 顶点着色器的妙用/Sample13_3/assets/frag_tree.sh
Normal file
@@ -0,0 +1,8 @@
|
||||
precision mediump float;
|
||||
varying vec2 vTextureCoord; //接收从顶点着色器过来的参数
|
||||
uniform sampler2D sTexture;//纹理内容数据
|
||||
void main()
|
||||
{
|
||||
//将计算出的颜色给此片元
|
||||
gl_FragColor=texture2D(sTexture, vTextureCoord);
|
||||
}
|
||||
8
第13章 顶点着色器的妙用/Sample13_3/assets/frag_water.sh
Normal file
8
第13章 顶点着色器的妙用/Sample13_3/assets/frag_water.sh
Normal file
@@ -0,0 +1,8 @@
|
||||
precision mediump float;
|
||||
varying vec2 vTextureCoord; //接收从顶点着色器过来的参数
|
||||
uniform sampler2D sTexture;//纹理内容数据
|
||||
void main()
|
||||
{
|
||||
//给此片元从纹理中采样出颜色值
|
||||
gl_FragColor = texture2D(sTexture, vTextureCoord);
|
||||
}
|
||||
12
第13章 顶点着色器的妙用/Sample13_3/assets/vertex_landform.sh
Normal file
12
第13章 顶点着色器的妙用/Sample13_3/assets/vertex_landform.sh
Normal file
@@ -0,0 +1,12 @@
|
||||
//山地的顶点着色器
|
||||
uniform mat4 uMVPMatrix; //总变换矩阵
|
||||
attribute vec3 aPosition; //顶点位置
|
||||
attribute vec2 aTexCoor; //顶点纹理坐标
|
||||
varying vec2 vTextureCoord; //用于传递给片元着色器的变量
|
||||
varying float vertexHeight;//接受顶点的高度值
|
||||
void main()
|
||||
{
|
||||
gl_Position = uMVPMatrix * vec4(aPosition,1); //根据总变换矩阵计算此次绘制此顶点位置
|
||||
vTextureCoord = aTexCoor;//将接收的纹理坐标传递给片元着色器
|
||||
vertexHeight = aPosition.y;//将该顶点的高度传入片元着色器
|
||||
}
|
||||
10
第13章 顶点着色器的妙用/Sample13_3/assets/vertex_leaves.sh
Normal file
10
第13章 顶点着色器的妙用/Sample13_3/assets/vertex_leaves.sh
Normal file
@@ -0,0 +1,10 @@
|
||||
//叶子的顶点着色器
|
||||
uniform mat4 uMVPMatrix; //总变换矩阵
|
||||
attribute vec3 aPosition; //顶点位置
|
||||
attribute vec2 aTexCoor; //顶点纹理坐标
|
||||
varying vec2 vTextureCoord; //用于传递给片元着色器的变量
|
||||
void main()
|
||||
{
|
||||
gl_Position = uMVPMatrix * vec4(aPosition,1); //根据总变换矩阵计算此次绘制此顶点位置
|
||||
vTextureCoord = aTexCoor;//将接收的纹理坐标传递给片元着色器
|
||||
}
|
||||
12
第13章 顶点着色器的妙用/Sample13_3/assets/vertex_tex.sh
Normal file
12
第13章 顶点着色器的妙用/Sample13_3/assets/vertex_tex.sh
Normal file
@@ -0,0 +1,12 @@
|
||||
uniform mat4 uMVPMatrix; //总变换矩阵
|
||||
attribute vec3 aPosition; //顶点位置
|
||||
attribute vec2 aTexCoor; //顶点纹理坐标
|
||||
varying vec2 vTextureCoord; //用于传递给片元着色器的变量
|
||||
varying vec3 vVertexCoord;
|
||||
void main()
|
||||
{
|
||||
gl_Position = uMVPMatrix * vec4(aPosition,1); //根据总变换矩阵计算此次绘制此顶点位置
|
||||
vTextureCoord = aTexCoor;//将接收的纹理坐标传递给片元着色器
|
||||
vVertexCoord = aPosition;
|
||||
|
||||
}
|
||||
29
第13章 顶点着色器的妙用/Sample13_3/assets/vertex_tree.sh
Normal file
29
第13章 顶点着色器的妙用/Sample13_3/assets/vertex_tree.sh
Normal file
@@ -0,0 +1,29 @@
|
||||
//这里是树干节点的顶点着色器
|
||||
//这里的所有的偏转角都是相对于Z轴正方向来说的,逆时针旋转的
|
||||
uniform mat4 uMVPMatrix; //总变换矩阵
|
||||
uniform float bend_R;//这里指的是树的弯曲半径
|
||||
uniform float direction_degree;//这里指的风向,用角度表示的,沿Z轴正方向逆时针旋转
|
||||
attribute vec3 aPosition; //顶点位置
|
||||
attribute vec2 aTexCoor; //顶点纹理坐标
|
||||
varying vec2 vTextureCoord; //用于传递给片元着色器的变量
|
||||
void main()
|
||||
{
|
||||
//计算当前的弧度
|
||||
float curr_radian=aPosition.y/bend_R;
|
||||
//计算当前点的结果高度
|
||||
float result_height=bend_R*sin(curr_radian);
|
||||
//计算当前点的增加的长度
|
||||
float increase=bend_R-bend_R*cos(curr_radian);
|
||||
//计算当前点最后的x坐标
|
||||
float result_X=aPosition.x+increase*sin(radians(direction_degree));
|
||||
//计算当前点最后的z坐标
|
||||
float result_Z=aPosition.z+increase*cos(radians(direction_degree));
|
||||
//最后结果
|
||||
vec4 result_point=vec4(result_X,result_height,result_Z,1.0);
|
||||
gl_Position = uMVPMatrix * result_point; //根据总变换矩阵计算此次绘制此顶点位置
|
||||
vTextureCoord = aTexCoor;//将接收的纹理坐标传递给片元着色器
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
28
第13章 顶点着色器的妙用/Sample13_3/assets/vertex_water.sh
Normal file
28
第13章 顶点着色器的妙用/Sample13_3/assets/vertex_water.sh
Normal file
@@ -0,0 +1,28 @@
|
||||
uniform mat4 uMVPMatrix; //总变换矩阵
|
||||
uniform float uStartAngle;//本帧起始角度
|
||||
uniform float uWidthSpan;//横向长度总跨度
|
||||
attribute vec3 aPosition; //顶点位置
|
||||
attribute vec2 aTexCoor; //顶点纹理坐标
|
||||
varying vec2 vTextureCoord; //用于传递给片元着色器的变量
|
||||
void main()
|
||||
{
|
||||
|
||||
//计算X向角度
|
||||
float angleSpanH=30.0*3.14159265;//横向角度总跨度
|
||||
float startX=0.0;//起始X坐标
|
||||
//根据横向角度总跨度、横向长度总跨度及当前点X坐标折算出当前点X坐标对应的角度
|
||||
float currAngleH=uStartAngle+((aPosition.x-startX)/uWidthSpan)*angleSpanH;
|
||||
|
||||
//计算出随z向发展起始角度的扰动值
|
||||
float startZ=0.0;//起始z坐标
|
||||
//根据纵向角度总跨度、纵向长度总跨度及当前点Y坐标折算出当前点Y坐标对应的角度
|
||||
float currAngleZ=((aPosition.z-startZ)/uWidthSpan)*angleSpanH;
|
||||
|
||||
//计算斜向波浪
|
||||
float tzH=sin(currAngleH-currAngleZ)*0.8;
|
||||
//根据总变换矩阵计算此次绘制此顶点位置
|
||||
gl_Position = uMVPMatrix * vec4(aPosition.x,tzH,aPosition.z,1);
|
||||
|
||||
// gl_Position = uMVPMatrix * vec4(aPosition,1);
|
||||
vTextureCoord = aTexCoor;//将接收的纹理坐标传递给片元着色器
|
||||
}
|
||||
Reference in New Issue
Block a user