Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 1x 111x 111x 111x 133x 1x 111x 111x 1x 1x 1x 1x 1x | import Frozen from "../Core/Frozen.js";
import defined from "../Core/defined.js";
import VertexFormat from "../Core/VertexFormat.js";
import EllipsoidSurfaceAppearanceFS from "../Shaders/Appearances/EllipsoidSurfaceAppearanceFS.js";
import EllipsoidSurfaceAppearanceVS from "../Shaders/Appearances/EllipsoidSurfaceAppearanceVS.js";
import Appearance from "./Appearance.js";
import Material from "./Material.js";
/**
* An appearance for geometry on the surface of the ellipsoid like {@link PolygonGeometry}
* and {@link RectangleGeometry}, which supports all materials like {@link MaterialAppearance}
* with {@link MaterialAppearance.MaterialSupport.ALL}. However, this appearance requires
* fewer vertex attributes since the fragment shader can procedurally compute <code>normal</code>,
* <code>tangent</code>, and <code>bitangent</code>.
*
* @alias EllipsoidSurfaceAppearance
* @constructor
*
* @param {object} [options] Object with the following properties:
* @param {boolean} [options.flat=false] When <code>true</code>, flat shading is used in the fragment shader, which means lighting is not taking into account.
* @param {boolean} [options.faceForward=options.aboveGround] When <code>true</code>, the fragment shader flips the surface normal as needed to ensure that the normal faces the viewer to avoid dark spots. This is useful when both sides of a geometry should be shaded like {@link WallGeometry}.
* @param {boolean} [options.translucent=true] When <code>true</code>, the geometry is expected to appear translucent so {@link EllipsoidSurfaceAppearance#renderState} has alpha blending enabled.
* @param {boolean} [options.aboveGround=false] When <code>true</code>, the geometry is expected to be on the ellipsoid's surface - not at a constant height above it - so {@link EllipsoidSurfaceAppearance#renderState} has backface culling enabled.
* @param {Material} [options.material=Material.ColorType] The material used to determine the fragment color.
* @param {string} [options.vertexShaderSource] Optional GLSL vertex shader source to override the default vertex shader.
* @param {string} [options.fragmentShaderSource] Optional GLSL fragment shader source to override the default fragment shader.
* @param {object} [options.renderState] Optional render state to override the default render state.
*
* @see {@link https://github.com/CesiumGS/cesium/wiki/Fabric|Fabric}
*
* @example
* const primitive = new Cesium.Primitive({
* geometryInstances : new Cesium.GeometryInstance({
* geometry : new Cesium.PolygonGeometry({
* vertexFormat : Cesium.EllipsoidSurfaceAppearance.VERTEX_FORMAT,
* // ...
* })
* }),
* appearance : new Cesium.EllipsoidSurfaceAppearance({
* material : Cesium.Material.fromType('Stripe')
* })
* });
*/
function EllipsoidSurfaceAppearance(options) {
options = options ?? Frozen.EMPTY_OBJECT;
const translucent = options.translucent ?? true;
const aboveGround = options.aboveGround ?? false;
/**
* The material used to determine the fragment color. Unlike other {@link EllipsoidSurfaceAppearance}
* properties, this is not read-only, so an appearance's material can change on the fly.
*
* @type Material
*
* @default {@link Material.ColorType}
*
* @see {@link https://github.com/CesiumGS/cesium/wiki/Fabric|Fabric}
*/
this.material = defined(options.material)
? options.material
: Material.fromType(Material.ColorType);
/**
* When <code>true</code>, the geometry is expected to appear translucent.
*
* @type {boolean}
*
* @default true
*/
this.translucent = options.translucent ?? true;
this._vertexShaderSource =
options.vertexShaderSource ?? EllipsoidSurfaceAppearanceVS;
this._fragmentShaderSource =
options.fragmentShaderSource ?? EllipsoidSurfaceAppearanceFS;
this._renderState = Appearance.getDefaultRenderState(
translucent,
!aboveGround,
options.renderState,
);
this._closed = false;
// Non-derived members
this._flat = options.flat ?? false;
this._faceForward = options.faceForward ?? aboveGround;
this._aboveGround = aboveGround;
}
Object.defineProperties(EllipsoidSurfaceAppearance.prototype, {
/**
* The GLSL source code for the vertex shader.
*
* @memberof EllipsoidSurfaceAppearance.prototype
*
* @type {string}
* @readonly
*/
vertexShaderSource: {
get: function () {
return this._vertexShaderSource;
},
},
/**
* The GLSL source code for the fragment shader. The full fragment shader
* source is built procedurally taking into account {@link EllipsoidSurfaceAppearance#material},
* {@link EllipsoidSurfaceAppearance#flat}, and {@link EllipsoidSurfaceAppearance#faceForward}.
* Use {@link EllipsoidSurfaceAppearance#getFragmentShaderSource} to get the full source.
*
* @memberof EllipsoidSurfaceAppearance.prototype
*
* @type {string}
* @readonly
*/
fragmentShaderSource: {
get: function () {
return this._fragmentShaderSource;
},
},
/**
* The WebGL fixed-function state to use when rendering the geometry.
* <p>
* The render state can be explicitly defined when constructing a {@link EllipsoidSurfaceAppearance}
* instance, or it is set implicitly via {@link EllipsoidSurfaceAppearance#translucent}
* and {@link EllipsoidSurfaceAppearance#aboveGround}.
* </p>
*
* @memberof EllipsoidSurfaceAppearance.prototype
*
* @type {object}
* @readonly
*/
renderState: {
get: function () {
return this._renderState;
},
},
/**
* When <code>true</code>, the geometry is expected to be closed so
* {@link EllipsoidSurfaceAppearance#renderState} has backface culling enabled.
* If the viewer enters the geometry, it will not be visible.
*
* @memberof EllipsoidSurfaceAppearance.prototype
*
* @type {boolean}
* @readonly
*
* @default false
*/
closed: {
get: function () {
return this._closed;
},
},
/**
* The {@link VertexFormat} that this appearance instance is compatible with.
* A geometry can have more vertex attributes and still be compatible - at a
* potential performance cost - but it can't have less.
*
* @memberof EllipsoidSurfaceAppearance.prototype
*
* @type VertexFormat
* @readonly
*
* @default {@link EllipsoidSurfaceAppearance.VERTEX_FORMAT}
*/
vertexFormat: {
get: function () {
return EllipsoidSurfaceAppearance.VERTEX_FORMAT;
},
},
/**
* When <code>true</code>, flat shading is used in the fragment shader,
* which means lighting is not taking into account.
*
* @memberof EllipsoidSurfaceAppearance.prototype
*
* @type {boolean}
* @readonly
*
* @default false
*/
flat: {
get: function () {
return this._flat;
},
},
/**
* When <code>true</code>, the fragment shader flips the surface normal
* as needed to ensure that the normal faces the viewer to avoid
* dark spots. This is useful when both sides of a geometry should be
* shaded like {@link WallGeometry}.
*
* @memberof EllipsoidSurfaceAppearance.prototype
*
* @type {boolean}
* @readonly
*
* @default true
*/
faceForward: {
get: function () {
return this._faceForward;
},
},
/**
* When <code>true</code>, the geometry is expected to be on the ellipsoid's
* surface - not at a constant height above it - so {@link EllipsoidSurfaceAppearance#renderState}
* has backface culling enabled.
*
*
* @memberof EllipsoidSurfaceAppearance.prototype
*
* @type {boolean}
* @readonly
*
* @default false
*/
aboveGround: {
get: function () {
return this._aboveGround;
},
},
});
/**
* The {@link VertexFormat} that all {@link EllipsoidSurfaceAppearance} instances
* are compatible with, which requires only <code>position</code> and <code>st</code>
* attributes. Other attributes are procedurally computed in the fragment shader.
*
* @type VertexFormat
*
* @constant
*/
EllipsoidSurfaceAppearance.VERTEX_FORMAT = VertexFormat.POSITION_AND_ST;
/**
* Procedurally creates the full GLSL fragment shader source. For {@link EllipsoidSurfaceAppearance},
* this is derived from {@link EllipsoidSurfaceAppearance#fragmentShaderSource}, {@link EllipsoidSurfaceAppearance#flat},
* and {@link EllipsoidSurfaceAppearance#faceForward}.
*
* @function
*
* @returns {string} The full GLSL fragment shader source.
*/
EllipsoidSurfaceAppearance.prototype.getFragmentShaderSource =
Appearance.prototype.getFragmentShaderSource;
/**
* Determines if the geometry is translucent based on {@link EllipsoidSurfaceAppearance#translucent} and {@link Material#isTranslucent}.
*
* @function
*
* @returns {boolean} <code>true</code> if the appearance is translucent.
*/
EllipsoidSurfaceAppearance.prototype.isTranslucent =
Appearance.prototype.isTranslucent;
/**
* Creates a render state. This is not the final render state instance; instead,
* it can contain a subset of render state properties identical to the render state
* created in the context.
*
* @function
*
* @returns {object} The render state.
*/
EllipsoidSurfaceAppearance.prototype.getRenderState =
Appearance.prototype.getRenderState;
export default EllipsoidSurfaceAppearance;
|