Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
86 changes: 86 additions & 0 deletions ImageDrapingFS.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
//This file is automatically rebuilt by the Cesium build process.
/*global define*/
define(function() {
'use strict';
return "varying vec3 v_positionEC;\n\
varying vec3 v_normalEC;\n\
varying vec2 v_st;\n\
\n\
\n\
vec4 windowToEye(vec4 fragCoord)\n\
{\n\
vec2 uv = fragCoord.xy / czm_viewport.zw;\n\
float z_window = czm_unpackDepth(texture2D(czm_globeDepthTexture, uv));\n\
if (z_window == 1.0)\n\
discard;\n\
\n\
float near = czm_depthRange.near;\n\
float far = czm_depthRange.far;\n\
\n\
vec3 ndcPos;\n\
ndcPos.x = 2.0 * (fragCoord.x - czm_viewport.x) / czm_viewport.z - 1.0;\n\
ndcPos.y = 2.0 * (fragCoord.y - czm_viewport.y) / czm_viewport.w - 1.0;\n\
ndcPos.z = (2.0 * z_window - near - far) / (far - near);\n\
\n\
vec4 clipPos;\n\
clipPos.w = czm_projection[3][2] / (ndcPos.z - (czm_projection[2][2] / czm_projection[2][3]));\n\
clipPos.xyz = ndcPos * clipPos.w;\n\
\n\
return czm_inverseProjection * clipPos;\n\
//return vec4(ndcPos, 1.0);\n\
}\n\
\n\
\n\
// Camera model and frames are based on OpenCV conventions:\n\
// http://docs.opencv.org/2.4/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html\n\
// we pass in a normalized intrinsic matrix as uniform so we can compute the normalized texture coordinates directly\n\
void main()\n\
{\n\
vec3 positionToEyeEC = -v_positionEC; \n\
\n\
// get fragment 3D pos in eye coordinates using depth buffer value at fragment location\n\
vec4 v_posEC = windowToEye(gl_FragCoord);\n\
\n\
// translate to video cam frame\n\
vec4 camPosEC = czm_modelViewRelativeToEye * czm_translateRelativeToEye(camPosHigh_1, camPosLow_2); \n\
vec4 v_posCam = v_posEC - camPosEC;\n\
\n\
// rotate to video cam frame\n\
vec3 lookRay = camAtt_3*czm_inverseViewRotation3D*v_posCam.xyz;\n\
\n\
// discard if behind camera\n\
if (lookRay.z < 0.1)\n\
discard;\n\
\n\
// undistort\n\
float xn = lookRay.x / lookRay.z;\n\
float yn = lookRay.y / lookRay.z;\n\
float k1 = camDistR_5[0];\n\
float k2 = camDistR_5[1];\n\
float k3 = camDistR_5[2];\n\
float p1 = camDistT_6[0];\n\
float p2 = camDistT_6[1];\n\
float r2 = xn*xn+yn*yn;\n\
float r4 = r2*r2;\n\
float r6 = r4*r2;\n\
float xd = xn*(1. + k1*r2 + k2*r4 + k3*r6) + 2.*p1*xn*yn + p2*(r2 + 2.*xn*xn);\n\
float yd = yn*(1. + k1*r2 + k2*r4 + k3*r6) + 2.*p2*xn*yn + p1*(r2 + 2.*yn*yn);\n\
\n\
// project with pinhole model\n\
vec3 st = camProj_4 * vec3(xd, yd, 1.);\n\
st.y = 1.0 - st.y; \n\
if (st.x < 0.0 || st.x > 1.0 || st.y < 0.0 || st.y > 1.0)\n\
discard;\n\
\n\
// get color from material \n\
czm_materialInput materialInput;\n\
materialInput.positionToEyeEC = positionToEyeEC;\n\
materialInput.st = vec2(st.x, st.y);\n\
czm_material material = czm_getMaterial(materialInput); \n\
gl_FragColor = vec4(material.diffuse + material.emission, material.alpha);\n\
\n\
//float depth = pow(v_posEC.z * 0.5 + 0.5, 8.0);\n\
//gl_FragColor = vec4(depth, depth, depth, 1.0);\n\
}\n\
";
});
25 changes: 25 additions & 0 deletions ImageDrapingVS.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//This file is automatically rebuilt by the Cesium build process.
/*global define*/
define(function() {
'use strict';
return "attribute vec3 position3DHigh;\n\
attribute vec3 position3DLow;\n\
attribute vec3 normal;\n\
attribute vec2 st;\n\
\n\
varying vec3 v_positionEC;\n\
varying vec3 v_normalEC;\n\
varying vec2 v_st;\n\
\n\
void main() \n\
{\n\
vec4 p = czm_computePosition();\n\
\n\
v_positionEC = (czm_modelViewRelativeToEye * p).xyz; // position in eye coordinates\n\
v_normalEC = czm_normal * normal; // normal in eye coordinates\n\
v_st = st;\n\
\n\
gl_Position = czm_modelViewProjectionRelativeToEye * p;\n\
}\n\
";
});
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<TileMap version="1.0.0" tilemapservice="http://tms.osgeo.org/1.0.0">
<Title>NE2_HR_LC_SR_W_DR_recolored.tif</Title>
<Abstract></Abstract>
<SRS>EPSG:4326</SRS>
<BoundingBox miny="-90.00000000000000" minx="-180.00000000000000" maxy="90.00000000000000" maxx="180.00000000000000"/>
<Origin y="-90.00000000000000" x="-180.00000000000000"/>
<TileFormat width="256" height="256" mime-type="image/jpg" extension="jpg"/>
<TileSets profile="geodetic">
<TileSet href="0" units-per-pixel="0.70312500000000" order="0"/>
<TileSet href="1" units-per-pixel="0.35156250000000" order="1"/>
<TileSet href="2" units-per-pixel="0.17578125000000" order="2"/>
</TileSets>
</TileMap>
<?xml version="1.0" encoding="utf-8"?>
<TileMap version="1.0.0" tilemapservice="http://tms.osgeo.org/1.0.0">
<Title>NE2_HR_LC_SR_W_DR_recolored.tif</Title>
<Abstract></Abstract>
<SRS>EPSG:4326</SRS>
<BoundingBox miny="-90.00000000000000" minx="-180.00000000000000" maxy="90.00000000000000" maxx="180.00000000000000"/>
<Origin y="-90.00000000000000" x="-180.00000000000000"/>
<TileFormat width="256" height="256" mime-type="image/jpg" extension="jpg"/>
<TileSets profile="geodetic">
<TileSet href="0" units-per-pixel="0.70312500000000" order="0"/>
<TileSet href="1" units-per-pixel="0.35156250000000" order="1"/>
<TileSet href="2" units-per-pixel="0.17578125000000" order="2"/>
</TileSets>
</TileMap>
Loading