72 lines
2.3 KiB
JavaScript
72 lines
2.3 KiB
JavaScript
export default `
|
|
#define USE_CUBE_MAP_SHADOW true
|
|
uniform sampler2D colorTexture;
|
|
uniform sampler2D depthTexture;
|
|
varying vec2 v_textureCoordinates;
|
|
uniform mat4 camera_projection_matrix;
|
|
uniform mat4 camera_view_matrix;
|
|
uniform vec4 helsing_visibleAreaColor;
|
|
uniform vec4 helsing_invisibleAreaColor;
|
|
uniform sampler2D helsing_texture;
|
|
|
|
vec4 getPositionEC(){
|
|
return czm_windowToEyeCoordinates(gl_FragCoord);
|
|
}
|
|
|
|
vec3 getNormalEC(){
|
|
return vec3(1.);
|
|
}
|
|
|
|
vec4 toEye(in vec2 uv,in float depth){
|
|
vec2 xy=vec2((uv.x*2.-1.),(uv.y*2.-1.));
|
|
vec4 posInCamera=czm_inverseProjection*vec4(xy,depth,1.);
|
|
posInCamera=posInCamera/posInCamera.w;
|
|
return posInCamera;
|
|
}
|
|
|
|
vec3 pointProjectOnPlane(in vec3 planeNormal,in vec3 planeOrigin,in vec3 point){
|
|
vec3 v01=point-planeOrigin;
|
|
float d=dot(planeNormal,v01);
|
|
return(point-planeNormal*d);
|
|
}
|
|
|
|
float getDepth(in vec4 depth){
|
|
float z_window=czm_unpackDepth(depth);
|
|
z_window=czm_reverseLogDepth(z_window);
|
|
float n_range=czm_depthRange.near;
|
|
float f_range=czm_depthRange.far;
|
|
return(2.*z_window-n_range-f_range)/(f_range-n_range);
|
|
}
|
|
|
|
bool visible(in vec4 result)
|
|
{
|
|
result.x/=result.w;
|
|
result.y/=result.w;
|
|
result.z/=result.w;
|
|
return result.x>=-1.&&result.x<=1.
|
|
&&result.y>=-1.&&result.y<=1.
|
|
&&result.z>=-1.&&result.z<=1.;
|
|
}
|
|
|
|
void main(){
|
|
// 釉色 = 结构二维(颜色纹理, 纹理坐标)
|
|
gl_FragColor = texture2D(colorTexture, v_textureCoordinates);
|
|
// 深度 = 获取深度(结构二维(深度纹理, 纹理坐标))
|
|
float depth = getDepth(texture2D(depthTexture, v_textureCoordinates));
|
|
// 视角 = (纹理坐标, 深度)
|
|
vec4 positionEC = toEye(v_textureCoordinates, depth);
|
|
// 世界坐标
|
|
vec4 wordPos = czm_inverseView * positionEC;
|
|
// 虚拟相机中坐标
|
|
vec4 vcPos = camera_view_matrix * wordPos;
|
|
vec4 videoColor = texture2D(helsing_texture, v_textureCoordinates);
|
|
float dis = length(vcPos.xyz);
|
|
vec4 posInEye = camera_projection_matrix * vcPos;
|
|
// 可视区颜色
|
|
// vec4 helsing_visibleAreaColor=vec4(0.,1.,0.,.5);
|
|
// vec4 helsing_invisibleAreaColor=vec4(1.,0.,0.,.5);
|
|
if(visible(posInEye)){
|
|
vec4 out_FragColor = helsing_visibleAreaColor;
|
|
gl_FragColor = mix(gl_FragColor,videoColor,1.0);
|
|
}
|
|
}`; |