2019-07-04 17:47:24 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2018-2019 Xiamen Yaji Software Co., Ltd.
|
|
|
|
|
2022-10-01 16:24:52 +08:00
|
|
|
https://axmolengine.github.io/
|
2019-07-04 17:47:24 +08:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-03-30 13:45:50 +08:00
|
|
|
|
2019-01-30 09:35:17 +08:00
|
|
|
const char* CC3D_terrain_frag = R"(
|
2016-10-26 16:03:08 +08:00
|
|
|
#ifdef GL_ES
|
2015-10-15 11:59:38 +08:00
|
|
|
precision mediump float;
|
2016-10-26 16:03:08 +08:00
|
|
|
#endif
|
|
|
|
uniform vec3 u_color;
|
|
|
|
varying vec2 v_texCoord;
|
|
|
|
varying vec3 v_normal;
|
|
|
|
#ifdef GL_ES
|
|
|
|
uniform lowp int u_has_alpha;
|
|
|
|
uniform lowp int u_has_light_map;
|
|
|
|
#else
|
|
|
|
uniform int u_has_alpha;
|
|
|
|
uniform int u_has_light_map;
|
|
|
|
#endif
|
|
|
|
uniform sampler2D u_alphaMap;
|
2022-07-04 21:26:48 +08:00
|
|
|
uniform sampler2D u_tex0;
|
|
|
|
uniform sampler2D u_tex1;
|
|
|
|
uniform sampler2D u_tex2;
|
|
|
|
uniform sampler2D u_tex3;
|
2016-10-26 16:03:08 +08:00
|
|
|
uniform sampler2D u_lightMap;
|
|
|
|
uniform float u_detailSize[4];
|
|
|
|
uniform vec3 u_lightDir;
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
vec4 lightColor;
|
|
|
|
if(u_has_light_map<=0)
|
|
|
|
{
|
|
|
|
lightColor = vec4(1.0,1.0,1.0,1.0);
|
|
|
|
}else
|
|
|
|
{
|
|
|
|
lightColor = texture2D(u_lightMap,v_texCoord);
|
2015-07-29 13:24:12 +08:00
|
|
|
}
|
2016-10-26 16:03:08 +08:00
|
|
|
float lightFactor = dot(-u_lightDir,v_normal);
|
|
|
|
if(u_has_alpha<=0)
|
|
|
|
{
|
2022-07-04 21:26:48 +08:00
|
|
|
gl_FragColor = texture2D(u_tex0, v_texCoord)*lightColor*lightFactor;
|
2016-10-26 16:03:08 +08:00
|
|
|
}else
|
|
|
|
{
|
|
|
|
vec4 blendFactor =texture2D(u_alphaMap,v_texCoord);
|
|
|
|
vec4 color = vec4(0.0,0.0,0.0,0.0);
|
2022-07-04 21:26:48 +08:00
|
|
|
color = texture2D(u_tex0, v_texCoord*u_detailSize[0])*blendFactor.r +
|
|
|
|
texture2D(u_tex1, v_texCoord*u_detailSize[1])*blendFactor.g + texture2D(u_tex2, v_texCoord*u_detailSize[2])*blendFactor.b
|
|
|
|
+ texture2D(u_tex3, v_texCoord*u_detailSize[3])*(1.0 - blendFactor.a);
|
2015-07-29 13:24:12 +08:00
|
|
|
gl_FragColor = vec4(color.rgb*lightColor.rgb*lightFactor, 1.0);
|
2015-03-30 13:45:50 +08:00
|
|
|
}
|
|
|
|
}
|
2016-11-02 14:13:34 +08:00
|
|
|
)";
|