CESIUM内置shader变量和函数[转]

摘要:
cesium中内置了一些常量、变量和函数,在vs和fs中可直接使用。内置uniform内置uniform主要置于AutomaticUniforms类里面,该类私有未开放文档。
cesium中内置了一些常量、变量和函数,在vs和fs中可直接使用。

内置uniform

内置uniform主要置于AutomaticUniforms类里面,该类私有未开放文档。

  • czm_backgroundColor

An automatic GLSL uniform representing the current scene background color.

Example:
// GLSL declaration
uniform vec4 czm_backgroundColor;
// Example: If the given color's RGB matches the background color, invert it.
vec4 adjustColorForContrast(vec4 color)
{
    if (czm_backgroundColor.rgb == color.rgb)
    {
        color.rgb = vec3(1.0) - color.rgb;
    }
    return color;
}
  • czm_brdfLut

An automatic GLSL uniform containing the BRDF look up texture used for image-based lighting computations.

Example:
// GLSL declaration
uniform sampler2D czm_brdfLut;
// Example: For a given roughness and NdotV value, find the material's BRDF information in the red and green channels
float roughness = 0.5;
float NdotV = dot(normal, view);
vec2 brdfLut = texture2D(czm_brdfLut, vec2(NdotV, 1.0 - roughness)).rg;

An automatic GLSL uniform containing the near distance (x) and the far distance (y) of the frustum defined by the camera. This is the individual frustum used for multi-frustum rendering.

Example:
// GLSL declaration
uniform vec2 czm_currentFrustum;
// Example
float frustumLength = czm_currentFrustum.y - czm_currentFrustum.x;

An automatic GLSL uniform representing the high bits of the camera position in model coordinates. This is used for GPU RTE to eliminate jittering artifacts when rendering as described inPrecisions, Precisions.

Example:
// GLSL declaration
uniform vec3 czm_encodedCameraPositionMCHigh;

An automatic GLSL uniform representing the low bits of the camera position in model coordinates. This is used for GPU RTE to eliminate jittering artifacts when rendering as described inPrecisions, Precisions.

Example:
// GLSL declaration
uniform vec3 czm_encodedCameraPositionMCLow;

An automatic GLSL uniform containing the near distance (x) and the far distance (y) of the frustum defined by the camera. This is the largest possible frustum, not an individual frustum used for multi-frustum rendering.

Example:
// GLSL declaration
uniform vec2 czm_entireFrustum;
// Example
float frustumLength = czm_entireFrustum.y - czm_entireFrustum.x;
  • czm_environmentMap

An automatic GLSL uniform containing the environment map used within the scene.

Example:
// GLSL declaration
uniform samplerCube czm_environmentMap;
// Example: Create a perfect reflection of the environment map on a  model
float reflected = reflect(view, normal);
vec4 reflectedColor = textureCube(czm_environmentMap, reflected);

An automatic GLSL uniform containing height (x) and height squared (y) of the eye (camera) in the 2D scene in meters.

  • czm_fogDensity

An automatic GLSL uniform scalar used to mix a color with the fog color based on the distance to the camera.

An automatic GLSL uniform representing the frame number. This uniform is automatically incremented every frame.

  • czm_frustumPlanes

The distances to the frustum planes. The top, bottom, left and right distances are the x, y, z, and w components, respectively.

  • czm_geometricToleranceOverMeter

An automatic GLSL uniform scalar representing the geometric tolerance per meter

  • czm_imagerySplitPosition

An automatic GLSL uniform representing the splitter position to use when rendering imagery layers with a splitter. This will be in pixel coordinates relative to the canvas.

An automatic GLSL uniform representing a 4x4 projection transformation matrix with the far plane at infinity, that transforms eye coordinates to clip coordinates. Clip coordinates is the coordinate system for a vertex shader'sgl_Positionoutput. An infinite far plane is used in algorithms like shadow volumes and GPU ray casting with proxy geometry to ensure that triangles are not clipped by the far plane.

Example:
// GLSL declaration
uniform mat4 czm_infiniteProjection;
// Example
gl_Position = czm_infiniteProjection * eyePosition;

An automatic GLSL uniform representing a 4x4 model transformation matrix that transforms world coordinates to model coordinates.

Example:
// GLSL declaration
uniform mat4 czm_inverseModel;
// Example
vec4 modelPosition = czm_inverseModel * worldPosition;

An automatic GLSL uniform representing a 4x4 transformation matrix that transforms from eye coordinates to model coordinates.

Example:
// GLSL declaration
uniform mat4 czm_inverseModelView;
// Example
vec4 modelPosition = czm_inverseModelView * eyePosition;

An automatic GLSL uniform representing a 4x4 transformation matrix that transforms from eye coordinates to 3D model coordinates. In 3D mode, this is identical toczm_inverseModelView, but in 2D and Columbus View it represents the inverse model-view matrix as if the camera were at an equivalent location in 3D mode. This is useful for lighting 2D and Columbus View in the same way that 3D is lit.

Example:
// GLSL declaration
uniform mat4 czm_inverseModelView3D;
// Example
vec4 modelPosition = czm_inverseModelView3D * eyePosition;

An automatic GLSL uniform representing a 4x4 inverse model-view-projection transformation matrix that transforms clip coordinates to model coordinates. Clip coordinates is the coordinate system for a vertex shader'sgl_Positionoutput.

Example:
// GLSL declaration
uniform mat4 czm_inverseModelViewProjection;
// Example
vec4 modelPosition = czm_inverseModelViewProjection * clipPosition;

An automatic GLSL uniform representing a 3x3 normal transformation matrix that transforms normal vectors in eye coordinates to model coordinates. This is the opposite of the transform provided byczm_normal.

Example:
// GLSL declaration
uniform mat3 czm_inverseNormal;
// Example
vec3 normalMC = czm_inverseNormal * normalEC;

An automatic GLSL uniform representing a 3x3 normal transformation matrix that transforms normal vectors in eye coordinates to 3D model coordinates. This is the opposite of the transform provided byczm_normal. In 3D mode, this is identical toczm_inverseNormal, but in 2D and Columbus View it represents the inverse normal transformation matrix as if the camera were at an equivalent location in 3D mode. This is useful for lighting 2D and Columbus View in the same way that 3D is lit.

Example:
// GLSL declaration
uniform mat3 czm_inverseNormal3D;
// Example
vec3 normalMC = czm_inverseNormal3D * normalEC;

An automatic GLSL uniform representing a 4x4 inverse projection transformation matrix that transforms from clip coordinates to eye coordinates. Clip coordinates is the coordinate system for a vertex shader'sgl_Positionoutput.

Example:
// GLSL declaration
uniform mat4 czm_inverseProjection;
// Example
vec4 eyePosition = czm_inverseProjection * clipPosition;

An automatic GLSL uniform representing a 4x4 transformation matrix that transforms from eye coordinates to world coordinates.

Example:
// GLSL declaration
uniform mat4 czm_inverseView;
// Example
vec4 worldPosition = czm_inverseView * eyePosition;

An automatic GLSL uniform representing a 4x4 transformation matrix that transforms from 3D eye coordinates to world coordinates. In 3D mode, this is identical toczm_inverseView, but in 2D and Columbus View it represents the inverse view matrix as if the camera were at an equivalent location in 3D mode. This is useful for lighting 2D and Columbus View in the same way that 3D is lit.

Example:
// GLSL declaration
uniform mat4 czm_inverseView3D;
// Example
vec4 worldPosition = czm_inverseView3D * eyePosition;

An automatic GLSL uniform representing a 4x4 view-projection transformation matrix that transforms clip coordinates to world coordinates. Clip coordinates is the coordinate system for a vertex shader'sgl_Positionoutput.

Example:
// GLSL declaration
uniform mat4 czm_inverseViewProjection;
// Example
vec4 worldPosition = czm_inverseViewProjection * clipPosition;

An automatic GLSL uniform representing a 3x3 rotation matrix that transforms vectors from eye coordinates to world coordinates.

Example:
// GLSL declaration
uniform mat3 czm_inverseViewRotation;
// Example
vec4 worldVector = czm_inverseViewRotation * eyeVector;

An automatic GLSL uniform representing a 3x3 rotation matrix that transforms vectors from 3D eye coordinates to world coordinates. In 3D mode, this is identical toczm_inverseViewRotation, but in 2D and Columbus View it represents the inverse view matrix as if the camera were at an equivalent location in 3D mode. This is useful for lighting 2D and Columbus View in the same way that 3D is lit.

Example:
// GLSL declaration
uniform mat3 czm_inverseViewRotation3D;
// Example
vec4 worldVector = czm_inverseViewRotation3D * eyeVector;
  • czm_invertClassificationColor

An automatic GLSL uniform that will be the highlight color of unclassified 3D Tiles.

  • czm_log2FarPlusOne

An automatic GLSL uniform containing log2 of the far distance + 1.0. This is used when reversing log depth computations.

  • czm_log2NearDistance

An automatic GLSL uniform containing log2 of the near distance. This is used when writing log depth in the fragment shader.

  • czm_minimumDisableDepthTestDistance

An automatic GLSL uniform representing the distance from the camera at which to disable the depth test of billboards, labels and points to, for example, prevent clipping against terrain. When set to zero, the depth test should always be applied. When less than zero, the depth test should never be applied.

An automatic GLSL uniform representing a 4x4 model transformation matrix that transforms model coordinates to world coordinates.

Example:
// GLSL declaration
uniform mat4 czm_model;
// Example
vec4 worldPosition = czm_model * modelPosition;

An automatic GLSL uniform representing a 4x4 model-view transformation matrix that transforms model coordinates to eye coordinates.
Positions should be transformed to eye coordinates usingczm_modelViewand normals should be transformed usingczm_normal.

Example:
// GLSL declaration
uniform mat4 czm_modelView;
// Example
vec4 eyePosition = czm_modelView * modelPosition;
// The above is equivalent to, but more efficient than:
vec4 eyePosition = czm_view * czm_model * modelPosition;

An automatic GLSL uniform representing a 4x4 model-view transformation matrix that transforms 3D model coordinates to eye coordinates. In 3D mode, this is identical toczm_modelView, but in 2D and Columbus View it represents the model-view matrix as if the camera were at an equivalent location in 3D mode. This is useful for lighting 2D and Columbus View in the same way that 3D is lit.
Positions should be transformed to eye coordinates usingczm_modelView3Dand normals should be transformed usingczm_normal3D.

Example:
// GLSL declaration
uniform mat4 czm_modelView3D;
// Example
vec4 eyePosition = czm_modelView3D * modelPosition;
// The above is equivalent to, but more efficient than:
vec4 eyePosition = czm_view3D * czm_model * modelPosition;

An automatic GLSL uniform representing a 4x4 model-view-projection transformation matrix that transforms model coordinates to clip coordinates. Clip coordinates is the coordinate system for a vertex shader'sgl_Positionoutput. The projection matrix places the far plane at infinity. This is useful in algorithms like shadow volumes and GPU ray casting with proxy geometry to ensure that triangles are not clipped by the far plane.

Example:
// GLSL declaration
uniform mat4 czm_modelViewInfiniteProjection;
// Example
vec4 gl_Position = czm_modelViewInfiniteProjection * modelPosition;
// The above is equivalent to, but more efficient than:
gl_Position = czm_infiniteProjection * czm_view * czm_model * modelPosition;

An automatic GLSL uniform representing a 4x4 model-view-projection transformation matrix that transforms model coordinates to clip coordinates. Clip coordinates is the coordinate system for a vertex shader'sgl_Positionoutput.

Example:
// GLSL declaration
uniform mat4 czm_modelViewProjection;
// Example
vec4 gl_Position = czm_modelViewProjection * modelPosition;
// The above is equivalent to, but more efficient than:
gl_Position = czm_projection * czm_view * czm_model * modelPosition;

An automatic GLSL uniform representing a 4x4 model-view-projection transformation matrix that transforms model coordinates, relative to the eye, to clip coordinates. Clip coordinates is the coordinate system for a vertex shader'sgl_Positionoutput. This is used in conjunction with czm_translateRelativeToEye.

Example:
// GLSL declaration
uniform mat4 czm_modelViewProjectionRelativeToEye;
// Example
attribute vec3 positionHigh;
attribute vec3 positionLow;
void main()
{
  vec4 p = czm_translateRelativeToEye(positionHigh, positionLow);
  gl_Position = czm_modelViewProjectionRelativeToEye * p;
}

An automatic GLSL uniform representing a 4x4 model-view transformation matrix that transforms model coordinates, relative to the eye, to eye coordinates. This is used in conjunction with czm_translateRelativeToEye.

Example:
// GLSL declaration
uniform mat4 czm_modelViewRelativeToEye;
// Example
attribute vec3 positionHigh;
attribute vec3 positionLow;
void main()
{
  vec4 p = czm_translateRelativeToEye(positionHigh, positionLow);
  gl_Position = czm_projection * (czm_modelViewRelativeToEye * p);
}

An automatic GLSL uniform representing the normalized direction to the moon in eye coordinates. This is commonly used for directional lighting computations.

Example:
// GLSL declaration
uniform vec3 czm_moonDirectionEC;
// Example
float diffuse = max(dot(czm_moonDirectionEC, normalEC), 0.0);

An automatic GLSL uniform representing the current morph transition time between 2D/Columbus View and 3D, with 0.0 being 2D or Columbus View and 1.0 being 3D.

Example:
// GLSL declaration
uniform float czm_morphTime;
// Example
vec4 p = czm_columbusViewMorph(position2D, position3D, czm_morphTime);

An automatic GLSL uniform representing a 3x3 normal transformation matrix that transforms normal vectors in model coordinates to eye coordinates.
Positions should be transformed to eye coordinates usingczm_modelViewand normals should be transformed usingczm_normal.

Example:
// GLSL declaration
uniform mat3 czm_normal;
// Example
vec3 eyeNormal = czm_normal * normal;

An automatic GLSL uniform representing a 3x3 normal transformation matrix that transforms normal vectors in 3D model coordinates to eye coordinates. In 3D mode, this is identical toczm_normal, but in 2D and Columbus View it represents the normal transformation matrix as if the camera were at an equivalent location in 3D mode. This is useful for lighting 2D and Columbus View in the same way that 3D is lit.
Positions should be transformed to eye coordinates usingczm_modelView3Dand normals should be transformed usingczm_normal3D.

Example:
// GLSL declaration
uniform mat3 czm_normal3D;
// Example
vec3 eyeNormal = czm_normal3D * normal;
  • czm_orthographicIn3D

An automatic GLSL uniform that indicates if the current camera is orthographic in 3D.

  • czm_pass

An automatic GLSL uniform representing the current rendering pass.

Example:
// GLSL declaration
uniform float czm_pass;
// Example
if ((czm_pass == czm_passTranslucent) && isOpaque())
{
    gl_Position *= 0.0; // Cull opaque geometry in the translucent pass
}

An automatic GLSL uniform representing a 4x4 projection transformation matrix that transforms eye coordinates to clip coordinates. Clip coordinates is the coordinate system for a vertex shader'sgl_Positionoutput.

Example:
// GLSL declaration
uniform mat4 czm_projection;
// Example
gl_Position = czm_projection * eyePosition;
  • czm_resolutionScale

An automatic GLSL uniform representing the ratio of canvas coordinate space to canvas pixel space.

Example:
uniform float czm_resolutionScale;
  • czm_sceneMode

An automatic GLSL uniform representing the current SceneMode, expressed as a float.

Example:
// GLSL declaration
uniform float czm_sceneMode;
// Example
if (czm_sceneMode == czm_sceneMode2D)
{
    eyeHeightSq = czm_eyeHeight2D.y;
}

An automatic GLSL uniform representing the normalized direction to the sun in eye coordinates. This is commonly used for directional lighting computations.

Example:
// GLSL declaration
uniform vec3 czm_sunDirectionEC;
// Example
float diffuse = max(dot(czm_sunDirectionEC, normalEC), 0.0);

An automatic GLSL uniform representing the normalized direction to the sun in world coordinates. This is commonly used for directional lighting computations.

Example:
// GLSL declaration
uniform vec3 czm_sunDirectionWC;

An automatic GLSL uniform representing the sun position in Columbus view world coordinates.

Example:
// GLSL declaration
uniform vec3 czm_sunPositionColumbusView;

An automatic GLSL uniform representing the sun position in world coordinates.

Example:
// GLSL declaration
uniform vec3 czm_sunPositionWC;

An automatic GLSL uniform representing a 3x3 rotation matrix that transforms from True Equator Mean Equinox (TEME) axes to the pseudo-fixed axes at the current scene time.

Example:
// GLSL declaration
uniform mat3 czm_temeToPseudoFixed;
// Example
vec3 pseudoFixed = czm_temeToPseudoFixed * teme;

An automatic GLSL uniform representing a 4x4 view transformation matrix that transforms world coordinates to eye coordinates.

Example:
// GLSL declaration
uniform mat4 czm_view;
// Example
vec4 eyePosition = czm_view * worldPosition;

An automatic GLSL uniform representing a 4x4 view transformation matrix that transforms 3D world coordinates to eye coordinates. In 3D mode, this is identical toczm_view, but in 2D and Columbus View it represents the view matrix as if the camera were at an equivalent location in 3D mode. This is useful for lighting 2D and Columbus View in the same way that 3D is lit.

Example:
// GLSL declaration
uniform mat4 czm_view3D;
// Example
vec4 eyePosition3D = czm_view3D * worldPosition3D;

An automatic GLSL uniform representing the position of the viewer (camera) in world coordinates.

An automatic GLSL uniform containing the viewport'sx,y,width, andheightproperties in anvec4'sx,y,z, andwcomponents, respectively.

Example:
// GLSL declaration
uniform vec4 czm_viewport;
// Scale the window coordinate components to [0, 1] by dividing
// by the viewport's width and height.
vec2 v = gl_FragCoord.xy / czm_viewport.zw;

An automatic GLSL uniform representing a 4x4 orthographic projection matrix that transforms window coordinates to clip coordinates. Clip coordinates is the coordinate system for a vertex shader'sgl_Positionoutput.
This transform is useful when a vertex shader inputs or manipulates window coordinates as done by BillboardCollection.
Do not confuseczm_viewportTransformationwithczm_viewportOrthographic. The former transforms from normalized device coordinates to window coordinates; the later transforms from window coordinates to clip coordinates, and is often used to assign togl_Position.

Example:
// GLSL declaration
uniform mat4 czm_viewportOrthographic;
// Example
gl_Position = czm_viewportOrthographic * vec4(windowPosition, 0.0, 1.0);

An automatic GLSL uniform representing a 4x4 transformation matrix that transforms normalized device coordinates to window coordinates. The context's full viewport is used, and the depth range is assumed to benear = 0andfar = 1.
This transform is useful when there is a need to manipulate window coordinates in a vertex shader as done by BillboardCollection. In many cases, this matrix will not be used directly; instead, czm_modelToWindowCoordinates will be used to transform directly from model to window coordinates.
Do not confuseczm_viewportTransformationwithczm_viewportOrthographic. The former transforms from normalized device coordinates to window coordinates; the later transforms from window coordinates to clip coordinates, and is often used to assign togl_Position.

Example:
// GLSL declaration
uniform mat4 czm_viewportTransformation;
// Use czm_viewportTransformation as part of the
// transform from model to window coordinates.
vec4 q = czm_modelViewProjection * positionMC;               // model to clip coordinates
q.xyz /= q.w;                                                // clip to normalized device coordinates (ndc)
q.xyz = (czm_viewportTransformation * vec4(q.xyz, 1.0)).xyz; // ndc to window coordinates

An automatic GLSL uniform representing a 4x4 view-projection transformation matrix that transforms world coordinates to clip coordinates. Clip coordinates is the coordinate system for a vertex shader'sgl_Positionoutput.

Example:
// GLSL declaration
uniform mat4 czm_viewProjection;
// Example
vec4 gl_Position = czm_viewProjection * czm_model * modelPosition;
// The above is equivalent to, but more efficient than:
gl_Position = czm_projection * czm_view * czm_model * modelPosition;

An automatic GLSL uniform representing a 3x3 view rotation matrix that transforms vectors in world coordinates to eye coordinates.

Example:
// GLSL declaration
uniform mat3 czm_viewRotation;
// Example
vec3 eyeVector = czm_viewRotation * worldVector;

An automatic GLSL uniform representing a 3x3 view rotation matrix that transforms vectors in 3D world coordinates to eye coordinates. In 3D mode, this is identical toczm_viewRotation, but in 2D and Columbus View it represents the view matrix as if the camera were at an equivalent location in 3D mode. This is useful for lighting 2D and Columbus View in the same way that 3D is lit.

Example:
// GLSL declaration
uniform mat3 czm_viewRotation3D;
// Example
vec3 eyeVector = czm_viewRotation3D * worldVector;

内置常量

这里常量和函数的定义,在cesium官网的一个历史文档里有描述,后来版本的文档里没有了。

https://cesiumjs.org/releases/b28/Documentation/index.html

点击glsl,可以看到。

  • czm_epsilon6
  • czm_epsilon7
  • czm_infinity
  • czm_oneOverPi
  • czm_oneOverTwoPi
  • czm_passCesium3DTile
  • czm_passCesium3DTileClassification
  • czm_passCesium3DTileClassificationIgnoreShow
  • czm_passClassification
  • czm_passCompute
  • czm_passEnvironment
  • czm_passGlobe
  • czm_passOpaque
  • czm_passOverlay
  • czm_passTerrainClassification
  • czm_passTranslucent
  • czm_pi
  • czm_piOverFour
  • czm_piOverSix
  • czm_piOverThree
  • czm_piOverTwo
  • czm_radiansPerDegree
  • czm_sceneMode
  • czm_sceneMode2D

内置结构体定义

内置函数

czm_alphaWeight

原文:https://www.cnblogs.com/wanghui2011/articles/10870294.html

免责声明:文章转载自《CESIUM内置shader变量和函数[转]》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Awk命令delphi 集合类型探究下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Android RecyclerView 快速平滑返回顶部

先看下实现的效果,没效果什么都白扯 下面直接上方法: //目标项是否在最后一个可见项之后 private booleanmShouldScroll; //记录目标项位置 private intmToPosition; //目标项是否在最后一个可见项之后 private boolean mShouldScroll; //记录目标项位...

js截取指定长度字符

Code/// <summary> /// 截取指定长度的(中英文)字符 /// </summary>function curStr(str,length) {     var position=0;     var result=[];     for (var i = 0; i < str.length; i++)   ...

node.js 实现接口-操作文件进行用户增删改查

首先安装npm,使用npm安装express npm install express -S /* * @Author: yinxin * @Date: 2020-03-27 10:18:41 * @LastEditTime: 2020-03-30 20:17:26 * @LastEditors: Please set LastEditors...

div固定显示的几种方法

很多时候我们会受到一些需求: 1、div一直置顶 2、div一直置底 3、超过一定的位置之后div置顶 4、超过一定位置之后div置底 那么下面针对上面的几个问题写几个案例: 一、div一直在屏幕的上方,这个倒是容易咱们直接使用position:fixed;然后设置他的top值和left就可以了,别忘了设置宽度哦 <div class="top"&g...

Unity3D中Mathf数学运算函数总结

引入: 看到一个案例注意到函数Mathf.SmoothDamp的使用,游戏中用于做相机的缓冲跟踪和boss直升机跟踪士兵。该函数是Unity3D中Mathf数学运算函数中的一个。一些游戏使用了smoothmove的功能,其实就是类似的效果,只是发现这个函数很容易的已经封装好了,查了官网文档发现使用起来真的非常简单。 smoothdamp,我的理解是平滑缓...

CSS图片垂直居中方法

让div里面的多行文本垂直居中的方法: div{height:100px;100px;border:solid 1px red;text-align:center; display:table-cell;vertical-align:middle} 下面是网上好不容易找的多种办法: 看到问此问题的很多,所以花点时间整理下,欢迎大家提意见,做补充修改,谢谢...