import ECEF from "./CoordinateTranslate";
let CesiumVideo3d = (function () {
var videoShed3dShader = `
uniform float mixNum;
uniform sampler2D colorTexture;
uniform sampler2D stcshadow;
uniform sampler2D videoTexture;
uniform sampler2D depthTexture;
uniform mat4 _shadowMap_matrix;
uniform vec4 shadowMap_lightPositionEC;
uniform vec4 shadowMap_normalOffsetScaleDistanceMaxDistanceAndDarkness;
uniform vec4 shadowMap_texelSizeDepthBiasAndNormalShadingSmooth;
in vec2 v_textureCoordinates;
vec4 toEye(in vec2 uv, in float depth){
vec2 xy = vec2((uv.x * 2.0 - 1.0),(uv.y * 2.0 - 1.0));
vec4 posInCamera =czm_inverseProjection * vec4(xy, depth, 1.0);
posInCamera =posInCamera / posInCamera.w;
return posInCamera;
}
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.0 * z_window - n_range - f_range) / (f_range - n_range);
}
float _czm_sampleShadowMap(sampler2D shadowMap, vec2 uv){
return texture(shadowMap, uv).r;
}
float _czm_shadowDepthCompare(sampler2D shadowMap, vec2 uv, float depth){
return step(depth, _czm_sampleShadowMap(shadowMap, uv));
}
float _czm_shadowVisibility(sampler2D shadowMap, czm_shadowParameters shadowParameters){
float depthBias = shadowParameters.depthBias;
float depth = shadowParameters.depth;
float nDotL = shadowParameters.nDotL;
float normalShadingSmooth = shadowParameters.normalShadingSmooth;
float darkness = shadowParameters.darkness;
vec2 uv = shadowParameters.texCoords;
depth -= depthBias;
vec2 texelStepSize = shadowParameters.texelStepSize;
float radius = 1.0;
float dx0 = -texelStepSize.x * radius;
float dy0 = -texelStepSize.y * radius;
float dx1 = texelStepSize.x * radius;
float dy1 = texelStepSize.y * radius;
float visibility =(
_czm_shadowDepthCompare(shadowMap, uv, depth)
+ _czm_shadowDepthCompare(shadowMap, uv + vec2(dx0, dy0), depth)
+ _czm_shadowDepthCompare(shadowMap, uv + vec2(0.0, dy0), depth)
+ _czm_shadowDepthCompare(shadowMap, uv + vec2(dx1, dy0), depth)
+ _czm_shadowDepthCompare(shadowMap, uv + vec2(dx0, 0.0), depth)
+ _czm_shadowDepthCompare(shadowMap, uv + vec2(dx1, 0.0), depth)
+ _czm_shadowDepthCompare(shadowMap, uv + vec2(dx0, dy1), depth)
+ _czm_shadowDepthCompare(shadowMap, uv + vec2(0.0, dy1), depth)
+ _czm_shadowDepthCompare(shadowMap, uv + vec2(dx1, dy1), depth)
) * (1.0 / 9.0);
return visibility;
}
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 ptm(vec3 pt){
return sqrt(pt.x*pt.x + pt.y*pt.y + pt.z*pt.z);
}
out vec4 vFragColor;
void main() {
const float PI = 3.141592653589793;
vec4 color = texture(colorTexture, v_textureCoordinates);
vec4 currD = texture(depthTexture, v_textureCoordinates);
if(currD.r>=1.0){
vFragColor = color;
return;
}
float depth = getDepth(currD);
vec4 positionEC = toEye(v_textureCoordinates, depth);
vec3 normalEC = vec3(1.0);
czm_shadowParameters shadowParameters;
shadowParameters.texelStepSize = shadowMap_texelSizeDepthBiasAndNormalShadingSmooth.xy;
shadowParameters.depthBias = shadowMap_texelSizeDepthBiasAndNormalShadingSmooth.z;
shadowParameters.normalShadingSmooth = shadowMap_texelSizeDepthBiasAndNormalShadingSmooth.w;
shadowParameters.darkness = shadowMap_normalOffsetScaleDistanceMaxDistanceAndDarkness.w;
shadowParameters.depthBias *= max(depth * 0.01, 1.0);
vec3 directionEC = normalize(positionEC.xyz - shadowMap_lightPositionEC.xyz);
float nDotL = clamp(dot(normalEC, -directionEC), 0.0, 1.0);
vec4 shadowPosition = _shadowMap_matrix * positionEC;
shadowPosition /= shadowPosition.w;
if (any(lessThan(shadowPosition.xyz, vec3(0.0))) || any(greaterThan(shadowPosition.xyz, vec3(1.0)))) {
vFragColor = color;
return;
}
shadowParameters.texCoords = shadowPosition.xy;
shadowParameters.depth = shadowPosition.z;
shadowParameters.nDotL = nDotL;
float visibility = _czm_shadowVisibility(stcshadow, shadowParameters);
vec4 videoColor = texture(videoTexture,shadowPosition.xy);
if(visibility==1.0){
vFragColor = mix(color,vec4(videoColor.xyz,1.0),mixNum*videoColor.a);
}else{
vFragColor = color;
}
} `
var Cesium = null;
var videoShed3d = function (cesium, viewer, param) {
Cesium = cesium;
this.ECEF = new ECEF();
this.param = param;
var option = this._initCameraParam();
this.optionType = {
Color: 1,
Image: 2,
Video: 3,
};
this.near = option.near ? option.near : 0.1;
if (
(option || (option = {}),
(this.viewer = viewer),
(this._cameraPosition = option.cameraPosition),
(this._position = option.position),
(this.type = option.type),
(this._alpha = option.alpha || 1),
(this.url = option.url),
(this.color = option.color),
(this._debugFrustum = Cesium.defaultValue(option.debugFrustum, !0)),
(this._aspectRatio = option.aspectRatio || this._getWinWidHei()),
(this._camerafov =
option.fov ||
Cesium.Math.toDegrees(this.viewer.scene.camera.frustum.fov)),
(this.texture =
option.texture ||
new Cesium.Texture({
context: this.viewer.scene.context,
source: {
width: 1,
height: 1,
arrayBufferView: new Uint8Array([255, 255, 255, 255]),
},
flipY: !1,
})),
(this._videoPlay = Cesium.defaultValue(option.videoPlay, !0)),
(this.defaultShow = Cesium.defaultValue(option.show, !0)),
!this.cameraPosition || !this.position)
)
return void console.log("初始化失败:请确认相机位置与视点位置正确!");
switch (this.type) {
default:
case this.optionType.Video:
this.activeVideo(this.url);
break;
case this.optionType.Image:
this.activePicture(this.url);
this.deActiveVideo();
break;
case this.optionType.Color:
this.activeColor(this.color), this.deActiveVideo();
}
this._createShadowMap(),
this._getOrientation(), this._addCameraFrustum();
this._addPostProcess();
this.viewer.scene.primitives.add(this);
};
Object.defineProperties(videoShed3d.prototype, {
alpha: {
get: function () {
return this._alpha;
},
set: function (e) {
return (this._alpha = e);
},
},
aspectRatio: {
get: function () {
return this._aspectRatio;
},
set: function (e) {
(this._aspectRatio = e), this._changeVideoWidHei();
},
},
debugFrustum: {
get: function () {
return this._debugFrustum;
},
set: function (e) {
(this._debugFrustum = e), (this.cameraFrustum.show = e);
},
},
fov: {
get: function () {
return this._camerafov;
},
set: function (e) {
(this._camerafov = e), this._changeCameraFov();
}
没有合适的资源?快使用搜索试试~ 我知道了~
基于cesium实现视频投射功能
共2个文件
js:2个
需积分: 5 18 下载量 77 浏览量
2023-11-09
16:57:23
上传
评论
收藏 7KB RAR 举报
温馨提示
使用cesium实现视频投射,在三维模型上展示实时视频
资源推荐
资源详情
资源评论
收起资源包目录
视频投射.rar (2个子文件)
视频投射
CoordinateTranslate.js 7KB
CesiumVideo3d.js 23KB
共 2 条
- 1
资源评论
cjh1126a
- 粉丝: 2
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功