diff --git a/Apps/Sandcastle/gallery/Custom Per-Feature Post Process.html b/Apps/Sandcastle/gallery/Custom Per-Feature Post Process.html index 7c50573d81d1..99b58dbaccd6 100644 --- a/Apps/Sandcastle/gallery/Custom Per-Feature Post Process.html +++ b/Apps/Sandcastle/gallery/Custom Per-Feature Post Process.html @@ -59,15 +59,15 @@ // Shade selected model with highlight. const fragmentShaderSource = ` uniform sampler2D colorTexture; - varying vec2 v_textureCoordinates; + in vec2 v_textureCoordinates; uniform vec4 highlight; void main() { - vec4 color = texture2D(colorTexture, v_textureCoordinates); + vec4 color = texture(colorTexture, v_textureCoordinates); if (czm_selected()) { vec3 highlighted = highlight.a * highlight.rgb + (1.0 - highlight.a) * color.rgb; - gl_FragColor = vec4(highlighted, 1.0); + out_FragColor = vec4(highlighted, 1.0); } else { - gl_FragColor = color; + out_FragColor = color; } } `; diff --git a/Apps/Sandcastle/gallery/Custom Post Process.html b/Apps/Sandcastle/gallery/Custom Post Process.html index 213efedaded8..2da4544f12d6 100644 --- a/Apps/Sandcastle/gallery/Custom Post Process.html +++ b/Apps/Sandcastle/gallery/Custom Post Process.html @@ -54,7 +54,7 @@ const fragmentShaderSource = ` uniform sampler2D colorTexture; - varying vec2 v_textureCoordinates; + in vec2 v_textureCoordinates; const int KERNEL_WIDTH = 16; void main(void) { @@ -65,11 +65,11 @@ { for (int j = 0; j < KERNEL_WIDTH; j++) { - averageValue += texture2D(colorTexture, integralPos + step * vec2(i, j)).rgb; + averageValue += texture(colorTexture, integralPos + step * vec2(i, j)).rgb; } } averageValue /= float(KERNEL_WIDTH * KERNEL_WIDTH); - gl_FragColor = vec4(averageValue, 1.0); + out_FragColor = vec4(averageValue, 1.0); } `; viewer.scene.postProcessStages.add( diff --git a/Apps/Sandcastle/gallery/Custom Shaders Models.html b/Apps/Sandcastle/gallery/Custom Shaders Models.html index 6349c9fa5c18..9b2766d525ea 100644 --- a/Apps/Sandcastle/gallery/Custom Shaders Models.html +++ b/Apps/Sandcastle/gallery/Custom Shaders Models.html @@ -105,7 +105,7 @@ void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material) { vec2 texCoord = fsInput.attributes.texCoord_0 + 0.1 * vec2(u_time, 0.0); - material.diffuse = texture2D(u_stripes, texCoord).rgb; + material.diffuse = texture(u_stripes, texCoord).rgb; } `, }); @@ -156,7 +156,7 @@ void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material) { vec2 texCoord = fsInput.attributes.texCoord_0; - vec4 checkerboard = texture2D(u_checkerboard, texCoord); + vec4 checkerboard = texture(u_checkerboard, texCoord); material.diffuse = mix(material.diffuse, vec3(0.0), checkerboard.r); } `, @@ -178,7 +178,7 @@ void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material) { vec2 texCoord = fsInput.attributes.texCoord_0; - vec4 checkerboard = texture2D(u_checkerboard, texCoord); + vec4 checkerboard = texture(u_checkerboard, texCoord); material.diffuse = checkerboard.rgb; material.alpha = checkerboard.a; } @@ -197,7 +197,7 @@ void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material) { vec2 texCoord = fsInput.attributes.texCoord_0; - vec4 checkerboard = texture2D(u_checkerboard, texCoord); + vec4 checkerboard = texture(u_checkerboard, texCoord); if (checkerboard.r > 0.0) { discard; } @@ -245,7 +245,7 @@ fragmentShaderText: ` void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material) { - material.diffuse = texture2D(u_gradient, fsInput.attributes.texCoord_0).rgb; + material.diffuse = texture(u_gradient, fsInput.attributes.texCoord_0).rgb; } `, }); diff --git a/Apps/Sandcastle/gallery/Fog Post Process.html b/Apps/Sandcastle/gallery/Fog Post Process.html index 3cedae53ed7f..e61088893390 100644 --- a/Apps/Sandcastle/gallery/Fog Post Process.html +++ b/Apps/Sandcastle/gallery/Fog Post Process.html @@ -61,7 +61,7 @@ const fragmentShaderSource = ` float getDistance(sampler2D depthTexture, vec2 texCoords) { - float depth = czm_unpackDepth(texture2D(depthTexture, texCoords)); + float depth = czm_unpackDepth(texture(depthTexture, texCoords)); if (depth == 0.0) { return czm_infinity; } @@ -85,14 +85,14 @@ uniform sampler2D depthTexture; uniform vec4 fogByDistance; uniform vec4 fogColor; - varying vec2 v_textureCoordinates; + in vec2 v_textureCoordinates; void main(void) { float distance = getDistance(depthTexture, v_textureCoordinates); - vec4 sceneColor = texture2D(colorTexture, v_textureCoordinates); + vec4 sceneColor = texture(colorTexture, v_textureCoordinates); float blendAmount = interpolateByDistance(fogByDistance, distance); vec4 finalFogColor = vec4(fogColor.rgb, fogColor.a * blendAmount); - gl_FragColor = alphaBlend(finalFogColor, sceneColor); + out_FragColor = alphaBlend(finalFogColor, sceneColor); } `; diff --git a/Apps/Sandcastle/gallery/MSAA.html b/Apps/Sandcastle/gallery/MSAA.html index eaa3f1a1990e..a7d070c2c719 100644 --- a/Apps/Sandcastle/gallery/MSAA.html +++ b/Apps/Sandcastle/gallery/MSAA.html @@ -34,9 +34,6 @@ //Sandcastle_Begin const viewer = new Cesium.Viewer("cesiumContainer", { terrainProvider: Cesium.createWorldTerrain(), - contextOptions: { - requestWebgl1: false, - }, }); viewer.clock.currentTime = Cesium.JulianDate.fromIso8601( diff --git a/Apps/Sandcastle/gallery/Materials.html b/Apps/Sandcastle/gallery/Materials.html index f6815a30fc00..659c38ea8252 100644 --- a/Apps/Sandcastle/gallery/Materials.html +++ b/Apps/Sandcastle/gallery/Materials.html @@ -120,9 +120,9 @@ czm_material czm_getMaterial(czm_materialInput materialInput) { czm_material material = czm_getDefaultMaterial(materialInput); vec4 color; - float heightValue = texture2D(heightField, materialInput.st).r; + float heightValue = texture(heightField, materialInput.st).r; color.rgb = mix(vec3(0.2, 0.6, 0.2), vec3(1.0, 0.5, 0.2), heightValue); - color.a = (1.0 - texture2D(image, materialInput.st).r) * 0.7; + color.a = (1.0 - texture(image, materialInput.st).r) * 0.7; color = czm_gammaCorrect(color); material.diffuse = color.rgb; material.alpha = color.a; diff --git a/Apps/Sandcastle/gallery/development/Custom Primitive.html b/Apps/Sandcastle/gallery/development/Custom Primitive.html index 335fb1f214c6..a64a480d3832 100644 --- a/Apps/Sandcastle/gallery/development/Custom Primitive.html +++ b/Apps/Sandcastle/gallery/development/Custom Primitive.html @@ -184,8 +184,8 @@ // Inteference patterns made by two plane waves crossing each // other at an angle. The color is based on the height. const vertexShader = ` - attribute vec3 a_position; - varying vec3 v_position; + in vec3 a_position; + out vec3 v_position; uniform float u_time; void main() { @@ -200,7 +200,7 @@ `; const fragmentShader = ` - varying vec3 v_position; + in vec3 v_position; uniform float u_time; uniform sampler2D u_texture; void main() @@ -214,7 +214,7 @@ z *= 0.5; // signed -> unsigned z = 0.5 + 0.5 * z; - gl_FragColor = texture2D(u_texture, vec2(z, 0.5)); + out_FragColor = texture(u_texture, vec2(z, 0.5)); } `; diff --git a/Apps/Sandcastle/gallery/development/Ground Primitive Materials.html b/Apps/Sandcastle/gallery/development/Ground Primitive Materials.html index 88ac0877aa58..e6f67810f190 100644 --- a/Apps/Sandcastle/gallery/development/Ground Primitive Materials.html +++ b/Apps/Sandcastle/gallery/development/Ground Primitive Materials.html @@ -133,9 +133,9 @@ source: "czm_material czm_getMaterial(czm_materialInput materialInput) {" + "czm_material material = czm_getDefaultMaterial(materialInput);" + - "float heightValue = texture2D(heightField, materialInput.st).r;" + + "float heightValue = texture(heightField, materialInput.st).r;" + "material.diffuse = mix(vec3(0.2, 0.6, 0.2), vec3(1.0, 0.5, 0.2), heightValue);" + - "material.alpha = (1.0 - texture2D(image, materialInput.st).r) * 0.7;" + + "material.alpha = (1.0 - texture(image, materialInput.st).r) * 0.7;" + "material.normal = bumpMap.normal;" + "material.specular = step(0.1, heightValue);" + // Specular mountain tops "material.shininess = 8.0;" + // Sharpen highlight diff --git a/Documentation/Contributors/CodingGuide/README.md b/Documentation/Contributors/CodingGuide/README.md index 321a5aa9f774..3b6218e95972 100644 --- a/Documentation/Contributors/CodingGuide/README.md +++ b/Documentation/Contributors/CodingGuide/README.md @@ -994,10 +994,11 @@ fullscreenSubscription.dispose(); - Files for vertex shaders have a `VS` suffix; fragment shaders have an `FS` suffix. For example: `BillboardCollectionVS.glsl` and `BillboardCollectionFS.glsl`. - Generally, identifiers, such as functions and variables, use `camelCase`. - Cesium built-in identifiers start with `czm_`, for example, [`czm_material`](https://github.com/CesiumGS/cesium/blob/main/Source/Shaders/Builtin/Structs/material.glsl). Files have the same name without the `czm_` prefix, e.g., `material.glsl`. +- Use `czm_textureCube` when sampling a cube map instead of `texture`. This is to preserve backwards compatibility with WebGL 1. - Varyings start with `v_`, e.g., ```javascript -varying vec2 v_textureCoordinates; +in vec2 v_textureCoordinates; ``` - Uniforms start with `u_`, e.g., diff --git a/Documentation/Contributors/TestingGuide/README.md b/Documentation/Contributors/TestingGuide/README.md index 3773886c2a56..2488dae152ca 100644 --- a/Documentation/Contributors/TestingGuide/README.md +++ b/Documentation/Contributors/TestingGuide/README.md @@ -494,7 +494,7 @@ Uniforms, the model matrix, and various depth options can be provided. In additi it("can declare automatic uniforms", function () { const fs = "void main() { " + - " gl_FragColor = vec4((czm_viewport.x == 0.0) && (czm_viewport.y == 0.0) && (czm_viewport.z == 1.0) && (czm_viewport.w == 1.0)); " + + " out_FragColor = vec4((czm_viewport.x == 0.0) && (czm_viewport.y == 0.0) && (czm_viewport.z == 1.0) && (czm_viewport.w == 1.0)); " + "}"; expect({ context: context, @@ -573,7 +573,7 @@ it("has czm_transpose (2x2)", function () { "void main() { " + " mat2 m = mat2(1.0, 2.0, 3.0, 4.0); " + " mat2 mt = mat2(1.0, 3.0, 2.0, 4.0); " + - " gl_FragColor = vec4(czm_transpose(m) == mt); " + + " out_FragColor = vec4(czm_transpose(m) == mt); " + "}"; context.verifyDrawForSpecs(fs); @@ -586,7 +586,7 @@ it("has czm_transpose (2x2)", function () { expect(context.readPixels()).toEqual([255, 255, 255, 255]); ``` -In the test above, the expectation is implicit in the GLSL string for the fragment shader, `fs`, which assigns white to `gl_FragColor` if `czm_transpose` correctly transposes the matrix. +In the test above, the expectation is implicit in the GLSL string for the fragment shader, `fs`, which assigns white to `out_FragColor` if `czm_transpose` correctly transposes the matrix. ### Spies diff --git a/Documentation/CustomShaderGuide/README.md b/Documentation/CustomShaderGuide/README.md index 6fa067428008..7a95e34cac73 100644 --- a/Documentation/CustomShaderGuide/README.md +++ b/Documentation/CustomShaderGuide/README.md @@ -133,8 +133,8 @@ const textureWithSampler = new Cesium.TextureUniform({ ## Varyings Varyings are declared in the `CustomShader` constructor. This automatically -adds a line such as `varying float v_userDefinedVarying;` to the top of the -GLSL shader. +adds lines such as `out float v_userDefinedVarying;` and `in float v_userDefinedVarying;` to the top of the +GLSL vertex and fragment shaders respectively. The user is responsible for assigning a value to this varying in `vertexShaderText` and using it in `fragmentShaderText`. For example: diff --git a/Documentation/FabricGuide/README.md b/Documentation/FabricGuide/README.md index 8288a4b0f908..23cfefc1f34a 100644 --- a/Documentation/FabricGuide/README.md +++ b/Documentation/FabricGuide/README.md @@ -235,7 +235,7 @@ A slightly more complicated example adds a specular component so that the materi } ``` -The `components` property contains sub-properties that define the appearance of the material. The value of each sub-property is a GLSL code snippet, hence the `vec3(0.5)` above, which creates a 3D vector with each component set to `0.5`. These have access to all GLSL functions like `mix`, `cos`, `texture2D`, etc. There are five sub-properties. +The `components` property contains sub-properties that define the appearance of the material. The value of each sub-property is a GLSL code snippet, hence the `vec3(0.5)` above, which creates a 3D vector with each component set to `0.5`. These have access to all GLSL functions like `mix`, `cos`, `texture`, etc. There are five sub-properties. | Name | Default | Description | | :---------- | :------------ | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | @@ -358,7 +358,7 @@ We can implement our own `DiffuseMap` material by using an image uniform: image : 'czm_defaultImage' }, components : { - diffuse : 'texture2D(image, materialInput.st).rgb' + diffuse : 'texture(image, materialInput.st).rgb' } } ``` diff --git a/Documentation/Schemas/Fabric/Examples/MaterialHierarchy2.json b/Documentation/Schemas/Fabric/Examples/MaterialHierarchy2.json index 8462f1b12773..a61ad11b54a8 100644 --- a/Documentation/Schemas/Fabric/Examples/MaterialHierarchy2.json +++ b/Documentation/Schemas/Fabric/Examples/MaterialHierarchy2.json @@ -5,7 +5,7 @@ "hot": "hot.jpg" }, "components" : { - "diffuse" : "texture2D(hot, materialInput.st).rgb" + "diffuse" : "texture(hot, materialInput.st).rgb" } }, "cold" : { @@ -13,7 +13,7 @@ "cold": "cold.jpg" }, "components" : { - "diffuse" : "texture2D(cold, materialInput.st).rgb" + "diffuse" : "texture(cold, materialInput.st).rgb" } } }, diff --git a/Documentation/Schemas/Fabric/Examples/TextureUniforms.json b/Documentation/Schemas/Fabric/Examples/TextureUniforms.json index 037c900d5291..38e639ef1255 100644 --- a/Documentation/Schemas/Fabric/Examples/TextureUniforms.json +++ b/Documentation/Schemas/Fabric/Examples/TextureUniforms.json @@ -12,8 +12,8 @@ } }, "components": { - "diffuse" : "textureCube(mycubemap, normalize(vec3(1.0))).rgb /* not an interesting reflection */", - "specular" : "texture2D(myothertexture2D, materialInput.st).r", - "emission" : "texture2D(mytexture2D, materialInput.st).rgb" + "diffuse" : "czm_textureCube(mycubemap, normalize(vec3(1.0))).rgb /* not an interesting reflection */", + "specular" : "texture(myothertexture2D, materialInput.st).r", + "emission" : "texture(mytexture2D, materialInput.st).rgb" } } \ No newline at end of file diff --git a/Specs/ShaderBuilderTester.js b/Specs/ShaderBuilderTester.js index 579a1cb6586c..a1b389f853c0 100644 --- a/Specs/ShaderBuilderTester.js +++ b/Specs/ShaderBuilderTester.js @@ -66,11 +66,11 @@ ShaderBuilderTester.expectHasVaryings = function ( ) { expectEqualUnordered( shaderBuilder._vertexShaderParts.varyingLines, - expectedVaryings + expectedVaryings.map((varying) => `out ${varying}`) ); expectEqualUnordered( shaderBuilder._fragmentShaderParts.varyingLines, - expectedVaryings + expectedVaryings.map((varying) => `in ${varying}`) ); }; diff --git a/Specs/addDefaultMatchers.js b/Specs/addDefaultMatchers.js index 3e7aa3a7f78b..feb2d8a7c5c4 100644 --- a/Specs/addDefaultMatchers.js +++ b/Specs/addDefaultMatchers.js @@ -806,7 +806,7 @@ function contextRenderAndReadPixels(options) { if (!defined(sp)) { if (!defined(vs)) { vs = - "attribute vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; + "in vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; } sp = ShaderProgram.fromCache({ context: context, diff --git a/packages/engine/Source/Core/PixelFormat.js b/packages/engine/Source/Core/PixelFormat.js index 34af6433a227..15c8f9bca391 100644 --- a/packages/engine/Source/Core/PixelFormat.js +++ b/packages/engine/Source/Core/PixelFormat.js @@ -31,6 +31,22 @@ const PixelFormat = { */ ALPHA: WebGLConstants.ALPHA, + /** + * A pixel format containing a red channel + * + * @type {Number} + * @constant + */ + RED: WebGLConstants.RED, + + /** + * A pixel format containing red and green channels. + * + * @type {Number} + * @constant + */ + RG: WebGLConstants.RG, + /** * A pixel format containing red, green, and blue channels. * @@ -178,8 +194,10 @@ PixelFormat.componentsLength = function (pixelFormat) { case PixelFormat.RGBA: return 4; case PixelFormat.LUMINANCE_ALPHA: + case PixelFormat.RG: return 2; case PixelFormat.ALPHA: + case PixelFormat.RED: case PixelFormat.LUMINANCE: return 1; default: @@ -195,6 +213,8 @@ PixelFormat.validate = function (pixelFormat) { pixelFormat === PixelFormat.DEPTH_COMPONENT || pixelFormat === PixelFormat.DEPTH_STENCIL || pixelFormat === PixelFormat.ALPHA || + pixelFormat === PixelFormat.RED || + pixelFormat === PixelFormat.RG || pixelFormat === PixelFormat.RGB || pixelFormat === PixelFormat.RGBA || pixelFormat === PixelFormat.LUMINANCE || @@ -469,7 +489,7 @@ PixelFormat.toInternalFormat = function (pixelFormat, pixelDatatype, context) { return WebGLConstants.RGB32F; case PixelFormat.RG: return WebGLConstants.RG32F; - case PixelFormat.R: + case PixelFormat.RED: return WebGLConstants.R32F; } } @@ -482,7 +502,7 @@ PixelFormat.toInternalFormat = function (pixelFormat, pixelDatatype, context) { return WebGLConstants.RGB16F; case PixelFormat.RG: return WebGLConstants.RG16F; - case PixelFormat.R: + case PixelFormat.RED: return WebGLConstants.R16F; } } diff --git a/packages/engine/Source/Renderer/AutomaticUniforms.js b/packages/engine/Source/Renderer/AutomaticUniforms.js index d922fc646316..a3304ee874b4 100644 --- a/packages/engine/Source/Renderer/AutomaticUniforms.js +++ b/packages/engine/Source/Renderer/AutomaticUniforms.js @@ -151,7 +151,7 @@ const AutomaticUniforms = { * * // Get the depth at the current fragment * vec2 coords = gl_FragCoord.xy / czm_viewport.zw; - * float depth = czm_unpackDepth(texture2D(czm_globeDepthTexture, coords)); + * float depth = czm_unpackDepth(texture(czm_globeDepthTexture, coords)); */ czm_globeDepthTexture: new AutomaticUniform({ size: 1, @@ -1400,7 +1400,7 @@ const AutomaticUniforms = { * // 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; + * vec2 brdfLut = texture(czm_brdfLut, vec2(NdotV, 1.0 - roughness)).rg; */ czm_brdfLut: new AutomaticUniform({ size: 1, @@ -1419,7 +1419,7 @@ const AutomaticUniforms = { * * // Example: Create a perfect reflection of the environment map on a model * float reflected = reflect(view, normal); - * vec4 reflectedColor = textureCube(czm_environmentMap, reflected); + * vec4 reflectedColor = texture(czm_environmentMap, reflected); */ czm_environmentMap: new AutomaticUniform({ size: 1, diff --git a/packages/engine/Source/Renderer/Context.js b/packages/engine/Source/Renderer/Context.js index 5d408803311e..b346e5fd6520 100644 --- a/packages/engine/Source/Renderer/Context.js +++ b/packages/engine/Source/Renderer/Context.js @@ -43,18 +43,9 @@ function Context(canvas, options) { Check.defined("canvas", canvas); //>>includeEnd('debug'); - let requestWebgl2 = false; - if (defined(options) && defined(options.requestWebgl2)) { - requestWebgl2 = options.requestWebgl2; - Context._deprecationWarning( - "ContextOptions.requestWebgl2", - "Cesium.requestWebgl2 was deprecated in CesiumJS 1.101 and will be removed in 1.102. Use Cesium.requestWebgl1 to request a WebGL1 or WebGL2 context." - ); - } - const { getWebGLStub, - requestWebgl1 = !requestWebgl2, + requestWebgl1, webgl: webglOptions = {}, allowTextureFilterAnisotropic = true, } = defaultValue(options, {}); @@ -72,9 +63,8 @@ function Context(canvas, options) { : getWebGLContext(canvas, webglOptions, requestWebgl1); // Get context type. instanceof will throw if WebGL2 is not supported - const webgl2 = - typeof WebGL2RenderingContext !== "undefined" && - glContext instanceof WebGL2RenderingContext; + const webgl2Supported = typeof WebGL2RenderingContext !== "undefined"; + const webgl2 = webgl2Supported && glContext instanceof WebGL2RenderingContext; this._canvas = canvas; this._originalGLContext = glContext; @@ -407,7 +397,7 @@ function Context(canvas, options) { * especially for horizon views. *

* - * @property {Boolean} [requestWebgl1 = true] If true and the browser supports it, use a WebGL 1 rendering context + * @property {Boolean} [requestWebGl1=false] If true and the browser supports it, use a WebGL 1 rendering context * @property {Boolean} [allowTextureFilterAnisotropic=true] If true, use anisotropic filtering during texture sampling * @property {WebGLOptions} [webgl] WebGL options to be passed on to canvas.getContext * @property {Function} [getWebGLStub] A function to create a WebGL stub for testing diff --git a/packages/engine/Source/Renderer/ShaderBuilder.js b/packages/engine/Source/Renderer/ShaderBuilder.js index fdcad2272ad4..ddf650988a7a 100644 --- a/packages/engine/Source/Renderer/ShaderBuilder.js +++ b/packages/engine/Source/Renderer/ShaderBuilder.js @@ -43,9 +43,9 @@ import ShaderFunction from "./ShaderFunction.js"; * "void main()", * "{", * " #ifdef SOLID_COLOR", - * " gl_FragColor = vec4(u_color, 1.0);", + * " out_FragColor = vec4(u_color, 1.0);", * " #else", - * " gl_FragColor = vec4(v_color, 1.0);", + * " out_FragColor = vec4(v_color, 1.0);", * " #endif", * "}" * ]); @@ -307,7 +307,7 @@ ShaderBuilder.prototype.addUniform = function (type, identifier, destination) { * @return {Number} The integer location of the attribute. This location can be used when creating attributes for a {@link VertexArray}. This will always be 0. * * @example - * // creates the line "attribute vec3 a_position;" + * // creates the line "in vec3 a_position;" * shaderBuilder.setPositionAttribute("vec3", "a_position"); */ ShaderBuilder.prototype.setPositionAttribute = function (type, identifier) { @@ -322,7 +322,7 @@ ShaderBuilder.prototype.setPositionAttribute = function (type, identifier) { } //>>includeEnd('debug'); - this._positionAttributeLine = `attribute ${type} ${identifier};`; + this._positionAttributeLine = `in ${type} ${identifier};`; // Some WebGL implementations require attribute 0 to always be active, so // this builder assumes the position will always go in location 0 @@ -343,7 +343,7 @@ ShaderBuilder.prototype.setPositionAttribute = function (type, identifier) { * @return {Number} The integer location of the attribute. This location can be used when creating attributes for a {@link VertexArray} * * @example - * // creates the line "attribute vec2 a_texCoord0;" in the vertex shader + * // creates the line "in vec2 a_texCoord0;" in the vertex shader * shaderBuilder.addAttribute("vec2", "a_texCoord0"); */ ShaderBuilder.prototype.addAttribute = function (type, identifier) { @@ -352,7 +352,7 @@ ShaderBuilder.prototype.addAttribute = function (type, identifier) { Check.typeOf.string("identifier", identifier); //>>includeEnd('debug'); - const line = `attribute ${type} ${identifier};`; + const line = `in ${type} ${identifier};`; this._attributeLines.push(line); const location = this._nextAttributeLocation; @@ -371,7 +371,8 @@ ShaderBuilder.prototype.addAttribute = function (type, identifier) { * @param {String} identifier An identifier for the varying. Identifiers must begin with v_ to be consistent with Cesium's style guide. * * @example - * // creates the line "varying vec3 v_color;" in both shaders + * // creates the line "in vec3 v_color;" in the vertex shader + * // creates the line "out vec3 v_color;" in the fragment shader * shaderBuilder.addVarying("vec3", "v_color"); */ ShaderBuilder.prototype.addVarying = function (type, identifier) { @@ -380,9 +381,9 @@ ShaderBuilder.prototype.addVarying = function (type, identifier) { Check.typeOf.string("identifier", identifier); //>>includeEnd('debug'); - const line = `varying ${type} ${identifier};`; - this._vertexShaderParts.varyingLines.push(line); - this._fragmentShaderParts.varyingLines.push(line); + const line = `${type} ${identifier};`; + this._vertexShaderParts.varyingLines.push(`out ${line}`); + this._fragmentShaderParts.varyingLines.push(`in ${line}`); }; /** @@ -427,9 +428,9 @@ ShaderBuilder.prototype.addVertexLines = function (lines) { * "void main()", * "{", * " #ifdef SOLID_COLOR", - * " gl_FragColor = vec4(u_color, 1.0);", + * " out_FragColor = vec4(u_color, 1.0);", * " #else", - * " gl_FragColor = vec4(v_color, 1.0);", + * " out_FragColor = vec4(v_color, 1.0);", * " #endif", * "}" * ]); diff --git a/packages/engine/Source/Renderer/ShaderSource.js b/packages/engine/Source/Renderer/ShaderSource.js index 330c604170e4..493aa622920f 100644 --- a/packages/engine/Source/Renderer/ShaderSource.js +++ b/packages/engine/Source/Renderer/ShaderSource.js @@ -1,9 +1,9 @@ import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import DeveloperError from "../Core/DeveloperError.js"; -import modernizeShader from "../Renderer/modernizeShader.js"; import CzmBuiltins from "../Shaders/Builtin/CzmBuiltins.js"; import AutomaticUniforms from "./AutomaticUniforms.js"; +import demodernizeShader from "./demodernizeShader.js"; function removeComments(source) { // remove inline comments @@ -223,12 +223,6 @@ function combineShader(shaderSource, isFragmentShader, context) { // combine into single string let result = ""; - // #version must be first - // defaults to #version 100 if not specified - if (defined(version)) { - result = `#version ${version}\n`; - } - const extensionsLength = extensions.length; for (i = 0; i < extensionsLength; i++) { result += extensions[i]; @@ -261,12 +255,6 @@ function combineShader(shaderSource, isFragmentShader, context) { } } - // GLSLModernizer inserts its own layout qualifiers - // at this position in the source - if (context.webgl2) { - result += "#define OUTPUT_DECLARATION\n\n"; - } - // Define a constant for the OES_texture_float_linear extension since WebGL does not. if (context.textureFloatLinear) { result += "#define OES_texture_float_linear\n\n"; @@ -278,19 +266,36 @@ function combineShader(shaderSource, isFragmentShader, context) { } // append built-ins + let builtinSources = ""; if (shaderSource.includeBuiltIns) { - result += getBuiltinsAndAutomaticUniforms(combinedSources); + builtinSources = getBuiltinsAndAutomaticUniforms(combinedSources); } // reset line number result += "\n#line 0\n"; // append actual source + const combinedShader = builtinSources + combinedSources; + if ( + context.webgl2 && + isFragmentShader && + !/layout\s*\(location\s*=\s*0\)\s*out\s+vec4\s+out_FragColor;/g.test( + combinedShader + ) && + !/czm_out_FragColor/g.test(combinedShader) && + /out_FragColor/g.test(combinedShader) + ) { + result += "layout(location = 0) out vec4 out_FragColor;\n\n"; + } + + result += builtinSources; result += combinedSources; // modernize the source - if (context.webgl2) { - result = modernizeShader(result, isFragmentShader, true); + if (!context.webgl2) { + result = demodernizeShader(result, isFragmentShader); + } else { + result = `#version 300 es\n${result}`; } return result; @@ -302,21 +307,21 @@ function combineShader(shaderSource, isFragmentShader, context) { * @param {Object} [options] Object with the following properties: * @param {String[]} [options.sources] An array of strings to combine containing GLSL code for the shader. * @param {String[]} [options.defines] An array of strings containing GLSL identifiers to #define. - * @param {String} [options.pickColorQualifier] The GLSL qualifier, uniform or varying, for the input czm_pickColor. When defined, a pick fragment shader is generated. + * @param {String} [options.pickColorQualifier] The GLSL qualifier, uniform or in, for the input czm_pickColor. When defined, a pick fragment shader is generated. * @param {Boolean} [options.includeBuiltIns=true] If true, referenced built-in functions will be included with the combined shader. Set to false if this shader will become a source in another shader, to avoid duplicating functions. * - * @exception {DeveloperError} options.pickColorQualifier must be 'uniform' or 'varying'. + * @exception {DeveloperError} options.pickColorQualifier must be 'uniform' or 'in'. * * @example * // 1. Prepend #defines to a shader * const source = new Cesium.ShaderSource({ * defines : ['WHITE'], - * sources : ['void main() { \n#ifdef WHITE\n gl_FragColor = vec4(1.0); \n#else\n gl_FragColor = vec4(0.0); \n#endif\n }'] + * sources : ['void main() { \n#ifdef WHITE\n out_FragColor = vec4(1.0); \n#else\n out_FragColor = vec4(0.0); \n#endif\n }'] * }); * * // 2. Modify a fragment shader for picking * const source2 = new Cesium.ShaderSource({ - * sources : ['void main() { gl_FragColor = vec4(1.0); }'], + * sources : ['void main() { out_FragColor = vec4(1.0); }'], * pickColorQualifier : 'uniform' * }); * @@ -330,10 +335,10 @@ function ShaderSource(options) { if ( defined(pickColorQualifier) && pickColorQualifier !== "uniform" && - pickColorQualifier !== "varying" + pickColorQualifier !== "in" ) { throw new DeveloperError( - "options.pickColorQualifier must be 'uniform' or 'varying'." + "options.pickColorQualifier must be 'uniform' or 'in'." ); } //>>includeEnd('debug'); @@ -430,8 +435,8 @@ ShaderSource.createPickVertexShaderSource = function (vertexShaderSource) { "czm_old_main" ); const pickMain = - "attribute vec4 pickColor; \n" + - "varying vec4 czm_pickColor; \n" + + "in vec4 pickColor; \n" + + "out vec4 czm_pickColor; \n" + "void main() \n" + "{ \n" + " czm_old_main(); \n" + @@ -454,10 +459,10 @@ ShaderSource.createPickFragmentShaderSource = function ( `void main() \n` + `{ \n` + ` czm_old_main(); \n` + - ` if (gl_FragColor.a == 0.0) { \n` + + ` if (out_FragColor.a == 0.0) { \n` + ` discard; \n` + ` } \n` + - ` gl_FragColor = czm_pickColor; \n` + + ` out_FragColor = czm_pickColor; \n` + `}`; return `${renamedFS}\n${pickMain}`; diff --git a/packages/engine/Source/Renderer/demodernizeShader.js b/packages/engine/Source/Renderer/demodernizeShader.js new file mode 100644 index 000000000000..357ed8de644a --- /dev/null +++ b/packages/engine/Source/Renderer/demodernizeShader.js @@ -0,0 +1,76 @@ +/** + * Transpiles a [GLSL 3.00]{@link https://registry.khronos.org/OpenGL/specs/es/3.0/GLSL_ES_Specification_3.00.pdf} + * shader to a [GLSL 1.00]{@link https://registry.khronos.org/OpenGL/specs/es/2.0/GLSL_ES_Specification_1.00.pdf} shader. + * + * This function does not aim to provide a comprehensive transpilation from GLSL 3.00 to GLSL 1.00; only the functionality + * used within the CesiumJS shaders is supported. + * + * @private + * + * @param {string} input The GLSL 3.00 shader. + * @param {boolean} isFragmentShader True if the shader is a fragment shader. + * + * @return {string} + */ +function demodernizeShader(input, isFragmentShader) { + let output = input; + + // Remove version string got GLSL 3.00. + output = output.replaceAll(`version 300 es`, ``); + + // Replace all texture calls with texture2D + output = output.replaceAll( + /(texture\()/g, + `texture2D(` // Trailing ')' is included in the match group. + ); + + if (isFragmentShader) { + // Replace the in with varying. + output = output.replaceAll(/(in)\s+(vec\d|mat\d|float)/g, `varying $2`); + + if (/out_FragData_(\d+)/.test(output)) { + output = `#extension GL_EXT_draw_buffers : enable\n${output}`; + + // Remove all layout declarations for out_FragData. + output = output.replaceAll( + /layout\s+\(location\s*=\s*\d+\)\s*out\s+vec4\s+out_FragData_\d+;/g, + `` + ); + + // Replace out_FragData with gl_FragData. + output = output.replaceAll(/out_FragData_(\d+)/g, `gl_FragData[$1]`); + } + + // Replace out_FragColor with gl_FragColor. + output = output.replaceAll(/out_FragColor/g, `gl_FragColor`); + output = output.replaceAll(/out_FragColor\[(\d+)\]/g, `gl_FragColor[$1]`); + + // Remove all layout declarations for out_FragColor. + output = output.replaceAll( + /layout\s+\(location\s*=\s*0\)\s*out\s+vec4\s+out_FragColor/g, + `` + ); + + if (/gl_FragDepth/.test(output)) { + output = `#extension GL_EXT_frag_depth : enable\n${output}`; + // Replace gl_FragDepth with gl_FragDepthEXT. + output = output.replaceAll(/gl_FragDepth/g, `gl_FragDepthEXT`); + } + } else { + // Replace the in with attribute. + output = output.replaceAll(/(in)\s+(vec\d|mat\d|float)/g, `attribute $2`); + + // Replace the out with varying. + output = output.replaceAll( + /(out)\s+(vec\d|mat\d|float)\s+([\w]+);/g, + `varying $2 $3;` + ); + } + + // Add version string for GLSL 1.00. + output = `#version 100\n${output}`; + + return output; +} + +export default demodernizeShader; diff --git a/packages/engine/Source/Renderer/modernizeShader.js b/packages/engine/Source/Renderer/modernizeShader.js deleted file mode 100644 index e3a9a360f5ec..000000000000 --- a/packages/engine/Source/Renderer/modernizeShader.js +++ /dev/null @@ -1,242 +0,0 @@ -import defined from "../Core/defined.js"; -import DeveloperError from "../Core/DeveloperError.js"; - -/** - * A function to port GLSL shaders from GLSL ES 1.00 to GLSL ES 3.00 - * - * This function is nowhere near comprehensive or complete. It just - * handles some common cases. - * - * Note that this function requires the presence of the - * "#define OUTPUT_DECLARATION" line that is appended - * by ShaderSource. - * - * @private - */ -function modernizeShader(source, isFragmentShader) { - const outputDeclarationRegex = /#define OUTPUT_DECLARATION/; - const splitSource = source.split("\n"); - - if (/#version 300 es/g.test(source)) { - return source; - } - - let outputDeclarationLine = -1; - let i, line; - for (i = 0; i < splitSource.length; ++i) { - line = splitSource[i]; - if (outputDeclarationRegex.test(line)) { - outputDeclarationLine = i; - break; - } - } - - if (outputDeclarationLine === -1) { - throw new DeveloperError("Could not find a #define OUTPUT_DECLARATION!"); - } - - const outputVariables = []; - - for (i = 0; i < 10; i++) { - const fragDataString = `gl_FragData\\[${i}\\]`; - const newOutput = `czm_out${i}`; - const regex = new RegExp(fragDataString, "g"); - if (regex.test(source)) { - setAdd(newOutput, outputVariables); - replaceInSourceString(fragDataString, newOutput, splitSource); - splitSource.splice( - outputDeclarationLine, - 0, - `layout(location = ${i}) out vec4 ${newOutput};` - ); - outputDeclarationLine += 1; - } - } - - const czmFragColor = "czm_fragColor"; - if (findInSource("gl_FragColor", splitSource)) { - setAdd(czmFragColor, outputVariables); - replaceInSourceString("gl_FragColor", czmFragColor, splitSource); - splitSource.splice( - outputDeclarationLine, - 0, - "layout(location = 0) out vec4 czm_fragColor;" - ); - outputDeclarationLine += 1; - } - - const variableMap = getVariablePreprocessorBranch( - outputVariables, - splitSource - ); - const lineAdds = {}; - for (i = 0; i < splitSource.length; i++) { - line = splitSource[i]; - for (const variable in variableMap) { - if (variableMap.hasOwnProperty(variable)) { - const matchVar = new RegExp( - `(layout)[^]+(out)[^]+(${variable})[^]+`, - "g" - ); - if (matchVar.test(line)) { - lineAdds[line] = variable; - } - } - } - } - - for (const layoutDeclaration in lineAdds) { - if (lineAdds.hasOwnProperty(layoutDeclaration)) { - const variableName = lineAdds[layoutDeclaration]; - let lineNumber = splitSource.indexOf(layoutDeclaration); - const entry = variableMap[variableName]; - const depth = entry.length; - for (let d = 0; d < depth; d++) { - splitSource.splice(lineNumber, 0, entry[d]); - } - lineNumber += depth + 1; - for (let d = depth - 1; d >= 0; d--) { - splitSource.splice(lineNumber, 0, `#endif //${entry[d]}`); - } - } - } - - const webgl2UniqueID = "WEBGL_2"; - const webgl2DefineMacro = `#define ${webgl2UniqueID}`; - const versionThree = "#version 300 es"; - let foundVersion = false; - for (i = 0; i < splitSource.length; i++) { - if (/#version/.test(splitSource[i])) { - splitSource[i] = versionThree; - foundVersion = true; - break; - } - } - - if (!foundVersion) { - splitSource.splice(0, 0, versionThree); - } - - splitSource.splice(1, 0, webgl2DefineMacro); - - removeExtension("EXT_draw_buffers", webgl2UniqueID, splitSource); - removeExtension("EXT_frag_depth", webgl2UniqueID, splitSource); - removeExtension("OES_standard_derivatives", webgl2UniqueID, splitSource); - - replaceInSourceString("texture2D", "texture", splitSource); - replaceInSourceString("texture3D", "texture", splitSource); - replaceInSourceString("textureCube", "texture", splitSource); - replaceInSourceString("gl_FragDepthEXT", "gl_FragDepth", splitSource); - - if (isFragmentShader) { - replaceInSourceString("varying", "in", splitSource); - } else { - replaceInSourceString("attribute", "in", splitSource); - replaceInSourceString("varying", "out", splitSource); - } - - return compileSource(splitSource); -} - -// Note that this fails if your string looks like -// searchString[singleCharacter]searchString -function replaceInSourceString(str, replacement, splitSource) { - const regexStr = `(^|[^\\w])(${str})($|[^\\w])`; - const regex = new RegExp(regexStr, "g"); - - const splitSourceLength = splitSource.length; - for (let i = 0; i < splitSourceLength; ++i) { - const line = splitSource[i]; - splitSource[i] = line.replace(regex, `$1${replacement}$3`); - } -} - -function replaceInSourceRegex(regex, replacement, splitSource) { - const splitSourceLength = splitSource.length; - for (let i = 0; i < splitSourceLength; ++i) { - const line = splitSource[i]; - splitSource[i] = line.replace(regex, replacement); - } -} - -function findInSource(str, splitSource) { - const regexStr = `(^|[^\\w])(${str})($|[^\\w])`; - const regex = new RegExp(regexStr, "g"); - - const splitSourceLength = splitSource.length; - for (let i = 0; i < splitSourceLength; ++i) { - const line = splitSource[i]; - if (regex.test(line)) { - return true; - } - } - return false; -} - -function compileSource(splitSource) { - let wholeSource = ""; - - const splitSourceLength = splitSource.length; - for (let i = 0; i < splitSourceLength; ++i) { - wholeSource += `${splitSource[i]}\n`; - } - return wholeSource; -} - -function setAdd(variable, set) { - if (set.indexOf(variable) === -1) { - set.push(variable); - } -} - -function getVariablePreprocessorBranch(layoutVariables, splitSource) { - const variableMap = {}; - - const numLayoutVariables = layoutVariables.length; - - const stack = []; - for (let i = 0; i < splitSource.length; ++i) { - const line = splitSource[i]; - const hasIF = /(#ifdef|#if)/g.test(line); - const hasELSE = /#else/g.test(line); - const hasENDIF = /#endif/g.test(line); - - if (hasIF) { - stack.push(line); - } else if (hasELSE) { - const top = stack[stack.length - 1]; - let op = top.replace("ifdef", "ifndef"); - if (/if/g.test(op)) { - op = op.replace(/(#if\s+)(\S*)([^]*)/, "$1!($2)$3"); - } - stack.pop(); - stack.push(op); - } else if (hasENDIF) { - stack.pop(); - } else if (!/layout/g.test(line)) { - for (let varIndex = 0; varIndex < numLayoutVariables; ++varIndex) { - const varName = layoutVariables[varIndex]; - if (line.indexOf(varName) !== -1) { - if (!defined(variableMap[varName])) { - variableMap[varName] = stack.slice(); - } else { - variableMap[varName] = variableMap[varName].filter(function (x) { - return stack.indexOf(x) >= 0; - }); - } - } - } - } - } - - return variableMap; -} - -function removeExtension(name, webgl2UniqueID, splitSource) { - const regex = `#extension\\s+GL_${name}\\s+:\\s+[a-zA-Z0-9]+\\s*$`; - replaceInSourceRegex(new RegExp(regex, "g"), "", splitSource); - - // replace any possible directive #ifdef (GL_EXT_extension) with WEBGL_2 unique directive - replaceInSourceString(`GL_${name}`, webgl2UniqueID, splitSource); -} -export default modernizeShader; diff --git a/packages/engine/Source/Scene/AutoExposure.js b/packages/engine/Source/Scene/AutoExposure.js index 3a3f71e39ba8..7c0968b99e2a 100644 --- a/packages/engine/Source/Scene/AutoExposure.js +++ b/packages/engine/Source/Scene/AutoExposure.js @@ -203,16 +203,16 @@ function createUniformMap(autoexposure, index) { function getShaderSource(index, length) { let source = "uniform sampler2D colorTexture; \n" + - "varying vec2 v_textureCoordinates; \n" + + "in vec2 v_textureCoordinates; \n" + "float sampleTexture(vec2 offset) { \n"; if (index === 0) { source += - " vec4 color = texture2D(colorTexture, v_textureCoordinates + offset); \n" + + " vec4 color = texture(colorTexture, v_textureCoordinates + offset); \n" + " return czm_luminance(color.rgb); \n"; } else { source += - " return texture2D(colorTexture, v_textureCoordinates + offset).r; \n"; + " return texture(colorTexture, v_textureCoordinates + offset).r; \n"; } source += "}\n\n"; @@ -244,13 +244,13 @@ function getShaderSource(index, length) { if (index === length - 1) { source += - " float previous = texture2D(previousLuminance, vec2(0.5)).r; \n" + + " float previous = texture(previousLuminance, vec2(0.5)).r; \n" + " color = clamp(color, minMaxLuminance.x, minMaxLuminance.y); \n" + " color = previous + (color - previous) / (60.0 * 1.5); \n" + " color = clamp(color, minMaxLuminance.x, minMaxLuminance.y); \n"; } - source += " gl_FragColor = vec4(color); \n" + "} \n"; + source += " out_FragColor = vec4(color); \n" + "} \n"; return source; } diff --git a/packages/engine/Source/Scene/BatchTable.js b/packages/engine/Source/Scene/BatchTable.js index 2ae5af54cb91..3efa78ae3c15 100644 --- a/packages/engine/Source/Scene/BatchTable.js +++ b/packages/engine/Source/Scene/BatchTable.js @@ -530,12 +530,12 @@ function getGlslAttributeFunction(batchTable, attributeIndex) { ) { glslFunction += "vec4 textureValue; \n" + - "textureValue.x = czm_unpackFloat(texture2D(batchTexture, st)); \n" + - "textureValue.y = czm_unpackFloat(texture2D(batchTexture, st + vec2(batchTextureStep.x, 0.0))); \n" + - "textureValue.z = czm_unpackFloat(texture2D(batchTexture, st + vec2(batchTextureStep.x * 2.0, 0.0))); \n" + - "textureValue.w = czm_unpackFloat(texture2D(batchTexture, st + vec2(batchTextureStep.x * 3.0, 0.0))); \n"; + "textureValue.x = czm_unpackFloat(texture(batchTexture, st)); \n" + + "textureValue.y = czm_unpackFloat(texture(batchTexture, st + vec2(batchTextureStep.x, 0.0))); \n" + + "textureValue.z = czm_unpackFloat(texture(batchTexture, st + vec2(batchTextureStep.x * 2.0, 0.0))); \n" + + "textureValue.w = czm_unpackFloat(texture(batchTexture, st + vec2(batchTextureStep.x * 3.0, 0.0))); \n"; } else { - glslFunction += " vec4 textureValue = texture2D(batchTexture, st); \n"; + glslFunction += " vec4 textureValue = texture(batchTexture, st); \n"; } glslFunction += ` ${functionReturnType} value = textureValue${functionReturnValue}; \n`; diff --git a/packages/engine/Source/Scene/BillboardCollection.js b/packages/engine/Source/Scene/BillboardCollection.js index 251fa7743d9a..d5b2bf1b2e92 100644 --- a/packages/engine/Source/Scene/BillboardCollection.js +++ b/packages/engine/Source/Scene/BillboardCollection.js @@ -1789,10 +1789,10 @@ function updateBoundingVolume(collection, frameState, boundingVolume) { function createDebugCommand(billboardCollection, context) { const fs = "uniform sampler2D billboard_texture; \n" + - "varying vec2 v_textureCoordinates; \n" + + "in vec2 v_textureCoordinates; \n" + "void main() \n" + "{ \n" + - " gl_FragColor = texture2D(billboard_texture, v_textureCoordinates); \n" + + " out_FragColor = texture(billboard_texture, v_textureCoordinates); \n" + "} \n"; const drawCommand = context.createViewportQuadCommand(fs, { diff --git a/packages/engine/Source/Scene/Cesium3DTileBatchTable.js b/packages/engine/Source/Scene/Cesium3DTileBatchTable.js index 68ccef83ece1..4430c4c0c353 100644 --- a/packages/engine/Source/Scene/Cesium3DTileBatchTable.js +++ b/packages/engine/Source/Scene/Cesium3DTileBatchTable.js @@ -517,13 +517,13 @@ Cesium3DTileBatchTable.prototype.getVertexShaderCallback = function ( newMain += `${ "uniform sampler2D tile_batchTexture; \n" + - "varying vec4 tile_featureColor; \n" + - "varying vec2 tile_featureSt; \n" + + "out vec4 tile_featureColor; \n" + + "out vec2 tile_featureSt; \n" + "void main() \n" + "{ \n" + " vec2 st = computeSt(" }${batchIdAttributeName}); \n` + - ` vec4 featureProperties = texture2D(tile_batchTexture, st); \n` + + ` vec4 featureProperties = texture(tile_batchTexture, st); \n` + ` tile_color(featureProperties); \n` + ` float show = ceil(featureProperties.a); \n` + // 0 - false, non-zero - true ` gl_Position *= show; \n`; // Per-feature show/hide @@ -553,7 +553,7 @@ Cesium3DTileBatchTable.prototype.getVertexShaderCallback = function ( // When VTF is not supported, color blend mode MIX will look incorrect due to the feature's color not being available in the vertex shader newMain = `${ - "varying vec2 tile_featureSt; \n" + + "out vec2 tile_featureSt; \n" + "void main() \n" + "{ \n" + " tile_color(vec4(1.0)); \n" + @@ -578,22 +578,22 @@ function getDefaultShader(source, applyHighlight) { } // The color blend mode is intended for the RGB channels so alpha is always just multiplied. - // gl_FragColor is multiplied by the tile color only when tile_colorBlend is 0.0 (highlight) + // out_FragColor is multiplied by the tile color only when tile_colorBlend is 0.0 (highlight) return ( `${source}uniform float tile_colorBlend; \n` + `void tile_color(vec4 tile_featureColor) \n` + `{ \n` + ` tile_main(); \n` + ` tile_featureColor = czm_gammaCorrect(tile_featureColor); \n` + - ` gl_FragColor.a *= tile_featureColor.a; \n` + + ` out_FragColor.a *= tile_featureColor.a; \n` + ` float highlight = ceil(tile_colorBlend); \n` + - ` gl_FragColor.rgb *= mix(tile_featureColor.rgb, vec3(1.0), highlight); \n` + + ` out_FragColor.rgb *= mix(tile_featureColor.rgb, vec3(1.0), highlight); \n` + `} \n` ); } function replaceDiffuseTextureCalls(source, diffuseAttributeOrUniformName) { - const functionCall = `texture2D(${diffuseAttributeOrUniformName}`; + const functionCall = `texture(${diffuseAttributeOrUniformName}`; let fromIndex = 0; let startIndex = source.indexOf(functionCall, fromIndex); @@ -668,12 +668,12 @@ function modifyDiffuse(source, diffuseAttributeOrUniformName, applyHighlight) { "} \n"; // The color blend mode is intended for the RGB channels so alpha is always just multiplied. - // gl_FragColor is multiplied by the tile color only when tile_colorBlend is 0.0 (highlight) + // out_FragColor is multiplied by the tile color only when tile_colorBlend is 0.0 (highlight) const highlight = " tile_featureColor = czm_gammaCorrect(tile_featureColor); \n" + - " gl_FragColor.a *= tile_featureColor.a; \n" + + " out_FragColor.a *= tile_featureColor.a; \n" + " float highlight = ceil(tile_colorBlend); \n" + - " gl_FragColor.rgb *= mix(tile_featureColor.rgb, vec3(1.0), highlight); \n"; + " out_FragColor.rgb *= mix(tile_featureColor.rgb, vec3(1.0), highlight); \n"; let setColor; if (type === "vec3" || type === "vec4") { @@ -691,8 +691,8 @@ function modifyDiffuse(source, diffuseAttributeOrUniformName, applyHighlight) { ` tile_main(); \n`; } else if (type === "sampler2D") { // Handles any number of nested parentheses - // E.g. texture2D(u_diffuse, uv) - // E.g. texture2D(u_diffuse, computeUV(index)) + // E.g. texture(u_diffuse, uv) + // E.g. texture(u_diffuse, computeUV(index)) source = replaceDiffuseTextureCalls(source, diffuseAttributeOrUniformName); setColor = " tile_diffuse = tile_featureColor; \n" + " tile_main(); \n"; @@ -727,14 +727,14 @@ Cesium3DTileBatchTable.prototype.getFragmentShaderCallback = function ( // When VTF is supported, per-feature show/hide already happened in the fragment shader source += "uniform sampler2D tile_pickTexture; \n" + - "varying vec2 tile_featureSt; \n" + - "varying vec4 tile_featureColor; \n" + + "in vec2 tile_featureSt; \n" + + "in vec4 tile_featureColor; \n" + "void main() \n" + "{ \n" + " tile_color(tile_featureColor); \n"; if (hasPremultipliedAlpha) { - source += " gl_FragColor.rgb *= gl_FragColor.a; \n"; + source += " out_FragColor.rgb *= out_FragColor.a; \n"; } source += "}"; @@ -745,10 +745,10 @@ Cesium3DTileBatchTable.prototype.getFragmentShaderCallback = function ( source += "uniform sampler2D tile_pickTexture; \n" + "uniform sampler2D tile_batchTexture; \n" + - "varying vec2 tile_featureSt; \n" + + "in vec2 tile_featureSt; \n" + "void main() \n" + "{ \n" + - " vec4 featureProperties = texture2D(tile_batchTexture, tile_featureSt); \n" + + " vec4 featureProperties = texture(tile_batchTexture, tile_featureSt); \n" + " if (featureProperties.a == 0.0) { \n" + // show: alpha == 0 - false, non-zeo - true " discard; \n" + " } \n"; @@ -775,7 +775,7 @@ Cesium3DTileBatchTable.prototype.getFragmentShaderCallback = function ( source += " tile_color(featureProperties); \n"; if (hasPremultipliedAlpha) { - source += " gl_FragColor.rgb *= gl_FragColor.a; \n"; + source += " out_FragColor.rgb *= out_FragColor.a; \n"; } source += "} \n"; @@ -794,28 +794,28 @@ Cesium3DTileBatchTable.prototype.getClassificationFragmentShaderCallback = funct // When VTF is supported, per-feature show/hide already happened in the fragment shader source += "uniform sampler2D tile_pickTexture;\n" + - "varying vec2 tile_featureSt; \n" + - "varying vec4 tile_featureColor; \n" + + "in vec2 tile_featureSt; \n" + + "in vec4 tile_featureColor; \n" + "void main() \n" + "{ \n" + " tile_main(); \n" + - " gl_FragColor = tile_featureColor; \n" + - " gl_FragColor.rgb *= gl_FragColor.a; \n" + + " out_FragColor = tile_featureColor; \n" + + " out_FragColor.rgb *= out_FragColor.a; \n" + "}"; } else { source += "uniform sampler2D tile_batchTexture; \n" + "uniform sampler2D tile_pickTexture;\n" + - "varying vec2 tile_featureSt; \n" + + "in vec2 tile_featureSt; \n" + "void main() \n" + "{ \n" + " tile_main(); \n" + - " vec4 featureProperties = texture2D(tile_batchTexture, tile_featureSt); \n" + + " vec4 featureProperties = texture(tile_batchTexture, tile_featureSt); \n" + " if (featureProperties.a == 0.0) { \n" + // show: alpha == 0 - false, non-zero - true " discard; \n" + " } \n" + - " gl_FragColor = featureProperties; \n" + - " gl_FragColor.rgb *= gl_FragColor.a; \n" + + " out_FragColor = featureProperties; \n" + + " out_FragColor.rgb *= out_FragColor.a; \n" + "} \n"; } return source; @@ -875,7 +875,7 @@ Cesium3DTileBatchTable.prototype.getUniformMapCallback = function () { }; Cesium3DTileBatchTable.prototype.getPickId = function () { - return "texture2D(tile_pickTexture, tile_featureSt)"; + return "texture(tile_pickTexture, tile_featureSt)"; }; /////////////////////////////////////////////////////////////////////////// diff --git a/packages/engine/Source/Scene/ClassificationPrimitive.js b/packages/engine/Source/Scene/ClassificationPrimitive.js index c68c7c4182b4..d0412080fabe 100644 --- a/packages/engine/Source/Scene/ClassificationPrimitive.js +++ b/packages/engine/Source/Scene/ClassificationPrimitive.js @@ -493,22 +493,17 @@ function modifyForEncodedNormals(primitive, vertexShaderSource) { return vertexShaderSource; } - if ( - vertexShaderSource.search(/attribute\s+vec3\s+extrudeDirection;/g) !== -1 - ) { + if (vertexShaderSource.search(/in\s+vec3\s+extrudeDirection;/g) !== -1) { const attributeName = "compressedAttributes"; //only shadow volumes use extrudeDirection, and shadow volumes use vertexFormat: POSITION_ONLY so we don't need to check other attributes - const attributeDecl = `attribute vec2 ${attributeName};`; + const attributeDecl = `in vec2 ${attributeName};`; const globalDecl = "vec3 extrudeDirection;\n"; const decode = ` extrudeDirection = czm_octDecode(${attributeName}, 65535.0);\n`; let modifiedVS = vertexShaderSource; - modifiedVS = modifiedVS.replace( - /attribute\s+vec3\s+extrudeDirection;/g, - "" - ); + modifiedVS = modifiedVS.replace(/in\s+vec3\s+extrudeDirection;/g, ""); modifiedVS = ShaderSource.replaceMain( modifiedVS, "czm_non_compressed_main" diff --git a/packages/engine/Source/Scene/DebugAppearance.js b/packages/engine/Source/Scene/DebugAppearance.js index 3b5608338708..1f2a8e2a978d 100644 --- a/packages/engine/Source/Scene/DebugAppearance.js +++ b/packages/engine/Source/Scene/DebugAppearance.js @@ -88,14 +88,12 @@ function DebugAppearance(options) { const vs = `${ - "attribute vec3 position3DHigh;\n" + - "attribute vec3 position3DLow;\n" + - "attribute float batchId;\n" + "in vec3 position3DHigh;\n" + + "in vec3 position3DLow;\n" + + "in float batchId;\n" }${ - perInstanceAttribute - ? "" - : `attribute ${glslDatatype} ${attributeName};\n` - }varying ${glslDatatype} ${varyingName};\n` + + perInstanceAttribute ? "" : `in ${glslDatatype} ${attributeName};\n` + }out ${glslDatatype} ${varyingName};\n` + `void main()\n` + `{\n` + `vec4 p = czm_translateRelativeToEye(position3DHigh, position3DLow);\n${ @@ -105,10 +103,10 @@ function DebugAppearance(options) { }gl_Position = czm_modelViewProjectionRelativeToEye * p;\n` + `}`; const fs = - `varying ${glslDatatype} ${varyingName};\n${getColor}\n` + + `in ${glslDatatype} ${varyingName};\n${getColor}\n` + `void main()\n` + `{\n` + - `gl_FragColor = getColor();\n` + + `out_FragColor = getColor();\n` + `}`; /** diff --git a/packages/engine/Source/Scene/DebugInspector.js b/packages/engine/Source/Scene/DebugInspector.js index bbb090508d6e..899933f7c915 100644 --- a/packages/engine/Source/Scene/DebugInspector.js +++ b/packages/engine/Source/Scene/DebugInspector.js @@ -31,7 +31,7 @@ function createDebugShowFrustumsShaderProgram(scene, shaderProgram) { const targets = []; fs.sources = fs.sources.map(function (source) { source = ShaderSource.replaceMain(source, "czm_Debug_main"); - const re = /gl_FragData\[(\d+)\]/g; + const re = /out_FragData_(\d+)/g; let match; while ((match = re.exec(source)) !== null) { if (targets.indexOf(match[1]) === -1) { @@ -52,12 +52,12 @@ function createDebugShowFrustumsShaderProgram(scene, shaderProgram) { let i; if (length > 0) { for (i = 0; i < length; ++i) { - newMain += ` gl_FragData[${targets[i]}].rgb *= debugShowCommandsColor;\n`; - newMain += ` gl_FragData[${targets[i]}].rgb *= debugShowFrustumsColor;\n`; + newMain += ` out_FragData_${targets[i]}.rgb *= debugShowCommandsColor;\n`; + newMain += ` out_FragData_${targets[i]}.rgb *= debugShowFrustumsColor;\n`; } } else { - newMain += " gl_FragColor.rgb *= debugShowCommandsColor;\n"; - newMain += " gl_FragColor.rgb *= debugShowFrustumsColor;\n"; + newMain += " out_FragColor.rgb *= debugShowCommandsColor;\n"; + newMain += " out_FragColor.rgb *= debugShowFrustumsColor;\n"; } newMain += "}"; diff --git a/packages/engine/Source/Scene/DepthPlane.js b/packages/engine/Source/Scene/DepthPlane.js index d36d6c9b0d34..75cf1465a75d 100644 --- a/packages/engine/Source/Scene/DepthPlane.js +++ b/packages/engine/Source/Scene/DepthPlane.js @@ -173,12 +173,6 @@ DepthPlane.prototype.update = function (frameState) { sources: [DepthPlaneFS], }); if (useLogDepth) { - const extension = - "#ifdef GL_EXT_frag_depth \n" + - "#extension GL_EXT_frag_depth : enable \n" + - "#endif \n\n"; - - fs.sources.push(extension); fs.defines.push("LOG_DEPTH"); vs.defines.push("LOG_DEPTH"); } diff --git a/packages/engine/Source/Scene/DerivedCommand.js b/packages/engine/Source/Scene/DerivedCommand.js index d5a30d837e88..1a9d6546f2ae 100644 --- a/packages/engine/Source/Scene/DerivedCommand.js +++ b/packages/engine/Source/Scene/DerivedCommand.js @@ -8,7 +8,7 @@ import ShaderSource from "../Renderer/ShaderSource.js"; */ function DerivedCommand() {} -const fragDepthRegex = /\bgl_FragDepthEXT\b/; +const fragDepthRegex = /\bgl_FragDepth\b/; const discardRegex = /\bdiscard\b/; function getDepthOnlyShaderProgram(context, shaderProgram) { @@ -44,18 +44,18 @@ function getDepthOnlyShaderProgram(context, shaderProgram) { let source; if (!writesDepthOrDiscards && !usesLogDepth) { source = - "void main() \n" + "{ \n" + " gl_FragColor = vec4(1.0); \n" + "} \n"; + "void main() \n" + + "{ \n" + + " out_FragColor = vec4(1.0); \n" + + "} \n"; fs = new ShaderSource({ sources: [source], }); } else if (!writesDepthOrDiscards && usesLogDepth) { source = - "#ifdef GL_EXT_frag_depth \n" + - "#extension GL_EXT_frag_depth : enable \n" + - "#endif \n\n" + "void main() \n" + "{ \n" + - " gl_FragColor = vec4(1.0); \n" + + " out_FragColor = vec4(1.0); \n" + " czm_writeLogDepth(); \n" + "} \n"; fs = new ShaderSource({ @@ -145,7 +145,6 @@ DerivedCommand.createDepthOnlyDerivedCommand = function ( const writeLogDepthRegex = /\s+czm_writeLogDepth\(/; const vertexlogDepthRegex = /\s+czm_vertexLogDepth\(/; -const extensionRegex = /\s*#extension\s+GL_EXT_frag_depth\s*:\s*enable/; function getLogDepthShaderProgram(context, shaderProgram) { const disableLogDepthWrite = @@ -210,20 +209,7 @@ function getLogDepthShaderProgram(context, shaderProgram) { writesLogDepth = true; } - let addExtension = true; - for (i = 0; i < length; ++i) { - if (extensionRegex.test(sources[i])) { - addExtension = false; - } - } - let logSource = ""; - if (addExtension) { - logSource += - "#ifdef GL_EXT_frag_depth \n" + - "#extension GL_EXT_frag_depth : enable \n" + - "#endif \n\n"; - } if (!writesLogDepth) { for (i = 0; i < length; i++) { @@ -297,10 +283,10 @@ function getPickShaderProgram(context, shaderProgram, pickId) { "void main() \n" + "{ \n" + " czm_non_pick_main(); \n" + - " if (gl_FragColor.a == 0.0) { \n" + + " if (out_FragColor.a == 0.0) { \n" + " discard; \n" + " } \n" + - " gl_FragColor = " + " out_FragColor = " }${pickId}; \n` + `} \n`; const newSources = new Array(length + 1); for (let i = 0; i < length; ++i) { diff --git a/packages/engine/Source/Scene/EllipsoidPrimitive.js b/packages/engine/Source/Scene/EllipsoidPrimitive.js index e9b0fdd04574..be29bae18217 100644 --- a/packages/engine/Source/Scene/EllipsoidPrimitive.js +++ b/packages/engine/Source/Scene/EllipsoidPrimitive.js @@ -238,11 +238,6 @@ function getVertexArray(context) { return vertexArray; } -const logDepthExtension = - "#ifdef GL_EXT_frag_depth \n" + - "#extension GL_EXT_frag_depth : enable \n" + - "#endif \n\n"; - /** * Called when {@link Viewer} or {@link CesiumWidget} render the scene to * get the draw commands needed to render this primitive. @@ -378,7 +373,6 @@ EllipsoidPrimitive.prototype.update = function (frameState) { if (this._useLogDepth) { vs.defines.push("LOG_DEPTH"); fs.defines.push("LOG_DEPTH"); - fs.sources.push(logDepthExtension); } this._sp = ShaderProgram.replaceCache({ @@ -443,7 +437,6 @@ EllipsoidPrimitive.prototype.update = function (frameState) { if (this._useLogDepth) { vs.defines.push("LOG_DEPTH"); fs.defines.push("LOG_DEPTH"); - fs.sources.push(logDepthExtension); } this._pickSP = ShaderProgram.replaceCache({ diff --git a/packages/engine/Source/Scene/GlobeTranslucencyState.js b/packages/engine/Source/Scene/GlobeTranslucencyState.js index 61fc02135509..6598da066928 100644 --- a/packages/engine/Source/Scene/GlobeTranslucencyState.js +++ b/packages/engine/Source/Scene/GlobeTranslucencyState.js @@ -401,7 +401,7 @@ function getDepthOnlyShaderProgram(vs, fs) { } const depthOnlyShader = - "void main() \n" + "{ \n" + " gl_FragColor = vec4(1.0); \n" + "} \n"; + "void main() \n" + "{ \n" + " out_FragColor = vec4(1.0); \n" + "} \n"; fs.sources = [depthOnlyShader]; } @@ -423,7 +423,7 @@ function getTranslucentShaderProgram(vs, fs) { "{ \n" + " vec2 st = gl_FragCoord.xy / czm_viewport.zw; \n" + "#ifdef MANUAL_DEPTH_TEST \n" + - " float logDepthOrDepth = czm_unpackDepth(texture2D(czm_globeDepthTexture, st)); \n" + + " float logDepthOrDepth = czm_unpackDepth(texture(czm_globeDepthTexture, st)); \n" + " if (logDepthOrDepth != 0.0) \n" + " { \n" + " vec4 eyeCoordinate = czm_windowToEyeCoordinates(gl_FragCoord.xy, logDepthOrDepth); \n" + @@ -435,13 +435,13 @@ function getTranslucentShaderProgram(vs, fs) { " } \n" + "#endif \n" + " czm_globe_translucency_main(); \n" + - " vec4 classificationColor = texture2D(u_classificationTexture, st); \n" + + " vec4 classificationColor = texture(u_classificationTexture, st); \n" + " if (classificationColor.a > 0.0) \n" + " { \n" + " // Reverse premultiplication process to get the correct composited result of the classification primitives \n" + " classificationColor.rgb /= classificationColor.a; \n" + " } \n" + - " gl_FragColor = classificationColor * vec4(classificationColor.aaa, 1.0) + gl_FragColor * (1.0 - classificationColor.a); \n" + + " out_FragColor = classificationColor * vec4(classificationColor.aaa, 1.0) + out_FragColor * (1.0 - classificationColor.a); \n" + "} \n"; sources.push(globeTranslucencyMain); @@ -473,12 +473,12 @@ function getPickShaderProgram(vs, fs) { "void main() \n" + "{ \n" + " vec2 st = gl_FragCoord.xy / czm_viewport.zw; \n" + - " vec4 pickColor = texture2D(u_classificationTexture, st); \n" + + " vec4 pickColor = texture(u_classificationTexture, st); \n" + " if (pickColor == vec4(0.0)) \n" + " { \n" + " discard; \n" + " } \n" + - " gl_FragColor = pickColor; \n" + + " out_FragColor = pickColor; \n" + "} \n"; fs.sources = [pickShader]; diff --git a/packages/engine/Source/Scene/GroundPolylinePrimitive.js b/packages/engine/Source/Scene/GroundPolylinePrimitive.js index efffa484988a..c33e61666170 100644 --- a/packages/engine/Source/Scene/GroundPolylinePrimitive.js +++ b/packages/engine/Source/Scene/GroundPolylinePrimitive.js @@ -405,12 +405,10 @@ function createShaderProgram(groundPolylinePrimitive, frameState, appearance) { // Check for use of v_width and v_polylineAngle in material shader // to determine whether these varyings should be active in the vertex shader. - if ( - materialShaderSource.search(/varying\s+float\s+v_polylineAngle;/g) !== -1 - ) { + if (materialShaderSource.search(/in\s+float\s+v_polylineAngle;/g) !== -1) { vsDefines.push("ANGLE_VARYING"); } - if (materialShaderSource.search(/varying\s+float\s+v_width;/g) !== -1) { + if (materialShaderSource.search(/in\s+float\s+v_width;/g) !== -1) { vsDefines.push("WIDTH_VARYING"); } } else { diff --git a/packages/engine/Source/Scene/InvertClassification.js b/packages/engine/Source/Scene/InvertClassification.js index 3fead5009c91..92922920a8ec 100644 --- a/packages/engine/Source/Scene/InvertClassification.js +++ b/packages/engine/Source/Scene/InvertClassification.js @@ -126,19 +126,18 @@ const rsDefault = { }; const translucentFS = - "#extension GL_EXT_frag_depth : enable\n" + "uniform sampler2D colorTexture;\n" + "uniform sampler2D depthTexture;\n" + "uniform sampler2D classifiedTexture;\n" + - "varying vec2 v_textureCoordinates;\n" + + "in vec2 v_textureCoordinates;\n" + "void main()\n" + "{\n" + - " vec4 color = texture2D(colorTexture, v_textureCoordinates);\n" + + " vec4 color = texture(colorTexture, v_textureCoordinates);\n" + " if (color.a == 0.0)\n" + " {\n" + " discard;\n" + " }\n" + - " bool isClassified = all(equal(texture2D(classifiedTexture, v_textureCoordinates), vec4(0.0)));\n" + + " bool isClassified = all(equal(texture(classifiedTexture, v_textureCoordinates), vec4(0.0)));\n" + "#ifdef UNCLASSIFIED\n" + " vec4 highlightColor = czm_invertClassificationColor;\n" + " if (isClassified)\n" + @@ -152,24 +151,24 @@ const translucentFS = " discard;\n" + " }\n" + "#endif\n" + - " gl_FragColor = color * highlightColor;\n" + - " gl_FragDepthEXT = texture2D(depthTexture, v_textureCoordinates).r;\n" + + " out_FragColor = color * highlightColor;\n" + + " gl_FragDepth = texture(depthTexture, v_textureCoordinates).r;\n" + "}\n"; const opaqueFS = "uniform sampler2D colorTexture;\n" + - "varying vec2 v_textureCoordinates;\n" + + "in vec2 v_textureCoordinates;\n" + "void main()\n" + "{\n" + - " vec4 color = texture2D(colorTexture, v_textureCoordinates);\n" + + " vec4 color = texture(colorTexture, v_textureCoordinates);\n" + " if (color.a == 0.0)\n" + " {\n" + " discard;\n" + " }\n" + "#ifdef UNCLASSIFIED\n" + - " gl_FragColor = color * czm_invertClassificationColor;\n" + + " out_FragColor = color * czm_invertClassificationColor;\n" + "#else\n" + - " gl_FragColor = color;\n" + + " out_FragColor = color;\n" + "#endif\n" + "}\n"; diff --git a/packages/engine/Source/Scene/Material.js b/packages/engine/Source/Scene/Material.js index 8198e4499f54..a2380e9481e6 100644 --- a/packages/engine/Source/Scene/Material.js +++ b/packages/engine/Source/Scene/Material.js @@ -1264,8 +1264,8 @@ Material._materialCache.addMaterial(Material.ImageType, { }, components: { diffuse: - "texture2D(image, fract(repeat * materialInput.st)).rgb * color.rgb", - alpha: "texture2D(image, fract(repeat * materialInput.st)).a * color.a", + "texture(image, fract(repeat * materialInput.st)).rgb * color.rgb", + alpha: "texture(image, fract(repeat * materialInput.st)).a * color.a", }, }, translucent: function (material) { @@ -1288,7 +1288,7 @@ Material._materialCache.addMaterial(Material.DiffuseMapType, { repeat: new Cartesian2(1.0, 1.0), }, components: { - diffuse: "texture2D(image, fract(repeat * materialInput.st)).channels", + diffuse: "texture(image, fract(repeat * materialInput.st)).channels", }, }, translucent: false, @@ -1309,7 +1309,7 @@ Material._materialCache.addMaterial(Material.AlphaMapType, { repeat: new Cartesian2(1.0, 1.0), }, components: { - alpha: "texture2D(image, fract(repeat * materialInput.st)).channel", + alpha: "texture(image, fract(repeat * materialInput.st)).channel", }, }, translucent: true, @@ -1330,7 +1330,7 @@ Material._materialCache.addMaterial(Material.SpecularMapType, { repeat: new Cartesian2(1.0, 1.0), }, components: { - specular: "texture2D(image, fract(repeat * materialInput.st)).channel", + specular: "texture(image, fract(repeat * materialInput.st)).channel", }, }, translucent: false, @@ -1351,7 +1351,7 @@ Material._materialCache.addMaterial(Material.EmissionMapType, { repeat: new Cartesian2(1.0, 1.0), }, components: { - emission: "texture2D(image, fract(repeat * materialInput.st)).channels", + emission: "texture(image, fract(repeat * materialInput.st)).channels", }, }, translucent: false, diff --git a/packages/engine/Source/Scene/Megatexture.js b/packages/engine/Source/Scene/Megatexture.js index d9951235d381..5e9db2fc72af 100644 --- a/packages/engine/Source/Scene/Megatexture.js +++ b/packages/engine/Source/Scene/Megatexture.js @@ -63,9 +63,9 @@ function Megatexture( let pixelFormat; if (channelCount === 1) { - pixelFormat = PixelFormat.LUMINANCE; + pixelFormat = context.webgl2 ? PixelFormat.RED : PixelFormat.LUMINANCE; } else if (channelCount === 2) { - pixelFormat = PixelFormat.LUMINANCE_ALPHA; + pixelFormat = context.webgl2 ? PixelFormat.RG : PixelFormat.LUMINANCE_ALPHA; } else if (channelCount === 3) { pixelFormat = PixelFormat.RGB; } else if (channelCount === 4) { diff --git a/packages/engine/Source/Scene/Model/CustomShader.js b/packages/engine/Source/Scene/Model/CustomShader.js index fc221f843fc2..463d277dcb7e 100644 --- a/packages/engine/Source/Scene/Model/CustomShader.js +++ b/packages/engine/Source/Scene/Model/CustomShader.js @@ -113,7 +113,7 @@ import CustomShaderTranslucencyMode from "./CustomShaderTranslucencyMode.js"; * `, * fragmentShaderText: ` * void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material) { - * material.normal = texture2D(u_normalMap, fsInput.attributes.texCoord_0); + * material.normal = texture(u_normalMap, fsInput.attributes.texCoord_0); * material.diffuse = v_selectedColor; * } * ` diff --git a/packages/engine/Source/Scene/Model/FeatureIdPipelineStage.js b/packages/engine/Source/Scene/Model/FeatureIdPipelineStage.js index 071660b4470f..6448b5984265 100644 --- a/packages/engine/Source/Scene/Model/FeatureIdPipelineStage.js +++ b/packages/engine/Source/Scene/Model/FeatureIdPipelineStage.js @@ -295,13 +295,13 @@ function processImplicitRange( ); // Declare the vertex attribute in the shader - // Example: attribute float a_implicit_feature_id_n; + // Example: in float a_implicit_feature_id_n; const shaderBuilder = renderResources.shaderBuilder; const implicitAttributeName = `a_implicit_${variableName}`; shaderBuilder.addAttribute("float", implicitAttributeName); // Also declare the corresponding varyings - // Example: varying float v_implicit_feature_id_n; + // Example: in float v_implicit_feature_id_n; const implicitVaryingName = `v_implicit_${variableName}`; shaderBuilder.addVarying("float", implicitVaryingName); @@ -388,9 +388,9 @@ function processTexture( ); // Read one or more channels from the texture - // example: texture2D(u_featureIdTexture_0, v_texCoord_1).rg + // example: texture(u_featureIdTexture_0, v_texCoord_1).rg const texCoord = `v_texCoord_${textureReader.texCoord}`; - const textureRead = `texture2D(${uniformName}, ${texCoord}).${channels}`; + const textureRead = `texture(${uniformName}, ${texCoord}).${channels}`; // Finally, assign to the struct field. Example: // featureIds.featureId_0 = unpacked; diff --git a/packages/engine/Source/Scene/Model/LightingModel.js b/packages/engine/Source/Scene/Model/LightingModel.js index 675ee3c5f9d3..f36715f3271f 100644 --- a/packages/engine/Source/Scene/Model/LightingModel.js +++ b/packages/engine/Source/Scene/Model/LightingModel.js @@ -9,7 +9,7 @@ const LightingModel = { /** * Use unlit shading, i.e. skip lighting calculations. The model's * diffuse color (assumed to be linear RGB, not sRGB) is used directly - * when computing gl_FragColor. The alpha mode is still + * when computing out_FragColor. The alpha mode is still * applied. * * @type {Number} diff --git a/packages/engine/Source/Scene/Model/MetadataPipelineStage.js b/packages/engine/Source/Scene/Model/MetadataPipelineStage.js index 20281d7627d0..df4ba81ceae3 100644 --- a/packages/engine/Source/Scene/Model/MetadataPipelineStage.js +++ b/packages/engine/Source/Scene/Model/MetadataPipelineStage.js @@ -452,7 +452,7 @@ function addPropertyTexturePropertyMetadata(renderResources, propertyInfo) { // Get a GLSL expression for the value of the property const texCoordVariable = `attributes.texCoord_${texCoord}`; - const valueExpression = `texture2D(${textureUniformName}, ${texCoordVariable}).${channels}`; + const valueExpression = `texture(${textureUniformName}, ${texCoordVariable}).${channels}`; // Some types need an unpacking step or two. For example, since texture reads // are always normalized, UINT8 (not normalized) properties need to be diff --git a/packages/engine/Source/Scene/Model/PickingPipelineStage.js b/packages/engine/Source/Scene/Model/PickingPipelineStage.js index aca03edde00a..166f71e814f8 100644 --- a/packages/engine/Source/Scene/Model/PickingPipelineStage.js +++ b/packages/engine/Source/Scene/Model/PickingPipelineStage.js @@ -157,7 +157,7 @@ function processPickTexture(renderResources, primitive, instances) { // The feature ID is ignored if it is greater than the number of features. renderResources.pickId = - "((selectedFeature.id < int(model_featuresLength)) ? texture2D(model_pickTexture, selectedFeature.st) : vec4(0.0))"; + "((selectedFeature.id < int(model_featuresLength)) ? texture(model_pickTexture, selectedFeature.st) : vec4(0.0))"; } function processInstancedPickIds(renderResources, context) { diff --git a/packages/engine/Source/Scene/OIT.js b/packages/engine/Source/Scene/OIT.js index 5cbe1ee52cab..8e3d4accaafe 100644 --- a/packages/engine/Source/Scene/OIT.js +++ b/packages/engine/Source/Scene/OIT.js @@ -18,6 +18,8 @@ import BlendFunction from "./BlendFunction.js"; /** * @private + * @constructor + * @param {Context} context */ function OIT(context) { this._numSamples = 1; @@ -90,6 +92,10 @@ function OIT(context) { this._useHDR = false; } +/** + * @private + * @param {OIT} oit + */ function destroyTextures(oit) { oit._accumulationTexture = oit._accumulationTexture && @@ -101,6 +107,10 @@ function destroyTextures(oit) { oit._revealageTexture.destroy(); } +/** + * @private + * @param {OIT} oit + */ function destroyFramebuffers(oit) { oit._translucentFBO.destroy(); oit._alphaFBO.destroy(); @@ -108,11 +118,22 @@ function destroyFramebuffers(oit) { oit._adjustAlphaFBO.destroy(); } +/** + * @private + * @param {OIT} oit + */ function destroyResources(oit) { destroyTextures(oit); destroyFramebuffers(oit); } +/** + * @private + * @param {OIT} oit + * @param {Context} context + * @param {Number} width + * @param {Number} height + */ function updateTextures(oit, context, width, height) { destroyTextures(oit); @@ -140,14 +161,19 @@ function updateTextures(oit, context, width, height) { }); } +/** + * @private + * @param {OIT} oit + * @param {Context} context + * @returns {Boolean} + */ function updateFramebuffers(oit, context) { destroyFramebuffers(oit); const completeFBO = WebGLConstants.FRAMEBUFFER_COMPLETE; let supported = true; - const width = oit._accumulationTexture.width; - const height = oit._accumulationTexture.height; + const { width, height } = oit._accumulationTexture; // if MRT is supported, attempt to make an FBO with multiple color attachments if (oit._translucentMRTSupport) { @@ -205,6 +231,14 @@ function updateFramebuffers(oit, context) { return supported; } +/** + * @private + * @param {Context} context + * @param {PassState} passState + * @param {Framebuffer} framebuffer + * @param {Boolean} useHDR + * @param {Number} numSamples + */ OIT.prototype.update = function ( context, passState, @@ -220,8 +254,7 @@ OIT.prototype.update = function ( this._opaqueTexture = framebuffer.getColorTexture(0); this._depthStencilTexture = framebuffer.getDepthStencilTexture(); - const width = this._opaqueTexture.width; - const height = this._opaqueTexture.height; + const { width, height } = this._opaqueTexture; const accumulationTexture = this._accumulationTexture; const textureChanged = @@ -458,76 +491,83 @@ function getTranslucentAlphaRenderState(oit, context, renderState) { } const mrtShaderSource = - " vec3 Ci = czm_gl_FragColor.rgb * czm_gl_FragColor.a;\n" + - " float ai = czm_gl_FragColor.a;\n" + + " vec3 Ci = czm_out_FragColor.rgb * czm_out_FragColor.a;\n" + + " float ai = czm_out_FragColor.a;\n" + " float wzi = czm_alphaWeight(ai);\n" + - " gl_FragData[0] = vec4(Ci * wzi, ai);\n" + - " gl_FragData[1] = vec4(ai * wzi);\n"; + " out_FragData_0 = vec4(Ci * wzi, ai);\n" + + " out_FragData_1 = vec4(ai * wzi);\n"; const colorShaderSource = - " vec3 Ci = czm_gl_FragColor.rgb * czm_gl_FragColor.a;\n" + - " float ai = czm_gl_FragColor.a;\n" + + " vec3 Ci = czm_out_FragColor.rgb * czm_out_FragColor.a;\n" + + " float ai = czm_out_FragColor.a;\n" + " float wzi = czm_alphaWeight(ai);\n" + - " gl_FragColor = vec4(Ci, ai) * wzi;\n"; + " out_FragColor = vec4(Ci, ai) * wzi;\n"; const alphaShaderSource = - " float ai = czm_gl_FragColor.a;\n" + " gl_FragColor = vec4(ai);\n"; + " float ai = czm_out_FragColor.a;\n" + " out_FragColor = vec4(ai);\n"; +/** + * @private + * @param {Context} context + * @param {ShaderProgram} shaderProgram + * @param {String} keyword + * @param {String} source + * @returns {ShaderProgram} + */ function getTranslucentShaderProgram(context, shaderProgram, keyword, source) { - let shader = context.shaderCache.getDerivedShaderProgram( - shaderProgram, - keyword - ); - if (!defined(shader)) { - const attributeLocations = shaderProgram._attributeLocations; - - const fs = shaderProgram.fragmentShaderSource.clone(); - - fs.sources = fs.sources.map(function (source) { - source = ShaderSource.replaceMain(source, "czm_translucent_main"); - source = source.replace(/gl_FragColor/g, "czm_gl_FragColor"); - source = source.replace(/\bdiscard\b/g, "czm_discard = true"); - source = source.replace(/czm_phong/g, "czm_translucentPhong"); - return source; - }); + const { shaderCache } = context; + const shader = shaderCache.getDerivedShaderProgram(shaderProgram, keyword); + if (defined(shader)) { + return shader; + } - // Discarding the fragment in main is a workaround for ANGLE D3D9 - // shader compilation errors. - - fs.sources.splice( - 0, - 0, - `${ - source.indexOf("gl_FragData") !== -1 - ? "#extension GL_EXT_draw_buffers : enable \n" - : "" - }vec4 czm_gl_FragColor;\n` + `bool czm_discard = false;\n` - ); + const attributeLocations = shaderProgram._attributeLocations; + const fs = shaderProgram.fragmentShaderSource.clone(); + + fs.sources = fs.sources.map(function (fsSource) { + return ShaderSource.replaceMain(fsSource, "czm_translucent_main") + .replace(/out_FragColor/g, "czm_out_FragColor") + .replace( + /layout\s*\(location\s*=\s*0\)\s*out\s+vec4\s+out_FragColor;/g, + "" + ) + .replace(/\bdiscard\b/g, "czm_discard = true") + .replace(/czm_phong/g, "czm_translucentPhong"); + }); - fs.sources.push( - `${ - "void main()\n" + - "{\n" + - " czm_translucent_main();\n" + - " if (czm_discard)\n" + - " {\n" + - " discard;\n" + - " }\n" - }${source}}\n` - ); + // Discarding the fragment in main is a workaround for ANGLE D3D9 + // shader compilation errors. + fs.sources.splice( + 0, + 0, + `vec4 czm_out_FragColor;\n` + `bool czm_discard = false;\n` + ); - shader = context.shaderCache.createDerivedShaderProgram( - shaderProgram, - keyword, - { - vertexShaderSource: shaderProgram.vertexShaderSource, - fragmentShaderSource: fs, - attributeLocations: attributeLocations, - } - ); + const fragDataMatches = [...source.matchAll(/out_FragData_(\d+)/g)]; + let fragDataDeclarations = ``; + for (let i = 0; i < fragDataMatches.length; i++) { + const fragDataMatch = fragDataMatches[i]; + fragDataDeclarations = `layout (location = ${fragDataMatch[1]}) out vec4 ${fragDataMatch[0]};\n${fragDataDeclarations}`; } + fs.sources.push(fragDataDeclarations); + + fs.sources.push( + `${ + "void main()\n" + + "{\n" + + " czm_translucent_main();\n" + + " if (czm_discard)\n" + + " {\n" + + " discard;\n" + + " }\n" + }${source}}\n` + ); - return shader; + return shaderCache.createDerivedShaderProgram(shaderProgram, keyword, { + vertexShaderSource: shaderProgram.vertexShaderSource, + fragmentShaderSource: fs, + attributeLocations: attributeLocations, + }); } function getTranslucentMRTShaderProgram(context, shaderProgram) { @@ -557,6 +597,13 @@ function getTranslucentAlphaShaderProgram(context, shaderProgram) { ); } +/** + * @private + * @param {DrawCommand} command + * @param {Context} context + * @param {*} result + * @returns {*} + */ OIT.prototype.createDerivedCommands = function (command, context, result) { if (!defined(result)) { result = {}; @@ -593,61 +640,68 @@ OIT.prototype.createDerivedCommands = function (command, context, result) { result.translucentCommand.shaderProgram = translucentShader; result.translucentCommand.renderState = translucentRenderState; } - } else { - let colorShader; - let colorRenderState; - let alphaShader; - let alphaRenderState; - if (defined(result.translucentCommand)) { - colorShader = result.translucentCommand.shaderProgram; - colorRenderState = result.translucentCommand.renderState; - alphaShader = result.alphaCommand.shaderProgram; - alphaRenderState = result.alphaCommand.renderState; - } + return result; + } - result.translucentCommand = DrawCommand.shallowClone( - command, - result.translucentCommand + let colorShader; + let colorRenderState; + let alphaShader; + let alphaRenderState; + if (defined(result.translucentCommand)) { + colorShader = result.translucentCommand.shaderProgram; + colorRenderState = result.translucentCommand.renderState; + alphaShader = result.alphaCommand.shaderProgram; + alphaRenderState = result.alphaCommand.renderState; + } + + result.translucentCommand = DrawCommand.shallowClone( + command, + result.translucentCommand + ); + result.alphaCommand = DrawCommand.shallowClone(command, result.alphaCommand); + + if ( + !defined(colorShader) || + result.shaderProgramId !== command.shaderProgram.id + ) { + result.translucentCommand.shaderProgram = getTranslucentColorShaderProgram( + context, + command.shaderProgram ); - result.alphaCommand = DrawCommand.shallowClone( - command, - result.alphaCommand + result.translucentCommand.renderState = getTranslucentColorRenderState( + this, + context, + command.renderState ); - - if ( - !defined(colorShader) || - result.shaderProgramId !== command.shaderProgram.id - ) { - result.translucentCommand.shaderProgram = getTranslucentColorShaderProgram( - context, - command.shaderProgram - ); - result.translucentCommand.renderState = getTranslucentColorRenderState( - this, - context, - command.renderState - ); - result.alphaCommand.shaderProgram = getTranslucentAlphaShaderProgram( - context, - command.shaderProgram - ); - result.alphaCommand.renderState = getTranslucentAlphaRenderState( - this, - context, - command.renderState - ); - result.shaderProgramId = command.shaderProgram.id; - } else { - result.translucentCommand.shaderProgram = colorShader; - result.translucentCommand.renderState = colorRenderState; - result.alphaCommand.shaderProgram = alphaShader; - result.alphaCommand.renderState = alphaRenderState; - } + result.alphaCommand.shaderProgram = getTranslucentAlphaShaderProgram( + context, + command.shaderProgram + ); + result.alphaCommand.renderState = getTranslucentAlphaRenderState( + this, + context, + command.renderState + ); + result.shaderProgramId = command.shaderProgram.id; + } else { + result.translucentCommand.shaderProgram = colorShader; + result.translucentCommand.renderState = colorRenderState; + result.alphaCommand.shaderProgram = alphaShader; + result.alphaCommand.renderState = alphaRenderState; } return result; }; +/** + * @private + * @param {OIT} oit + * @param {Scene} scene + * @param {Function} executeFunction + * @param {PassState} passState + * @param {DrawCommand[]} commands + * @param {InvertClassification} invertClassification + */ function executeTranslucentCommandsSortedMultipass( oit, scene, @@ -660,13 +714,12 @@ function executeTranslucentCommandsSortedMultipass( let derivedCommand; let j; - const context = scene.context; - const useLogDepth = scene.frameState.useLogDepth; + const { context, frameState } = scene; + const { useLogDepth, shadowState } = frameState; const useHdr = scene._hdr; const framebuffer = passState.framebuffer; - const length = commands.length; - const lightShadowsEnabled = scene.frameState.shadowState.lightShadowsEnabled; + const lightShadowsEnabled = shadowState.lightShadowsEnabled; passState.framebuffer = oit._adjustTranslucentFBO.framebuffer; oit._adjustTranslucentCommand.execute(context, passState); @@ -676,7 +729,7 @@ function executeTranslucentCommandsSortedMultipass( const debugFramebuffer = oit._opaqueFBO.framebuffer; passState.framebuffer = oit._translucentFBO.framebuffer; - for (j = 0; j < length; ++j) { + for (j = 0; j < commands.length; ++j) { command = commands[j]; command = useLogDepth ? command.derivedCommands.logDepth.command : command; command = useHdr ? command.derivedCommands.hdr.command : command; @@ -710,7 +763,7 @@ function executeTranslucentCommandsSortedMultipass( passState.framebuffer = oit._alphaFBO.framebuffer; - for (j = 0; j < length; ++j) { + for (j = 0; j < commands.length; ++j) { command = commands[j]; command = useLogDepth ? command.derivedCommands.logDepth.command : command; command = useHdr ? command.derivedCommands.hdr.command : command; @@ -745,6 +798,15 @@ function executeTranslucentCommandsSortedMultipass( passState.framebuffer = framebuffer; } +/** + * @private + * @param {OIT} oit + * @param {Scene} scene + * @param {Function} executeFunction + * @param {PassState} passState + * @param {DrawCommand[]} commands + * @param {InvertClassification} invertClassification + */ function executeTranslucentCommandsSortedMRT( oit, scene, @@ -753,13 +815,12 @@ function executeTranslucentCommandsSortedMRT( commands, invertClassification ) { - const context = scene.context; - const useLogDepth = scene.frameState.useLogDepth; + const { context, frameState } = scene; + const { useLogDepth, shadowState } = frameState; const useHdr = scene._hdr; const framebuffer = passState.framebuffer; - const length = commands.length; - const lightShadowsEnabled = scene.frameState.shadowState.lightShadowsEnabled; + const lightShadowsEnabled = shadowState.lightShadowsEnabled; passState.framebuffer = oit._adjustTranslucentFBO.framebuffer; oit._adjustTranslucentCommand.execute(context, passState); @@ -770,7 +831,7 @@ function executeTranslucentCommandsSortedMRT( let command; let derivedCommand; - for (let j = 0; j < length; ++j) { + for (let j = 0; j < commands.length; ++j) { command = commands[j]; command = useLogDepth ? command.derivedCommands.logDepth.command : command; command = useHdr ? command.derivedCommands.hdr.command : command; @@ -805,6 +866,14 @@ function executeTranslucentCommandsSortedMRT( passState.framebuffer = framebuffer; } +/** + * @private + * @param {Scene} scene + * @param {Function} executeFunction + * @param {PassState} passState + * @param {DrawCommand[]} commands + * @param {InvertClassification} invertClassification + */ OIT.prototype.executeCommands = function ( scene, executeFunction, @@ -834,10 +903,21 @@ OIT.prototype.executeCommands = function ( ); }; +/** + * @private + * @param {Context} context + * @param {PassState} passState + */ OIT.prototype.execute = function (context, passState) { this._compositeCommand.execute(context, passState); }; +/** + * @private + * @param {Context} context + * @param {PassState} passState + * @param {Color} clearColor + */ OIT.prototype.clear = function (context, passState, clearColor) { const framebuffer = passState.framebuffer; @@ -859,14 +939,25 @@ OIT.prototype.clear = function (context, passState, clearColor) { passState.framebuffer = framebuffer; }; +/** + * @private + * @returns {Boolean} + */ OIT.prototype.isSupported = function () { return this._translucentMRTSupport || this._translucentMultipassSupport; }; +/** + * @private + * @returns {Boolean} + */ OIT.prototype.isDestroyed = function () { return false; }; +/** + * @private + */ OIT.prototype.destroy = function () { destroyResources(this); @@ -890,4 +981,5 @@ OIT.prototype.destroy = function () { return destroyObject(this); }; + export default OIT; diff --git a/packages/engine/Source/Scene/PickDepth.js b/packages/engine/Source/Scene/PickDepth.js index 459929e6f457..19b246252623 100644 --- a/packages/engine/Source/Scene/PickDepth.js +++ b/packages/engine/Source/Scene/PickDepth.js @@ -32,10 +32,10 @@ function updateCopyCommands(pickDepth, context, depthTexture) { if (!defined(pickDepth._copyDepthCommand)) { const fs = "uniform highp sampler2D u_texture;\n" + - "varying vec2 v_textureCoordinates;\n" + + "in vec2 v_textureCoordinates;\n" + "void main()\n" + "{\n" + - " gl_FragColor = czm_packDepth(texture2D(u_texture, v_textureCoordinates).r);\n" + + " out_FragColor = czm_packDepth(texture(u_texture, v_textureCoordinates).r);\n" + "}\n"; pickDepth._copyDepthCommand = context.createViewportQuadCommand(fs, { renderState: RenderState.fromCache(), diff --git a/packages/engine/Source/Scene/PointCloud.js b/packages/engine/Source/Scene/PointCloud.js index b8c18a07c6c4..a5e94aad2fbc 100644 --- a/packages/engine/Source/Scene/PointCloud.js +++ b/packages/engine/Source/Scene/PointCloud.js @@ -947,15 +947,15 @@ function createShaders(pointCloud, frameState, style) { attributeType = `vec${componentCount}`; } - attributeDeclarations += `attribute ${attributeType} ${attributeName}; \n`; + attributeDeclarations += `in ${attributeType} ${attributeName}; \n`; attributeLocations[attributeName] = attribute.location; } createUniformMap(pointCloud, frameState); let vs = - "attribute vec3 a_position; \n" + - "varying vec4 v_color; \n" + + "in vec3 a_position; \n" + + "out vec4 v_color; \n" + "uniform vec4 u_pointSizeAndTimeAndGeometricErrorAndDepthMultiplier; \n" + "uniform vec4 u_constantColor; \n" + "uniform vec4 u_highlightColor; \n"; @@ -972,10 +972,10 @@ function createShaders(pointCloud, frameState, style) { if (usesColors) { if (isTranslucent) { - vs += "attribute vec4 a_color; \n"; + vs += "in vec4 a_color; \n"; } else if (isRGB565) { vs += - "attribute float a_color; \n" + + "in float a_color; \n" + "const float SHIFT_RIGHT_11 = 1.0 / 2048.0; \n" + "const float SHIFT_RIGHT_5 = 1.0 / 32.0; \n" + "const float SHIFT_LEFT_11 = 2048.0; \n" + @@ -983,19 +983,19 @@ function createShaders(pointCloud, frameState, style) { "const float NORMALIZE_6 = 1.0 / 64.0; \n" + "const float NORMALIZE_5 = 1.0 / 32.0; \n"; } else { - vs += "attribute vec3 a_color; \n"; + vs += "in vec3 a_color; \n"; } } if (usesNormals) { if (isOctEncoded16P || isOctEncodedDraco) { - vs += "attribute vec2 a_normal; \n"; + vs += "in vec2 a_normal; \n"; } else { - vs += "attribute vec3 a_normal; \n"; + vs += "in vec3 a_normal; \n"; } } if (hasBatchIds) { - vs += "attribute float a_batchId; \n"; + vs += "in float a_batchId; \n"; } if (isQuantized || isQuantizedDraco || isOctEncodedDraco) { @@ -1121,7 +1121,7 @@ function createShaders(pointCloud, frameState, style) { vs += "} \n"; - let fs = "varying vec4 v_color; \n"; + let fs = "in vec4 v_color; \n"; if (hasClippedContent) { fs += @@ -1136,7 +1136,7 @@ function createShaders(pointCloud, frameState, style) { fs += "void main() \n" + "{ \n" + - " gl_FragColor = czm_gammaCorrect(v_color); \n"; + " out_FragColor = czm_gammaCorrect(v_color); \n"; if (hasClippedContent) { fs += getClipAndStyleCode( diff --git a/packages/engine/Source/Scene/PointCloudEyeDomeLighting.js b/packages/engine/Source/Scene/PointCloudEyeDomeLighting.js index 3d97a7a0af42..e247beac473f 100644 --- a/packages/engine/Source/Scene/PointCloudEyeDomeLighting.js +++ b/packages/engine/Source/Scene/PointCloudEyeDomeLighting.js @@ -126,25 +126,30 @@ function getECShaderProgram(context, shaderProgram) { const fs = shaderProgram.fragmentShaderSource.clone(); + fs.sources.splice( + 0, + 0, + `layout (location = 0) out vec4 out_FragData_0;\nlayout (location = 1) out vec4 out_FragData_1;` + ); + fs.sources = fs.sources.map(function (source) { source = ShaderSource.replaceMain( source, "czm_point_cloud_post_process_main" ); - source = source.replace(/gl_FragColor/g, "gl_FragData[0]"); + source = source.replaceAll(/out_FragColor/g, "out_FragData_0"); return source; }); - fs.sources.unshift("#extension GL_EXT_draw_buffers : enable \n"); fs.sources.push( "void main() \n" + "{ \n" + " czm_point_cloud_post_process_main(); \n" + "#ifdef LOG_DEPTH\n" + " czm_writeLogDepth();\n" + - " gl_FragData[1] = czm_packDepth(gl_FragDepthEXT); \n" + + " out_FragData_1 = czm_packDepth(gl_FragDepth); \n" + "#else\n" + - " gl_FragData[1] = czm_packDepth(gl_FragCoord.z);\n" + + " out_FragData_1 = czm_packDepth(gl_FragCoord.z);\n" + "#endif\n" + "}" ); diff --git a/packages/engine/Source/Scene/PolylineCollection.js b/packages/engine/Source/Scene/PolylineCollection.js index 6913657cff5c..3f9150479a0a 100644 --- a/packages/engine/Source/Scene/PolylineCollection.js +++ b/packages/engine/Source/Scene/PolylineCollection.js @@ -1294,8 +1294,7 @@ PolylineBucket.prototype.updateShader = function ( // Check for use of v_polylineAngle in material shader if ( - this.material.shaderSource.search(/varying\s+float\s+v_polylineAngle;/g) !== - -1 + this.material.shaderSource.search(/in\s+float\s+v_polylineAngle;/g) !== -1 ) { defines.push("POLYLINE_DASH"); } @@ -1306,11 +1305,7 @@ PolylineBucket.prototype.updateShader = function ( const fs = new ShaderSource({ defines: defines, - sources: [ - "varying vec4 v_pickColor;\n", - this.material.shaderSource, - PolylineFS, - ], + sources: ["in vec4 v_pickColor;\n", this.material.shaderSource, PolylineFS], }); const vsSource = batchTable.getVertexShaderCallback()(PolylineVS); diff --git a/packages/engine/Source/Scene/PolylineMaterialAppearance.js b/packages/engine/Source/Scene/PolylineMaterialAppearance.js index 91a5c1d72ccf..01f961149910 100644 --- a/packages/engine/Source/Scene/PolylineMaterialAppearance.js +++ b/packages/engine/Source/Scene/PolylineMaterialAppearance.js @@ -111,9 +111,8 @@ Object.defineProperties(PolylineMaterialAppearance.prototype, { get: function () { let vs = this._vertexShaderSource; if ( - this.material.shaderSource.search( - /varying\s+float\s+v_polylineAngle;/g - ) !== -1 + this.material.shaderSource.search(/in\s+float\s+v_polylineAngle;/g) !== + -1 ) { vs = `#define POLYLINE_DASH\n${vs}`; } diff --git a/packages/engine/Source/Scene/PostProcessStage.js b/packages/engine/Source/Scene/PostProcessStage.js index 49f80de5712d..1af387e0ae54 100644 --- a/packages/engine/Source/Scene/PostProcessStage.js +++ b/packages/engine/Source/Scene/PostProcessStage.js @@ -40,7 +40,7 @@ import PostProcessStageSampleMode from "./PostProcessStageSampleMode.js"; * * @exception {DeveloperError} options.textureScale must be greater than 0.0 and less than or equal to 1.0. * @exception {DeveloperError} options.pixelFormat must be a color format. - * @exception {DeveloperError} When options.pixelDatatype is FLOAT, this WebGL implementation must support the OES_texture_float extension. Check context.floatingPointTexture. + * @exception {DeveloperError} When options.pixelDatatype is FLOAT, this WebGL implementation must support floating point textures. Check context.floatingPointTexture. * * @see PostProcessStageComposite * @@ -48,12 +48,12 @@ import PostProcessStageSampleMode from "./PostProcessStageSampleMode.js"; * // Simple stage to change the color * const fs =` * uniform sampler2D colorTexture; - * varying vec2 v_textureCoordinates; + * in vec2 v_textureCoordinates; * uniform float scale; * uniform vec3 offset; * void main() { - * vec4 color = texture2D(colorTexture, v_textureCoordinates); - * gl_FragColor = vec4(color.rgb * scale + offset, 1.0); + * vec4 color = texture(colorTexture, v_textureCoordinates); + * out_FragColor = vec4(color.rgb * scale + offset, 1.0); * }`; * scene.postProcessStages.add(new Cesium.PostProcessStage({ * fragmentShader : fs, @@ -70,15 +70,15 @@ import PostProcessStageSampleMode from "./PostProcessStageSampleMode.js"; * // If czm_selected returns true, the current fragment belongs to geometry in the selected array. * const fs =` * uniform sampler2D colorTexture; - * varying vec2 v_textureCoordinates; + * in vec2 v_textureCoordinates; * uniform vec4 highlight; * void main() { - * vec4 color = texture2D(colorTexture, v_textureCoordinates); + * vec4 color = texture(colorTexture, v_textureCoordinates); * if (czm_selected()) { * vec3 highlighted = highlight.a * highlight.rgb + (1.0 - highlight.a) * color.rgb; - * gl_FragColor = vec4(highlighted, 1.0); + * out_FragColor = vec4(highlighted, 1.0); * } else { - * gl_FragColor = color; + * out_FragColor = color; * } * }`; * const stage = scene.postProcessStages.add(new Cesium.PostProcessStage({ @@ -364,7 +364,7 @@ Object.defineProperties(PostProcessStage.prototype, { * if (czm_selected(v_textureCoordinates)) { * // apply post-process stage * } else { - * gl_FragColor = texture2D(colorTexture, v_textureCoordinates); + * out_FragColor = texture(colorTexture, v_textureCoordinates); * } * *

@@ -556,22 +556,22 @@ function createDrawCommand(stage, context) { if (defined(stage._selectedIdTexture)) { const width = stage._selectedIdTexture.width; - fs = fs.replace(/varying\s+vec2\s+v_textureCoordinates;/g, ""); + fs = fs.replace(/in\s+vec2\s+v_textureCoordinates;/g, ""); fs = `${ "#define CZM_SELECTED_FEATURE \n" + "uniform sampler2D czm_idTexture; \n" + "uniform sampler2D czm_selectedIdTexture; \n" + "uniform float czm_selectedIdTextureStep; \n" + - "varying vec2 v_textureCoordinates; \n" + + "in vec2 v_textureCoordinates; \n" + "bool czm_selected(vec2 offset) \n" + "{ \n" + " bool selected = false;\n" + - " vec4 id = texture2D(czm_idTexture, v_textureCoordinates + offset); \n" + + " vec4 id = texture(czm_idTexture, v_textureCoordinates + offset); \n" + " for (int i = 0; i < " }${width}; ++i) \n` + ` { \n` + - ` vec4 selectedId = texture2D(czm_selectedIdTexture, vec2((float(i) + 0.5) * czm_selectedIdTextureStep, 0.5)); \n` + + ` vec4 selectedId = texture(czm_selectedIdTexture, vec2((float(i) + 0.5) * czm_selectedIdTextureStep, 0.5)); \n` + ` if (all(equal(id, selectedId))) \n` + ` { \n` + ` return true; \n` + diff --git a/packages/engine/Source/Scene/PostProcessStageLibrary.js b/packages/engine/Source/Scene/PostProcessStageLibrary.js index 5dadb1112cad..73db1b8adcf6 100644 --- a/packages/engine/Source/Scene/PostProcessStageLibrary.js +++ b/packages/engine/Source/Scene/PostProcessStageLibrary.js @@ -283,7 +283,7 @@ function getSilhouetteEdgeDetection(edgeDetectionStages) { for (let i = 0; i < edgeDetectionStages.length; ++i) { fsDecl += `uniform sampler2D edgeTexture${i}; \n`; fsLoop += - ` vec4 edge${i} = texture2D(edgeTexture${i}, v_textureCoordinates); \n` + + ` vec4 edge${i} = texture(edgeTexture${i}, v_textureCoordinates); \n` + ` if (edge${i}.a > 0.0) \n` + ` { \n` + ` color = edge${i}; \n` + @@ -293,12 +293,12 @@ function getSilhouetteEdgeDetection(edgeDetectionStages) { } const fs = - `${fsDecl}varying vec2 v_textureCoordinates; \n` + + `${fsDecl}in vec2 v_textureCoordinates; \n` + `void main() { \n` + ` vec4 color = vec4(0.0); \n` + ` for (int i = 0; i < ${edgeDetectionStages.length}; i++) \n` + ` { \n${fsLoop} } \n` + - ` gl_FragColor = color; \n` + + ` out_FragColor = color; \n` + `} \n`; const edgeComposite = new PostProcessStage({ diff --git a/packages/engine/Source/Scene/Primitive.js b/packages/engine/Source/Scene/Primitive.js index 60746abf5cb3..2ac5e23c0730 100644 --- a/packages/engine/Source/Scene/Primitive.js +++ b/packages/engine/Source/Scene/Primitive.js @@ -743,7 +743,7 @@ function cloneInstance(instance, geometry) { }; } -const positionRegex = /attribute\s+vec(?:3|4)\s+(.*)3DHigh;/g; +const positionRegex = /in\s+vec(?:3|4)\s+(.*)3DHigh;/g; Primitive._modifyShaderPosition = function ( primitive, @@ -771,8 +771,7 @@ Primitive._modifyShaderPosition = function ( if (!defined(primitive.rtcCenter)) { // Use GPU RTE if (!scene3DOnly) { - attributes += - `attribute vec3 ${name}2DHigh;\n` + `attribute vec3 ${name}2DLow;\n`; + attributes += `in vec3 ${name}2DHigh;\nin vec3 ${name}2DLow;\n`; computeFunctions += `${functionName}\n` + @@ -805,16 +804,16 @@ Primitive._modifyShaderPosition = function ( } else { // Use RTC vertexShaderSource = vertexShaderSource.replace( - /attribute\s+vec(?:3|4)\s+position3DHigh;/g, + /in\s+vec(?:3|4)\s+position3DHigh;/g, "" ); vertexShaderSource = vertexShaderSource.replace( - /attribute\s+vec(?:3|4)\s+position3DLow;/g, + /in\s+vec(?:3|4)\s+position3DLow;/g, "" ); forwardDecl += "uniform mat4 u_modifiedModelView;\n"; - attributes += "attribute vec4 position;\n"; + attributes += "in vec4 position;\n"; computeFunctions += `${functionName}\n` + @@ -871,7 +870,7 @@ Primitive._updateColorAttribute = function ( return vertexShaderSource; } - if (vertexShaderSource.search(/attribute\s+vec4\s+color;/g) === -1) { + if (vertexShaderSource.search(/in\s+vec4\s+color;/g) === -1) { return vertexShaderSource; } @@ -887,7 +886,7 @@ Primitive._updateColorAttribute = function ( //>>includeEnd('debug'); let modifiedVS = vertexShaderSource; - modifiedVS = modifiedVS.replace(/attribute\s+vec4\s+color;/g, ""); + modifiedVS = modifiedVS.replace(/in\s+vec4\s+color;/g, ""); if (!isDepthFail) { modifiedVS = modifiedVS.replace( /(\b)color(\b)/g, @@ -905,7 +904,7 @@ Primitive._updateColorAttribute = function ( function appendPickToVertexShader(source) { const renamedVS = ShaderSource.replaceMain(source, "czm_non_pick_main"); const pickMain = - "varying vec4 v_pickColor; \n" + + "out vec4 v_pickColor; \n" + "void main() \n" + "{ \n" + " czm_non_pick_main(); \n" + @@ -916,11 +915,11 @@ function appendPickToVertexShader(source) { } function appendPickToFragmentShader(source) { - return `varying vec4 v_pickColor;\n${source}`; + return `in vec4 v_pickColor;\n${source}`; } Primitive._updatePickColorAttribute = function (source) { - let vsPick = source.replace(/attribute\s+vec4\s+pickColor;/g, ""); + let vsPick = source.replace(/in\s+vec4\s+pickColor;/g, ""); vsPick = vsPick.replace( /(\b)pickColor(\b)/g, "$1czm_batchTable_pickColor(batchId)$2" @@ -933,10 +932,10 @@ Primitive._appendOffsetToShader = function (primitive, vertexShaderSource) { return vertexShaderSource; } - let attr = "attribute float batchId;\n"; - attr += "attribute float applyOffset;"; + let attr = "in float batchId;\n"; + attr += "in float applyOffset;"; let modifiedShader = vertexShaderSource.replace( - /attribute\s+float\s+batchId;/g, + /in\s+float\s+batchId;/g, attr ); @@ -1033,17 +1032,16 @@ function modifyForEncodedNormals(primitive, vertexShaderSource) { } const containsNormal = - vertexShaderSource.search(/attribute\s+vec3\s+normal;/g) !== -1; - const containsSt = - vertexShaderSource.search(/attribute\s+vec2\s+st;/g) !== -1; + vertexShaderSource.search(/in\s+vec3\s+normal;/g) !== -1; + const containsSt = vertexShaderSource.search(/in\s+vec2\s+st;/g) !== -1; if (!containsNormal && !containsSt) { return vertexShaderSource; } const containsTangent = - vertexShaderSource.search(/attribute\s+vec3\s+tangent;/g) !== -1; + vertexShaderSource.search(/in\s+vec3\s+tangent;/g) !== -1; const containsBitangent = - vertexShaderSource.search(/attribute\s+vec3\s+bitangent;/g) !== -1; + vertexShaderSource.search(/in\s+vec3\s+bitangent;/g) !== -1; let numComponents = containsSt && containsNormal ? 2.0 : 1.0; numComponents += containsTangent || containsBitangent ? 1 : 0; @@ -1051,7 +1049,7 @@ function modifyForEncodedNormals(primitive, vertexShaderSource) { const type = numComponents > 1 ? `vec${numComponents}` : "float"; const attributeName = "compressedAttributes"; - const attributeDecl = `attribute ${type} ${attributeName};`; + const attributeDecl = `in ${type} ${attributeName};`; let globalDecl = ""; let decode = ""; @@ -1092,10 +1090,10 @@ function modifyForEncodedNormals(primitive, vertexShaderSource) { } let modifiedVS = vertexShaderSource; - modifiedVS = modifiedVS.replace(/attribute\s+vec3\s+normal;/g, ""); - modifiedVS = modifiedVS.replace(/attribute\s+vec2\s+st;/g, ""); - modifiedVS = modifiedVS.replace(/attribute\s+vec3\s+tangent;/g, ""); - modifiedVS = modifiedVS.replace(/attribute\s+vec3\s+bitangent;/g, ""); + modifiedVS = modifiedVS.replace(/in\s+vec3\s+normal;/g, ""); + modifiedVS = modifiedVS.replace(/in\s+vec2\s+st;/g, ""); + modifiedVS = modifiedVS.replace(/in\s+vec3\s+tangent;/g, ""); + modifiedVS = modifiedVS.replace(/in\s+vec3\s+bitangent;/g, ""); modifiedVS = ShaderSource.replaceMain(modifiedVS, "czm_non_compressed_main"); const compressedMain = `${"void main() \n" + "{ \n"}${decode} czm_non_compressed_main(); \n` + @@ -1125,19 +1123,12 @@ function depthClampFS(fragmentShaderSource) { modifiedFS += "void main() {\n" + " czm_non_depth_clamp_main();\n" + - "#if defined(GL_EXT_frag_depth)\n" + " #if defined(LOG_DEPTH)\n" + " czm_writeLogDepth();\n" + " #else\n" + " czm_writeDepthClamp();\n" + " #endif\n" + - "#endif\n" + "}\n"; - modifiedFS = `${ - "#ifdef GL_EXT_frag_depth\n" + - "#extension GL_EXT_frag_depth : enable\n" + - "#endif\n" - }${modifiedFS}`; return modifiedFS; } diff --git a/packages/engine/Source/Scene/ShadowMap.js b/packages/engine/Source/Scene/ShadowMap.js index 66d7a8371d37..966b274a896a 100644 --- a/packages/engine/Source/Scene/ShadowMap.js +++ b/packages/engine/Source/Scene/ShadowMap.js @@ -763,7 +763,7 @@ function createDebugShadowViewCommand(shadowMap, context) { if (shadowMap._isPointLight) { fs = "uniform samplerCube shadowMap_textureCube; \n" + - "varying vec2 v_textureCoordinates; \n" + + "in vec2 v_textureCoordinates; \n" + "void main() \n" + "{ \n" + " vec2 uv = v_textureCoordinates; \n" + @@ -812,21 +812,21 @@ function createDebugShadowViewCommand(shadowMap, context) { " } \n" + " } \n" + " \n" + - " float shadow = czm_unpackDepth(textureCube(shadowMap_textureCube, dir)); \n" + - " gl_FragColor = vec4(vec3(shadow), 1.0); \n" + + " float shadow = czm_unpackDepth(czm_textureCube(shadowMap_textureCube, dir)); \n" + + " out_FragColor = vec4(vec3(shadow), 1.0); \n" + "} \n"; } else { fs = `${ "uniform sampler2D shadowMap_texture; \n" + - "varying vec2 v_textureCoordinates; \n" + + "in vec2 v_textureCoordinates; \n" + "void main() \n" + "{ \n" }${ shadowMap._usesDepthTexture - ? " float shadow = texture2D(shadowMap_texture, v_textureCoordinates).r; \n" - : " float shadow = czm_unpackDepth(texture2D(shadowMap_texture, v_textureCoordinates)); \n" - } gl_FragColor = vec4(vec3(shadow), 1.0); \n` + `} \n`; + ? " float shadow = texture(shadowMap_texture, v_textureCoordinates).r; \n" + : " float shadow = czm_unpackDepth(texture(shadowMap_texture, v_textureCoordinates)); \n" + } out_FragColor = vec4(vec3(shadow), 1.0); \n` + `} \n`; } const drawCommand = context.createViewportQuadCommand(fs, { diff --git a/packages/engine/Source/Scene/ShadowMapShader.js b/packages/engine/Source/Scene/ShadowMapShader.js index 013cbbfa35c0..7c9744d90c79 100644 --- a/packages/engine/Source/Scene/ShadowMapShader.js +++ b/packages/engine/Source/Scene/ShadowMapShader.js @@ -39,7 +39,7 @@ ShadowMapShader.createShadowCastVertexShader = function ( } const shadowVS = - "varying vec3 v_positionEC; \n" + + "in vec3 v_positionEC; \n" + "void main() \n" + "{ \n" + " czm_shadow_cast_main(); \n" + @@ -80,7 +80,7 @@ ShadowMapShader.createShadowCastFragmentShader = function ( if (isPointLight) { if (!hasPositionVarying) { - fsSource += "varying vec3 v_positionEC; \n"; + fsSource += "in vec3 v_positionEC; \n"; } fsSource += "uniform vec4 shadowMap_lightPositionEC; \n"; } @@ -92,7 +92,7 @@ ShadowMapShader.createShadowCastFragmentShader = function ( "void main() \n" + "{ \n" + " czm_shadow_cast_main(); \n" + - " if (gl_FragColor.a == 0.0) \n" + + " if (out_FragColor.a == 0.0) \n" + " { \n" + " discard; \n" + " } \n"; @@ -106,11 +106,11 @@ ShadowMapShader.createShadowCastFragmentShader = function ( ` discard; \n` + ` } \n` + ` distance /= shadowMap_lightPositionEC.w; // radius \n` + - ` gl_FragColor = czm_packDepth(distance); \n`; + ` out_FragColor = czm_packDepth(distance); \n`; } else if (usesDepthTexture) { - fsSource += " gl_FragColor = vec4(1.0); \n"; + fsSource += " out_FragColor = vec4(1.0); \n"; } else { - fsSource += " gl_FragColor = czm_packDepth(gl_FragCoord.z); \n"; + fsSource += " out_FragColor = czm_packDepth(gl_FragCoord.z); \n"; } fsSource += "} \n"; @@ -257,7 +257,7 @@ ShadowMapShader.createShadowReceiveFragmentShader = function ( "uniform vec4 shadowMap_normalOffsetScaleDistanceMaxDistanceAndDarkness; \n" + "uniform vec4 shadowMap_texelSizeDepthBiasAndNormalShadingSmooth; \n" + "#ifdef LOG_DEPTH \n" + - "varying vec3 v_logPositionEC; \n" + + "in vec3 v_logPositionEC; \n" + "#endif \n" + "vec4 getPositionEC() \n" + "{ \n" @@ -364,7 +364,7 @@ ShadowMapShader.createShadowReceiveFragmentShader = function ( }${ debugCascadeColors ? " // Draw cascade colors for debugging \n" + - " gl_FragColor *= czm_cascadeColor(weights); \n" + " out_FragColor *= czm_cascadeColor(weights); \n" : "" }`; } else { @@ -383,7 +383,7 @@ ShadowMapShader.createShadowReceiveFragmentShader = function ( " float visibility = czm_shadowVisibility(shadowMap_texture, shadowParameters); \n"; } - fsSource += " gl_FragColor.rgb *= visibility; \n" + "} \n"; + fsSource += " out_FragColor.rgb *= visibility; \n" + "} \n"; sources.push(fsSource); diff --git a/packages/engine/Source/Scene/ShadowVolumeAppearance.js b/packages/engine/Source/Scene/ShadowVolumeAppearance.js index 169bf41b2c90..8a3186d24bf0 100644 --- a/packages/engine/Source/Scene/ShadowVolumeAppearance.js +++ b/packages/engine/Source/Scene/ShadowVolumeAppearance.js @@ -168,7 +168,7 @@ ShadowVolumeAppearance.prototype.createPickFragmentShader = function ( return new ShaderSource({ defines: defines, sources: [ShadowVolumeAppearanceFS], - pickColorQualifier: "varying", + pickColorQualifier: "in", }); }; diff --git a/packages/engine/Source/Scene/Vector3DTilePolylines.js b/packages/engine/Source/Scene/Vector3DTilePolylines.js index 63e56542148a..d3f5f61c5f4a 100644 --- a/packages/engine/Source/Scene/Vector3DTilePolylines.js +++ b/packages/engine/Source/Scene/Vector3DTilePolylines.js @@ -421,7 +421,7 @@ const PolylineFS = "uniform vec4 u_highlightColor; \n" + "void main()\n" + "{\n" + - " gl_FragColor = u_highlightColor;\n" + + " out_FragColor = u_highlightColor;\n" + "}\n"; function createShaders(primitive, context) { diff --git a/packages/engine/Source/Scene/Vector3DTilePrimitive.js b/packages/engine/Source/Scene/Vector3DTilePrimitive.js index 7e5f566b83fb..e3cbba091ea0 100644 --- a/packages/engine/Source/Scene/Vector3DTilePrimitive.js +++ b/packages/engine/Source/Scene/Vector3DTilePrimitive.js @@ -283,7 +283,7 @@ function createShaders(primitive, context) { `${fragmentShaderSource}void main() \n` + `{ \n` + ` czm_non_pick_main(); \n` + - ` gl_FragColor = ${pickId}; \n` + + ` out_FragColor = ${pickId}; \n` + `} \n`; primitive._spPick = ShaderProgram.fromCache({ context: context, @@ -343,7 +343,7 @@ function createShaders(primitive, context) { `void main() \n` + `{ \n` + ` czm_non_pick_main(); \n` + - ` gl_FragColor = ${pickId}; \n` + + ` out_FragColor = ${pickId}; \n` + `} \n`; const pickVS = new ShaderSource({ diff --git a/packages/engine/Source/Scene/createElevationBandMaterial.js b/packages/engine/Source/Scene/createElevationBandMaterial.js index 6ecbdeeb51b3..375964c207d6 100644 --- a/packages/engine/Source/Scene/createElevationBandMaterial.js +++ b/packages/engine/Source/Scene/createElevationBandMaterial.js @@ -462,9 +462,7 @@ function createLayeredEntries(layers) { * }); */ function createElevationBandMaterial(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); - const scene = options.scene; - const layers = options.layers; + const { scene, layers } = defaultValue(options, defaultValue.EMPTY_OBJECT); //>>includeStart('debug', pragmas.debug); Check.typeOf.object("options.scene", scene); @@ -472,36 +470,34 @@ function createElevationBandMaterial(options) { Check.typeOf.number.greaterThan("options.layers.length", layers.length, 0); //>>includeEnd('debug'); + const { context } = scene; const entries = createLayeredEntries(layers); const entriesLength = entries.length; - let i; let heightTexBuffer; let heightTexDatatype; let heightTexFormat; - const isPackedHeight = !createElevationBandMaterial._useFloatTexture( - scene.context - ); + const isPackedHeight = !createElevationBandMaterial._useFloatTexture(context); if (isPackedHeight) { heightTexDatatype = PixelDatatype.UNSIGNED_BYTE; heightTexFormat = PixelFormat.RGBA; heightTexBuffer = new Uint8Array(entriesLength * 4); - for (i = 0; i < entriesLength; i++) { + for (let i = 0; i < entriesLength; i++) { Cartesian4.packFloat(entries[i].height, scratchPackedFloat); Cartesian4.pack(scratchPackedFloat, heightTexBuffer, i * 4); } } else { heightTexDatatype = PixelDatatype.FLOAT; - heightTexFormat = PixelFormat.LUMINANCE; + heightTexFormat = context.webgl2 ? PixelFormat.RED : PixelFormat.LUMINANCE; heightTexBuffer = new Float32Array(entriesLength); - for (i = 0; i < entriesLength; i++) { + for (let i = 0; i < entriesLength; i++) { heightTexBuffer[i] = entries[i].height; } } const heightsTex = Texture.create({ - context: scene.context, + context: context, pixelFormat: heightTexFormat, pixelDatatype: heightTexDatatype, source: { @@ -518,7 +514,7 @@ function createElevationBandMaterial(options) { }); const colorsArray = new Uint8Array(entriesLength * 4); - for (i = 0; i < entriesLength; i++) { + for (let i = 0; i < entriesLength; i++) { const color = entries[i].color; color.toBytes(scratchColorBytes); colorsArray[i * 4 + 0] = scratchColorBytes[0]; @@ -528,7 +524,7 @@ function createElevationBandMaterial(options) { } const colorsTex = Texture.create({ - context: scene.context, + context: context, pixelFormat: PixelFormat.RGBA, pixelDatatype: PixelDatatype.UNSIGNED_BYTE, source: { @@ -544,11 +540,10 @@ function createElevationBandMaterial(options) { }), }); - const material = Material.fromType("ElevationBand", { + return Material.fromType("ElevationBand", { heights: heightsTex, colors: colorsTex, }); - return material; } /** diff --git a/packages/engine/Source/Scene/getClipAndStyleCode.js b/packages/engine/Source/Scene/getClipAndStyleCode.js index e6d9714f6825..41eddcf14072 100644 --- a/packages/engine/Source/Scene/getClipAndStyleCode.js +++ b/packages/engine/Source/Scene/getClipAndStyleCode.js @@ -27,7 +27,7 @@ function getClipAndStyleCode( ` float clippingPlanesEdgeWidth = ${styleUniformName}.a; \n` + ` if (clipDistance > 0.0 && clipDistance < clippingPlanesEdgeWidth) \n` + ` { \n` + - ` gl_FragColor = clippingPlanesEdgeColor;\n` + + ` out_FragColor = clippingPlanesEdgeColor;\n` + ` } \n`; return shaderCode; } diff --git a/packages/engine/Source/Scene/getClippingFunction.js b/packages/engine/Source/Scene/getClippingFunction.js index 2d93169443a0..be41a8717b11 100644 --- a/packages/engine/Source/Scene/getClippingFunction.js +++ b/packages/engine/Source/Scene/getClippingFunction.js @@ -122,7 +122,7 @@ function getClippingPlaneFloat(width, height) { ` int pixX = clippingPlaneNumber - (pixY * ${width});\n` + ` float u = (float(pixX) + 0.5) * ${pixelWidthString};\n` + // sample from center of pixel ` float v = (float(pixY) + 0.5) * ${pixelHeightString};\n` + - ` vec4 plane = texture2D(packedClippingPlanes, vec2(u, v));\n` + + ` vec4 plane = texture(packedClippingPlanes, vec2(u, v));\n` + ` return czm_transformPlane(plane, transform);\n` + `}\n`; return functionString; @@ -151,11 +151,11 @@ function getClippingPlaneUint8(width, height) { ` int pixX = clippingPlaneStartIndex - (pixY * ${width});\n` + ` float u = (float(pixX) + 0.5) * ${pixelWidthString};\n` + // sample from center of pixel ` float v = (float(pixY) + 0.5) * ${pixelHeightString};\n` + - ` vec4 oct32 = texture2D(packedClippingPlanes, vec2(u, v)) * 255.0;\n` + + ` vec4 oct32 = texture(packedClippingPlanes, vec2(u, v)) * 255.0;\n` + ` vec2 oct = vec2(oct32.x * 256.0 + oct32.y, oct32.z * 256.0 + oct32.w);\n` + ` vec4 plane;\n` + ` plane.xyz = czm_octDecode(oct, 65535.0);\n` + - ` plane.w = czm_unpackFloat(texture2D(packedClippingPlanes, vec2(u + ${pixelWidthString}, v)));\n` + + ` plane.w = czm_unpackFloat(texture(packedClippingPlanes, vec2(u + ${pixelWidthString}, v)));\n` + ` return czm_transformPlane(plane, transform);\n` + `}\n`; return functionString; diff --git a/packages/engine/Source/Scene/processVoxelProperties.js b/packages/engine/Source/Scene/processVoxelProperties.js index 61702148ca15..46dc60fd6136 100644 --- a/packages/engine/Source/Scene/processVoxelProperties.js +++ b/packages/engine/Source/Scene/processVoxelProperties.js @@ -340,7 +340,7 @@ function processVoxelProperties(renderResources, primitive) { const componentType = componentTypes[i]; const glslTextureSwizzle = getGlslTextureSwizzle(type, componentType); shaderBuilder.addFunctionLines(functionId, [ - `properties.${name} = texture2D(u_megatextureTextures[${i}], texcoord)${glslTextureSwizzle};`, + `properties.${name} = texture(u_megatextureTextures[${i}], texcoord)${glslTextureSwizzle};`, ]); } shaderBuilder.addFunctionLines(functionId, [ diff --git a/packages/engine/Source/Shaders/AdjustTranslucentFS.glsl b/packages/engine/Source/Shaders/AdjustTranslucentFS.glsl index cd5dd453615c..4f67a3c3b85e 100644 --- a/packages/engine/Source/Shaders/AdjustTranslucentFS.glsl +++ b/packages/engine/Source/Shaders/AdjustTranslucentFS.glsl @@ -1,21 +1,24 @@ #ifdef MRT -#extension GL_EXT_draw_buffers : enable +layout (location = 0) out vec4 out_FragData_0; +layout (location = 1) out vec4 out_FragData_1; +#else +layout (location = 0) out vec4 out_FragColor; #endif uniform vec4 u_bgColor; uniform sampler2D u_depthTexture; -varying vec2 v_textureCoordinates; +in vec2 v_textureCoordinates; void main() { - if (texture2D(u_depthTexture, v_textureCoordinates).r < 1.0) + if (texture(u_depthTexture, v_textureCoordinates).r < 1.0) { #ifdef MRT - gl_FragData[0] = u_bgColor; - gl_FragData[1] = vec4(u_bgColor.a); + out_FragData_0 = u_bgColor; + out_FragData_1 = vec4(u_bgColor.a); #else - gl_FragColor = u_bgColor; + out_FragColor = u_bgColor; #endif return; } diff --git a/packages/engine/Source/Shaders/Appearances/AllMaterialAppearanceFS.glsl b/packages/engine/Source/Shaders/Appearances/AllMaterialAppearanceFS.glsl index acf2427cd397..7583e8a0b5ec 100644 --- a/packages/engine/Source/Shaders/Appearances/AllMaterialAppearanceFS.glsl +++ b/packages/engine/Source/Shaders/Appearances/AllMaterialAppearanceFS.glsl @@ -1,8 +1,8 @@ -varying vec3 v_positionEC; -varying vec3 v_normalEC; -varying vec3 v_tangentEC; -varying vec3 v_bitangentEC; -varying vec2 v_st; +in vec3 v_positionEC; +in vec3 v_normalEC; +in vec3 v_tangentEC; +in vec3 v_bitangentEC; +in vec2 v_st; void main() { @@ -22,8 +22,8 @@ void main() czm_material material = czm_getMaterial(materialInput); #ifdef FLAT - gl_FragColor = vec4(material.diffuse + material.emission, material.alpha); + out_FragColor = vec4(material.diffuse + material.emission, material.alpha); #else - gl_FragColor = czm_phong(normalize(positionToEyeEC), material, czm_lightDirectionEC); + out_FragColor = czm_phong(normalize(positionToEyeEC), material, czm_lightDirectionEC); #endif } diff --git a/packages/engine/Source/Shaders/Appearances/AllMaterialAppearanceVS.glsl b/packages/engine/Source/Shaders/Appearances/AllMaterialAppearanceVS.glsl index 33d9d300a304..79b241f4700d 100644 --- a/packages/engine/Source/Shaders/Appearances/AllMaterialAppearanceVS.glsl +++ b/packages/engine/Source/Shaders/Appearances/AllMaterialAppearanceVS.glsl @@ -1,16 +1,16 @@ -attribute vec3 position3DHigh; -attribute vec3 position3DLow; -attribute vec3 normal; -attribute vec3 tangent; -attribute vec3 bitangent; -attribute vec2 st; -attribute float batchId; +in vec3 position3DHigh; +in vec3 position3DLow; +in vec3 normal; +in vec3 tangent; +in vec3 bitangent; +in vec2 st; +in float batchId; -varying vec3 v_positionEC; -varying vec3 v_normalEC; -varying vec3 v_tangentEC; -varying vec3 v_bitangentEC; -varying vec2 v_st; +out vec3 v_positionEC; +out vec3 v_normalEC; +out vec3 v_tangentEC; +out vec3 v_bitangentEC; +out vec2 v_st; void main() { diff --git a/packages/engine/Source/Shaders/Appearances/BasicMaterialAppearanceFS.glsl b/packages/engine/Source/Shaders/Appearances/BasicMaterialAppearanceFS.glsl index d0fa1028a41d..cc4d8f711b9b 100644 --- a/packages/engine/Source/Shaders/Appearances/BasicMaterialAppearanceFS.glsl +++ b/packages/engine/Source/Shaders/Appearances/BasicMaterialAppearanceFS.glsl @@ -1,5 +1,5 @@ -varying vec3 v_positionEC; -varying vec3 v_normalEC; +in vec3 v_positionEC; +in vec3 v_normalEC; void main() { @@ -16,8 +16,8 @@ void main() czm_material material = czm_getMaterial(materialInput); #ifdef FLAT - gl_FragColor = vec4(material.diffuse + material.emission, material.alpha); + out_FragColor = vec4(material.diffuse + material.emission, material.alpha); #else - gl_FragColor = czm_phong(normalize(positionToEyeEC), material, czm_lightDirectionEC); + out_FragColor = czm_phong(normalize(positionToEyeEC), material, czm_lightDirectionEC); #endif } diff --git a/packages/engine/Source/Shaders/Appearances/BasicMaterialAppearanceVS.glsl b/packages/engine/Source/Shaders/Appearances/BasicMaterialAppearanceVS.glsl index d17aa17009b9..339f9f43bbb9 100644 --- a/packages/engine/Source/Shaders/Appearances/BasicMaterialAppearanceVS.glsl +++ b/packages/engine/Source/Shaders/Appearances/BasicMaterialAppearanceVS.glsl @@ -1,10 +1,10 @@ -attribute vec3 position3DHigh; -attribute vec3 position3DLow; -attribute vec3 normal; -attribute float batchId; +in vec3 position3DHigh; +in vec3 position3DLow; +in vec3 normal; +in float batchId; -varying vec3 v_positionEC; -varying vec3 v_normalEC; +out vec3 v_positionEC; +out vec3 v_normalEC; void main() { diff --git a/packages/engine/Source/Shaders/Appearances/EllipsoidSurfaceAppearanceFS.glsl b/packages/engine/Source/Shaders/Appearances/EllipsoidSurfaceAppearanceFS.glsl index cf66e4b9c898..32d3c663fc91 100644 --- a/packages/engine/Source/Shaders/Appearances/EllipsoidSurfaceAppearanceFS.glsl +++ b/packages/engine/Source/Shaders/Appearances/EllipsoidSurfaceAppearanceFS.glsl @@ -1,6 +1,6 @@ -varying vec3 v_positionMC; -varying vec3 v_positionEC; -varying vec2 v_st; +in vec3 v_positionMC; +in vec3 v_positionEC; +in vec2 v_st; void main() { @@ -26,8 +26,8 @@ void main() czm_material material = czm_getMaterial(materialInput); #ifdef FLAT - gl_FragColor = vec4(material.diffuse + material.emission, material.alpha); + out_FragColor = vec4(material.diffuse + material.emission, material.alpha); #else - gl_FragColor = czm_phong(normalize(positionToEyeEC), material, czm_lightDirectionEC); + out_FragColor = czm_phong(normalize(positionToEyeEC), material, czm_lightDirectionEC); #endif } diff --git a/packages/engine/Source/Shaders/Appearances/EllipsoidSurfaceAppearanceVS.glsl b/packages/engine/Source/Shaders/Appearances/EllipsoidSurfaceAppearanceVS.glsl index 6f4e11300a7c..3942e6f07a42 100644 --- a/packages/engine/Source/Shaders/Appearances/EllipsoidSurfaceAppearanceVS.glsl +++ b/packages/engine/Source/Shaders/Appearances/EllipsoidSurfaceAppearanceVS.glsl @@ -1,11 +1,11 @@ -attribute vec3 position3DHigh; -attribute vec3 position3DLow; -attribute vec2 st; -attribute float batchId; +in vec3 position3DHigh; +in vec3 position3DLow; +in vec2 st; +in float batchId; -varying vec3 v_positionMC; -varying vec3 v_positionEC; -varying vec2 v_st; +out vec3 v_positionMC; +out vec3 v_positionEC; +out vec2 v_st; void main() { diff --git a/packages/engine/Source/Shaders/Appearances/PerInstanceColorAppearanceFS.glsl b/packages/engine/Source/Shaders/Appearances/PerInstanceColorAppearanceFS.glsl index d9728d66a46a..386b0176c179 100644 --- a/packages/engine/Source/Shaders/Appearances/PerInstanceColorAppearanceFS.glsl +++ b/packages/engine/Source/Shaders/Appearances/PerInstanceColorAppearanceFS.glsl @@ -1,6 +1,6 @@ -varying vec3 v_positionEC; -varying vec3 v_normalEC; -varying vec4 v_color; +in vec3 v_positionEC; +in vec3 v_normalEC; +in vec4 v_color; void main() { @@ -20,5 +20,5 @@ void main() material.diffuse = color.rgb; material.alpha = color.a; - gl_FragColor = czm_phong(normalize(positionToEyeEC), material, czm_lightDirectionEC); + out_FragColor = czm_phong(normalize(positionToEyeEC), material, czm_lightDirectionEC); } diff --git a/packages/engine/Source/Shaders/Appearances/PerInstanceColorAppearanceVS.glsl b/packages/engine/Source/Shaders/Appearances/PerInstanceColorAppearanceVS.glsl index 5d0711b68949..b2deb2d44398 100644 --- a/packages/engine/Source/Shaders/Appearances/PerInstanceColorAppearanceVS.glsl +++ b/packages/engine/Source/Shaders/Appearances/PerInstanceColorAppearanceVS.glsl @@ -1,12 +1,12 @@ -attribute vec3 position3DHigh; -attribute vec3 position3DLow; -attribute vec3 normal; -attribute vec4 color; -attribute float batchId; +in vec3 position3DHigh; +in vec3 position3DLow; +in vec3 normal; +in vec4 color; +in float batchId; -varying vec3 v_positionEC; -varying vec3 v_normalEC; -varying vec4 v_color; +out vec3 v_positionEC; +out vec3 v_normalEC; +out vec4 v_color; void main() { diff --git a/packages/engine/Source/Shaders/Appearances/PerInstanceFlatColorAppearanceFS.glsl b/packages/engine/Source/Shaders/Appearances/PerInstanceFlatColorAppearanceFS.glsl index 0af342a73e28..748e96c00a34 100644 --- a/packages/engine/Source/Shaders/Appearances/PerInstanceFlatColorAppearanceFS.glsl +++ b/packages/engine/Source/Shaders/Appearances/PerInstanceFlatColorAppearanceFS.glsl @@ -1,6 +1,6 @@ -varying vec4 v_color; +in vec4 v_color; void main() { - gl_FragColor = czm_gammaCorrect(v_color); + out_FragColor = czm_gammaCorrect(v_color); } diff --git a/packages/engine/Source/Shaders/Appearances/PerInstanceFlatColorAppearanceVS.glsl b/packages/engine/Source/Shaders/Appearances/PerInstanceFlatColorAppearanceVS.glsl index f38d44046db4..e770bd5a23c8 100644 --- a/packages/engine/Source/Shaders/Appearances/PerInstanceFlatColorAppearanceVS.glsl +++ b/packages/engine/Source/Shaders/Appearances/PerInstanceFlatColorAppearanceVS.glsl @@ -1,9 +1,9 @@ -attribute vec3 position3DHigh; -attribute vec3 position3DLow; -attribute vec4 color; -attribute float batchId; +in vec3 position3DHigh; +in vec3 position3DLow; +in vec4 color; +in float batchId; -varying vec4 v_color; +out vec4 v_color; void main() { diff --git a/packages/engine/Source/Shaders/Appearances/PolylineColorAppearanceVS.glsl b/packages/engine/Source/Shaders/Appearances/PolylineColorAppearanceVS.glsl index 9cfea0f4376a..7d81b2e4766f 100644 --- a/packages/engine/Source/Shaders/Appearances/PolylineColorAppearanceVS.glsl +++ b/packages/engine/Source/Shaders/Appearances/PolylineColorAppearanceVS.glsl @@ -1,14 +1,14 @@ -attribute vec3 position3DHigh; -attribute vec3 position3DLow; -attribute vec3 prevPosition3DHigh; -attribute vec3 prevPosition3DLow; -attribute vec3 nextPosition3DHigh; -attribute vec3 nextPosition3DLow; -attribute vec2 expandAndWidth; -attribute vec4 color; -attribute float batchId; +in vec3 position3DHigh; +in vec3 position3DLow; +in vec3 prevPosition3DHigh; +in vec3 prevPosition3DLow; +in vec3 nextPosition3DHigh; +in vec3 nextPosition3DLow; +in vec2 expandAndWidth; +in vec4 color; +in float batchId; -varying vec4 v_color; +out vec4 v_color; void main() { diff --git a/packages/engine/Source/Shaders/Appearances/PolylineMaterialAppearanceVS.glsl b/packages/engine/Source/Shaders/Appearances/PolylineMaterialAppearanceVS.glsl index 5aa604445edb..7ffae16b7dc1 100644 --- a/packages/engine/Source/Shaders/Appearances/PolylineMaterialAppearanceVS.glsl +++ b/packages/engine/Source/Shaders/Appearances/PolylineMaterialAppearanceVS.glsl @@ -1,16 +1,16 @@ -attribute vec3 position3DHigh; -attribute vec3 position3DLow; -attribute vec3 prevPosition3DHigh; -attribute vec3 prevPosition3DLow; -attribute vec3 nextPosition3DHigh; -attribute vec3 nextPosition3DLow; -attribute vec2 expandAndWidth; -attribute vec2 st; -attribute float batchId; +in vec3 position3DHigh; +in vec3 position3DLow; +in vec3 prevPosition3DHigh; +in vec3 prevPosition3DLow; +in vec3 nextPosition3DHigh; +in vec3 nextPosition3DLow; +in vec2 expandAndWidth; +in vec2 st; +in float batchId; -varying float v_width; -varying vec2 v_st; -varying float v_polylineAngle; +out float v_width; +out vec2 v_st; +out float v_polylineAngle; void main() { diff --git a/packages/engine/Source/Shaders/Appearances/TexturedMaterialAppearanceFS.glsl b/packages/engine/Source/Shaders/Appearances/TexturedMaterialAppearanceFS.glsl index bbf240245f60..f0afbc825a12 100644 --- a/packages/engine/Source/Shaders/Appearances/TexturedMaterialAppearanceFS.glsl +++ b/packages/engine/Source/Shaders/Appearances/TexturedMaterialAppearanceFS.glsl @@ -1,6 +1,6 @@ -varying vec3 v_positionEC; -varying vec3 v_normalEC; -varying vec2 v_st; +in vec3 v_positionEC; +in vec3 v_normalEC; +in vec2 v_st; void main() { @@ -18,8 +18,8 @@ void main() czm_material material = czm_getMaterial(materialInput); #ifdef FLAT - gl_FragColor = vec4(material.diffuse + material.emission, material.alpha); + out_FragColor = vec4(material.diffuse + material.emission, material.alpha); #else - gl_FragColor = czm_phong(normalize(positionToEyeEC), material, czm_lightDirectionEC); + out_FragColor = czm_phong(normalize(positionToEyeEC), material, czm_lightDirectionEC); #endif } diff --git a/packages/engine/Source/Shaders/Appearances/TexturedMaterialAppearanceVS.glsl b/packages/engine/Source/Shaders/Appearances/TexturedMaterialAppearanceVS.glsl index 7ceb6e0b5239..b1a66f55428a 100644 --- a/packages/engine/Source/Shaders/Appearances/TexturedMaterialAppearanceVS.glsl +++ b/packages/engine/Source/Shaders/Appearances/TexturedMaterialAppearanceVS.glsl @@ -1,12 +1,12 @@ -attribute vec3 position3DHigh; -attribute vec3 position3DLow; -attribute vec3 normal; -attribute vec2 st; -attribute float batchId; +in vec3 position3DHigh; +in vec3 position3DLow; +in vec3 normal; +in vec2 st; +in float batchId; -varying vec3 v_positionEC; -varying vec3 v_normalEC; -varying vec2 v_st; +out vec3 v_positionEC; +out vec3 v_normalEC; +out vec2 v_st; void main() { diff --git a/packages/engine/Source/Shaders/BillboardCollectionFS.glsl b/packages/engine/Source/Shaders/BillboardCollectionFS.glsl index 59c0f1cc8f83..916731d92779 100644 --- a/packages/engine/Source/Shaders/BillboardCollectionFS.glsl +++ b/packages/engine/Source/Shaders/BillboardCollectionFS.glsl @@ -8,20 +8,20 @@ uniform sampler2D u_atlas; uniform vec4 u_highlightColor; #endif -varying vec2 v_textureCoordinates; -varying vec4 v_pickColor; -varying vec4 v_color; +in vec2 v_textureCoordinates; +in vec4 v_pickColor; +in vec4 v_color; #ifdef SDF -varying vec4 v_outlineColor; -varying float v_outlineWidth; +in vec4 v_outlineColor; +in float v_outlineWidth; #endif #ifdef FRAGMENT_DEPTH_CHECK -varying vec4 v_textureCoordinateBounds; // the min and max x and y values for the texture coordinates -varying vec4 v_originTextureCoordinateAndTranslate; // texture coordinate at the origin, billboard translate (used for label glyphs) -varying vec4 v_compressed; // x: eyeDepth, y: applyTranslate & enableDepthCheck, z: dimensions, w: imageSize -varying mat2 v_rotationMatrix; +in vec4 v_textureCoordinateBounds; // the min and max x and y values for the texture coordinates +in vec4 v_originTextureCoordinateAndTranslate; // texture coordinate at the origin, billboard translate (used for label glyphs) +in vec4 v_compressed; // x: eyeDepth, y: applyTranslate & enableDepthCheck, z: dimensions, w: imageSize +in mat2 v_rotationMatrix; const float SHIFT_LEFT12 = 4096.0; const float SHIFT_LEFT1 = 2.0; @@ -45,7 +45,7 @@ float getGlobeDepth(vec2 adjustedST, vec2 depthLookupST, bool applyTranslate, ve } vec2 st = ((lookupVector - translation + labelOffset) + gl_FragCoord.xy) / czm_viewport.zw; - float logDepthOrDepth = czm_unpackDepth(texture2D(czm_globeDepthTexture, st)); + float logDepthOrDepth = czm_unpackDepth(texture(czm_globeDepthTexture, st)); if (logDepthOrDepth == 0.0) { @@ -63,7 +63,7 @@ float getGlobeDepth(vec2 adjustedST, vec2 depthLookupST, bool applyTranslate, ve // Get the distance from the edge of a glyph at a given position sampling an SDF texture. float getDistance(vec2 position) { - return texture2D(u_atlas, position).r; + return texture(u_atlas, position).r; } // Samples the sdf texture at the given position and produces a color based on the fill color and the outline. @@ -90,7 +90,7 @@ vec4 getSDFColor(vec2 position, float outlineWidth, vec4 outlineColor, float smo void main() { - vec4 color = texture2D(u_atlas, v_textureCoordinates); + vec4 color = texture(u_atlas, v_textureCoordinates); #ifdef SDF float outlineWidth = v_outlineWidth; @@ -99,7 +99,7 @@ void main() // Get the current distance float distance = getDistance(v_textureCoordinates); -#ifdef GL_OES_standard_derivatives +#if (__VERSION__ == 300 || defined(GL_OES_standard_derivatives)) float smoothing = fwidth(distance); // Get an offset that is approximately half the distance to the neighbor pixels // 0.354 is approximately half of 1/sqrt(2) @@ -117,7 +117,7 @@ void main() // Equally weight the center sample and the 4 neighboring samples color = (center + color1 + color2 + color3 + color4)/5.0; #else - // Just do a single sample + // If no derivatives available (IE 10?), just do a single sample float smoothing = 1.0/32.0; color = getSDFColor(v_textureCoordinates, outlineWidth, outlineColor, smoothing); #endif @@ -153,7 +153,7 @@ void main() #ifdef VECTOR_TILE color *= u_highlightColor; #endif - gl_FragColor = color; + out_FragColor = color; #ifdef LOG_DEPTH czm_writeLogDepth(); diff --git a/packages/engine/Source/Shaders/BillboardCollectionVS.glsl b/packages/engine/Source/Shaders/BillboardCollectionVS.glsl index 56d291f34fcc..d8f927d07b59 100644 --- a/packages/engine/Source/Shaders/BillboardCollectionVS.glsl +++ b/packages/engine/Source/Shaders/BillboardCollectionVS.glsl @@ -1,36 +1,36 @@ #ifdef INSTANCED -attribute vec2 direction; +in vec2 direction; #endif -attribute vec4 positionHighAndScale; -attribute vec4 positionLowAndRotation; -attribute vec4 compressedAttribute0; // pixel offset, translate, horizontal origin, vertical origin, show, direction, texture coordinates (texture offset) -attribute vec4 compressedAttribute1; // aligned axis, translucency by distance, image width -attribute vec4 compressedAttribute2; // label horizontal origin, image height, color, pick color, size in meters, valid aligned axis, 13 bits free -attribute vec4 eyeOffset; // eye offset in meters, 4 bytes free (texture range) -attribute vec4 scaleByDistance; // near, nearScale, far, farScale -attribute vec4 pixelOffsetScaleByDistance; // near, nearScale, far, farScale -attribute vec4 compressedAttribute3; // distance display condition near, far, disableDepthTestDistance, dimensions -attribute vec2 sdf; // sdf outline color (rgb) and width (w) +in vec4 positionHighAndScale; +in vec4 positionLowAndRotation; +in vec4 compressedAttribute0; // pixel offset, translate, horizontal origin, vertical origin, show, direction, texture coordinates (texture offset) +in vec4 compressedAttribute1; // aligned axis, translucency by distance, image width +in vec4 compressedAttribute2; // label horizontal origin, image height, color, pick color, size in meters, valid aligned axis, 13 bits free +in vec4 eyeOffset; // eye offset in meters, 4 bytes free (texture range) +in vec4 scaleByDistance; // near, nearScale, far, farScale +in vec4 pixelOffsetScaleByDistance; // near, nearScale, far, farScale +in vec4 compressedAttribute3; // distance display condition near, far, disableDepthTestDistance, dimensions +in vec2 sdf; // sdf outline color (rgb) and width (w) #if defined(VERTEX_DEPTH_CHECK) || defined(FRAGMENT_DEPTH_CHECK) -attribute vec4 textureCoordinateBoundsOrLabelTranslate; // the min and max x and y values for the texture coordinates +in vec4 textureCoordinateBoundsOrLabelTranslate; // the min and max x and y values for the texture coordinates #endif #ifdef VECTOR_TILE -attribute float a_batchId; +in float a_batchId; #endif -varying vec2 v_textureCoordinates; +out vec2 v_textureCoordinates; #ifdef FRAGMENT_DEPTH_CHECK -varying vec4 v_textureCoordinateBounds; -varying vec4 v_originTextureCoordinateAndTranslate; -varying vec4 v_compressed; // x: eyeDepth, y: applyTranslate & enableDepthCheck, z: dimensions, w: imageSize -varying mat2 v_rotationMatrix; +out vec4 v_textureCoordinateBounds; +out vec4 v_originTextureCoordinateAndTranslate; +out vec4 v_compressed; // x: eyeDepth, y: applyTranslate & enableDepthCheck, z: dimensions, w: imageSize +out mat2 v_rotationMatrix; #endif -varying vec4 v_pickColor; -varying vec4 v_color; +out vec4 v_pickColor; +out vec4 v_color; #ifdef SDF -varying vec4 v_outlineColor; -varying float v_outlineWidth; +out vec4 v_outlineColor; +out float v_outlineWidth; #endif const float UPPER_BOUND = 32768.0; @@ -95,7 +95,7 @@ float getGlobeDepth(vec4 positionEC) { vec4 posWC = czm_eyeToWindowCoordinates(positionEC); - float globeDepth = czm_unpackDepth(texture2D(czm_globeDepthTexture, posWC.xy / czm_viewport.zw)); + float globeDepth = czm_unpackDepth(texture(czm_globeDepthTexture, posWC.xy / czm_viewport.zw)); if (globeDepth == 0.0) { diff --git a/packages/engine/Source/Shaders/BrdfLutGeneratorFS.glsl b/packages/engine/Source/Shaders/BrdfLutGeneratorFS.glsl index 677742c353eb..32bee9afd4fe 100644 --- a/packages/engine/Source/Shaders/BrdfLutGeneratorFS.glsl +++ b/packages/engine/Source/Shaders/BrdfLutGeneratorFS.glsl @@ -1,4 +1,4 @@ -varying vec2 v_textureCoordinates; +in vec2 v_textureCoordinates; const float M_PI = 3.141592653589793; float vdcRadicalInverse(int i) @@ -79,5 +79,5 @@ vec2 integrateBrdf(float roughness, float NdotV) void main() { - gl_FragColor = vec4(integrateBrdf(v_textureCoordinates.y, v_textureCoordinates.x), 0.0, 1.0); + out_FragColor = vec4(integrateBrdf(v_textureCoordinates.y, v_textureCoordinates.x), 0.0, 1.0); } diff --git a/packages/engine/Source/Shaders/Builtin/Functions/depthClamp.glsl b/packages/engine/Source/Shaders/Builtin/Functions/depthClamp.glsl index a00dfb537e58..e3f4de325aa7 100644 --- a/packages/engine/Source/Shaders/Builtin/Functions/depthClamp.glsl +++ b/packages/engine/Source/Shaders/Builtin/Functions/depthClamp.glsl @@ -1,6 +1,6 @@ // emulated noperspective -#if defined(GL_EXT_frag_depth) && !defined(LOG_DEPTH) -varying float v_WindowZ; +#if (__VERSION__ == 300 || defined(GL_EXT_frag_depth)) && !defined(LOG_DEPTH) +out float v_WindowZ; #endif /** @@ -36,7 +36,7 @@ varying float v_WindowZ; vec4 czm_depthClamp(vec4 coords) { #ifndef LOG_DEPTH -#ifdef GL_EXT_frag_depth +#if __VERSION__ == 300 || defined(GL_EXT_frag_depth) v_WindowZ = (0.5 * (coords.z / coords.w) + 0.5) * coords.w; coords.z = 0.0; #else diff --git a/packages/engine/Source/Shaders/Builtin/Functions/getWaterNoise.glsl b/packages/engine/Source/Shaders/Builtin/Functions/getWaterNoise.glsl index 11e452835c81..8228129a6c29 100644 --- a/packages/engine/Source/Shaders/Builtin/Functions/getWaterNoise.glsl +++ b/packages/engine/Source/Shaders/Builtin/Functions/getWaterNoise.glsl @@ -27,10 +27,10 @@ vec4 czm_getWaterNoise(sampler2D normalMap, vec2 uv, float time, float angleInRa uv1 = fract(uv1); uv2 = fract(uv2); uv3 = fract(uv3); - vec4 noise = (texture2D(normalMap, uv0)) + - (texture2D(normalMap, uv1)) + - (texture2D(normalMap, uv2)) + - (texture2D(normalMap, uv3)); + vec4 noise = (texture(normalMap, uv0)) + + (texture(normalMap, uv1)) + + (texture(normalMap, uv2)) + + (texture(normalMap, uv3)); // average and scale to between -1 and 1 return ((noise / 4.0) - 0.5) * 2.0; diff --git a/packages/engine/Source/Shaders/Builtin/Functions/phong.glsl b/packages/engine/Source/Shaders/Builtin/Functions/phong.glsl index af5db0a20d40..d7c018401680 100644 --- a/packages/engine/Source/Shaders/Builtin/Functions/phong.glsl +++ b/packages/engine/Source/Shaders/Builtin/Functions/phong.glsl @@ -23,7 +23,7 @@ float czm_private_getSpecularOfMaterial(vec3 lightDirectionEC, vec3 toEyeEC, czm * vec3 positionToEyeEC = // ... * czm_material material = // ... * vec3 lightDirectionEC = // ... - * gl_FragColor = czm_phong(normalize(positionToEyeEC), material, lightDirectionEC); + * out_FragColor = czm_phong(normalize(positionToEyeEC), material, lightDirectionEC); * * @see czm_getMaterial */ diff --git a/packages/engine/Source/Shaders/Builtin/Functions/readDepth.glsl b/packages/engine/Source/Shaders/Builtin/Functions/readDepth.glsl index e731a167b8c5..aed69cc5cc2e 100644 --- a/packages/engine/Source/Shaders/Builtin/Functions/readDepth.glsl +++ b/packages/engine/Source/Shaders/Builtin/Functions/readDepth.glsl @@ -1,4 +1,4 @@ float czm_readDepth(sampler2D depthTexture, vec2 texCoords) { - return czm_reverseLogDepth(texture2D(depthTexture, texCoords).r); + return czm_reverseLogDepth(texture(depthTexture, texCoords).r); } diff --git a/packages/engine/Source/Shaders/Builtin/Functions/sampleOctahedralProjection.glsl b/packages/engine/Source/Shaders/Builtin/Functions/sampleOctahedralProjection.glsl index 6c44a6e55d60..3a625ccfe417 100644 --- a/packages/engine/Source/Shaders/Builtin/Functions/sampleOctahedralProjection.glsl +++ b/packages/engine/Source/Shaders/Builtin/Functions/sampleOctahedralProjection.glsl @@ -32,10 +32,10 @@ vec3 czm_sampleOctahedralProjectionWithFiltering(sampler2D projectedMap, vec2 te // Do bilinear filtering #ifndef OES_texture_float_linear - vec3 color1 = texture2D(projectedMap, coord + vec2(0.0, pixel.y)).rgb; - vec3 color2 = texture2D(projectedMap, coord + vec2(pixel.x, 0.0)).rgb; - vec3 color3 = texture2D(projectedMap, coord + pixel).rgb; - vec3 color4 = texture2D(projectedMap, coord).rgb; + vec3 color1 = texture(projectedMap, coord + vec2(0.0, pixel.y)).rgb; + vec3 color2 = texture(projectedMap, coord + vec2(pixel.x, 0.0)).rgb; + vec3 color3 = texture(projectedMap, coord + pixel).rgb; + vec3 color4 = texture(projectedMap, coord).rgb; vec2 texturePosition = coord * textureSize; @@ -47,7 +47,7 @@ vec3 czm_sampleOctahedralProjectionWithFiltering(sampler2D projectedMap, vec2 te vec3 color = mix(average1, average2, fv); #else - vec3 color = texture2D(projectedMap, coord).rgb; + vec3 color = texture(projectedMap, coord).rgb; #endif return color; diff --git a/packages/engine/Source/Shaders/Builtin/Functions/shadowDepthCompare.glsl b/packages/engine/Source/Shaders/Builtin/Functions/shadowDepthCompare.glsl index ea7bec62ecc0..b95435b85c38 100644 --- a/packages/engine/Source/Shaders/Builtin/Functions/shadowDepthCompare.glsl +++ b/packages/engine/Source/Shaders/Builtin/Functions/shadowDepthCompare.glsl @@ -1,15 +1,15 @@ float czm_sampleShadowMap(highp samplerCube shadowMap, vec3 d) { - return czm_unpackDepth(textureCube(shadowMap, d)); + return czm_unpackDepth(czm_textureCube(shadowMap, d)); } float czm_sampleShadowMap(highp sampler2D shadowMap, vec2 uv) { #ifdef USE_SHADOW_DEPTH_TEXTURE - return texture2D(shadowMap, uv).r; + return texture(shadowMap, uv).r; #else - return czm_unpackDepth(texture2D(shadowMap, uv)); + return czm_unpackDepth(texture(shadowMap, uv)); #endif } diff --git a/packages/engine/Source/Shaders/Builtin/Functions/tangentToEyeSpaceMatrix.glsl b/packages/engine/Source/Shaders/Builtin/Functions/tangentToEyeSpaceMatrix.glsl index 46aae7308ea1..8f2403c9faff 100644 --- a/packages/engine/Source/Shaders/Builtin/Functions/tangentToEyeSpaceMatrix.glsl +++ b/packages/engine/Source/Shaders/Builtin/Functions/tangentToEyeSpaceMatrix.glsl @@ -12,7 +12,7 @@ * * @example * mat3 tangentToEye = czm_tangentToEyeSpaceMatrix(normalEC, tangentEC, bitangentEC); - * vec3 normal = tangentToEye * texture2D(normalMap, st).xyz; + * vec3 normal = tangentToEye * texture(normalMap, st).xyz; */ mat3 czm_tangentToEyeSpaceMatrix(vec3 normalEC, vec3 tangentEC, vec3 bitangentEC) { diff --git a/packages/engine/Source/Shaders/Builtin/Functions/textureCube.glsl b/packages/engine/Source/Shaders/Builtin/Functions/textureCube.glsl new file mode 100644 index 000000000000..123f1598ff10 --- /dev/null +++ b/packages/engine/Source/Shaders/Builtin/Functions/textureCube.glsl @@ -0,0 +1,17 @@ +/** + * A wrapper around the texture (WebGL2) / textureCube (WebGL1) + * function to allow for WebGL 1 support. + * + * @name czm_textureCube + * @glslFunction + * + * @param {samplerCube} sampler The sampler. + * @param {vec3} p The coordinates to sample the texture at. + */ +vec4 czm_textureCube(samplerCube sampler, vec3 p) { +#if __VERSION__ == 300 + return texture(sampler, p); +#else + return textureCube(sampler, p); +#endif +} \ No newline at end of file diff --git a/packages/engine/Source/Shaders/Builtin/Functions/translateRelativeToEye.glsl b/packages/engine/Source/Shaders/Builtin/Functions/translateRelativeToEye.glsl index efa787d06218..b62fabc76a22 100644 --- a/packages/engine/Source/Shaders/Builtin/Functions/translateRelativeToEye.glsl +++ b/packages/engine/Source/Shaders/Builtin/Functions/translateRelativeToEye.glsl @@ -17,8 +17,8 @@ * @returns {vec3} The position translated to be relative to the camera's position. * * @example - * attribute vec3 positionHigh; - * attribute vec3 positionLow; + * in vec3 positionHigh; + * in vec3 positionLow; * * void main() * { diff --git a/packages/engine/Source/Shaders/Builtin/Functions/vertexLogDepth.glsl b/packages/engine/Source/Shaders/Builtin/Functions/vertexLogDepth.glsl index a840e4b5724e..93276aeb268f 100644 --- a/packages/engine/Source/Shaders/Builtin/Functions/vertexLogDepth.glsl +++ b/packages/engine/Source/Shaders/Builtin/Functions/vertexLogDepth.glsl @@ -1,8 +1,8 @@ #ifdef LOG_DEPTH // 1.0 at the near plane, increasing linearly from there. -varying float v_depthFromNearPlusOne; +out float v_depthFromNearPlusOne; #ifdef SHADOW_MAP -varying vec3 v_logPositionEC; +out vec3 v_logPositionEC; #endif #endif diff --git a/packages/engine/Source/Shaders/Builtin/Functions/writeDepthClamp.glsl b/packages/engine/Source/Shaders/Builtin/Functions/writeDepthClamp.glsl index 665c3f1f5fd1..1b0ab8a080f2 100644 --- a/packages/engine/Source/Shaders/Builtin/Functions/writeDepthClamp.glsl +++ b/packages/engine/Source/Shaders/Builtin/Functions/writeDepthClamp.glsl @@ -1,27 +1,24 @@ // emulated noperspective -#if defined(GL_EXT_frag_depth) && !defined(LOG_DEPTH) -varying float v_WindowZ; +#if !defined(LOG_DEPTH) +in float v_WindowZ; #endif /** * Emulates GL_DEPTH_CLAMP. Clamps a fragment to the near and far plane * by writing the fragment's depth. See czm_depthClamp for more details. - *

- * The shader must enable the GL_EXT_frag_depth extension. - *

* * @name czm_writeDepthClamp * @glslFunction * * @example - * gl_FragColor = color; + * out_FragColor = color; * czm_writeDepthClamp(); * * @see czm_depthClamp */ void czm_writeDepthClamp() { -#if defined(GL_EXT_frag_depth) && !defined(LOG_DEPTH) - gl_FragDepthEXT = clamp(v_WindowZ * gl_FragCoord.w, 0.0, 1.0); +#if (!defined(LOG_DEPTH) && (__VERSION__ == 300 || defined(GL_EXT_frag_depth))) + gl_FragDepth = clamp(v_WindowZ * gl_FragCoord.w, 0.0, 1.0); #endif } diff --git a/packages/engine/Source/Shaders/Builtin/Functions/writeLogDepth.glsl b/packages/engine/Source/Shaders/Builtin/Functions/writeLogDepth.glsl index 45204f9efb6f..d0501b072459 100644 --- a/packages/engine/Source/Shaders/Builtin/Functions/writeLogDepth.glsl +++ b/packages/engine/Source/Shaders/Builtin/Functions/writeLogDepth.glsl @@ -1,5 +1,5 @@ #ifdef LOG_DEPTH -varying float v_depthFromNearPlusOne; +in float v_depthFromNearPlusOne; #ifdef POLYGON_OFFSET uniform vec2 u_polygonOffset; @@ -27,7 +27,7 @@ uniform vec2 u_polygonOffset; */ void czm_writeLogDepth(float depth) { -#if defined(GL_EXT_frag_depth) && defined(LOG_DEPTH) +#if (defined(LOG_DEPTH) && (__VERSION__ == 300 || defined(GL_EXT_frag_depth))) // Discard the vertex if it's not between the near and far planes. // We allow a bit of epsilon on the near plane comparison because a 1.0 // from the vertex shader (indicating the vertex should be _on_ the near @@ -41,8 +41,8 @@ void czm_writeLogDepth(float depth) float factor = u_polygonOffset[0]; float units = u_polygonOffset[1]; -// If we can't compute derivatives, just leave out the factor I guess? -#ifdef GL_OES_standard_derivatives +#if (__VERSION__ == 300 || defined(GL_OES_standard_derivatives)) + // This factor doesn't work in IE 10 if (factor != 0.0) { // m = sqrt(dZdX^2 + dZdY^2); float x = dFdx(depth); @@ -56,11 +56,11 @@ void czm_writeLogDepth(float depth) #endif - gl_FragDepthEXT = log2(depth) * czm_oneOverLog2FarDepthFromNearPlusOne; + gl_FragDepth = log2(depth) * czm_oneOverLog2FarDepthFromNearPlusOne; #ifdef POLYGON_OFFSET // Apply the units after the log depth. - gl_FragDepthEXT += czm_epsilon7 * units; + gl_FragDepth += czm_epsilon7 * units; #endif #endif diff --git a/packages/engine/Source/Shaders/CloudCollectionFS.glsl b/packages/engine/Source/Shaders/CloudCollectionFS.glsl index 086b4b2efc76..e1bdb39c62a6 100644 --- a/packages/engine/Source/Shaders/CloudCollectionFS.glsl +++ b/packages/engine/Source/Shaders/CloudCollectionFS.glsl @@ -1,11 +1,11 @@ uniform sampler2D u_noiseTexture; uniform vec3 u_noiseTextureDimensions; uniform float u_noiseDetail; -varying vec2 v_offset; -varying vec3 v_maximumSize; -varying vec4 v_color; -varying float v_slice; -varying float v_brightness; +in vec2 v_offset; +in vec3 v_maximumSize; +in vec4 v_color; +in float v_slice; +in float v_brightness; float wrap(float value, float rangeLength) { if(value < 0.0) { @@ -22,15 +22,14 @@ vec3 wrapVec(vec3 value, float rangeLength) { wrap(value.z, rangeLength)); } -float textureSliceWidth = u_noiseTextureDimensions.x; -float noiseTextureRows = u_noiseTextureDimensions.y; -float inverseNoiseTextureRows = u_noiseTextureDimensions.z; - -float textureSliceWidthSquared = textureSliceWidth * textureSliceWidth; -vec2 inverseNoiseTextureDimensions = vec2(noiseTextureRows / textureSliceWidthSquared, - inverseNoiseTextureRows / textureSliceWidth); - vec2 voxelToUV(vec3 voxelIndex) { + float textureSliceWidth = u_noiseTextureDimensions.x; + float noiseTextureRows = u_noiseTextureDimensions.y; + float inverseNoiseTextureRows = u_noiseTextureDimensions.z; + + float textureSliceWidthSquared = textureSliceWidth * textureSliceWidth; + vec2 inverseNoiseTextureDimensions = vec2(noiseTextureRows / textureSliceWidthSquared, + inverseNoiseTextureRows / textureSliceWidth); vec3 wrappedIndex = wrapVec(voxelIndex, textureSliceWidth); float column = mod(wrappedIndex.z, textureSliceWidth * inverseNoiseTextureRows); float row = floor(wrappedIndex.z / textureSliceWidth * noiseTextureRows); @@ -44,12 +43,13 @@ vec2 voxelToUV(vec3 voxelIndex) { vec4 lerpSamplesX(vec3 voxelIndex, float x) { vec2 uv0 = voxelToUV(voxelIndex); vec2 uv1 = voxelToUV(voxelIndex + vec3(1.0, 0.0, 0.0)); - vec4 sample0 = texture2D(u_noiseTexture, uv0); - vec4 sample1 = texture2D(u_noiseTexture, uv1); + vec4 sample0 = texture(u_noiseTexture, uv0); + vec4 sample1 = texture(u_noiseTexture, uv1); return mix(sample0, sample1, x); } vec4 sampleNoiseTexture(vec3 position) { + float textureSliceWidth = u_noiseTextureDimensions.x; vec3 recenteredPos = position + vec3(textureSliceWidth / 2.0); vec3 lerpValue = fract(recenteredPos); vec3 voxelIndex = floor(recenteredPos); @@ -231,7 +231,7 @@ vec4 drawCloud(vec3 rayOrigin, vec3 rayDir, vec3 cloudCenter, vec3 cloudScale, f void main() { #ifdef DEBUG_BILLBOARDS - gl_FragColor = vec4(0.0, 0.5, 0.5, 1.0); + out_FragColor = vec4(0.0, 0.5, 0.5, 1.0); #endif // To avoid calculations with high values, // we raycast from an arbitrarily smaller space. @@ -248,7 +248,7 @@ void main() { vec3 point, normal; if(intersectEllipsoid(rayOrigin, rayDir, ellipsoidCenter, ellipsoidScale, v_slice, point, normal)) { - gl_FragColor = v_brightness * v_color; + out_FragColor = v_brightness * v_color; } #else #ifndef DEBUG_BILLBOARDS @@ -257,7 +257,7 @@ void main() { if(cloud.w < 0.01) { discard; } - gl_FragColor = cloud; + out_FragColor = cloud; #endif #endif } diff --git a/packages/engine/Source/Shaders/CloudCollectionVS.glsl b/packages/engine/Source/Shaders/CloudCollectionVS.glsl index d241a3a517df..147274918ff3 100644 --- a/packages/engine/Source/Shaders/CloudCollectionVS.glsl +++ b/packages/engine/Source/Shaders/CloudCollectionVS.glsl @@ -1,17 +1,17 @@ #ifdef INSTANCED -attribute vec2 direction; +in vec2 direction; #endif -attribute vec4 positionHighAndScaleX; -attribute vec4 positionLowAndScaleY; -attribute vec4 packedAttribute0; -attribute vec4 packedAttribute1; -attribute vec4 color; +in vec4 positionHighAndScaleX; +in vec4 positionLowAndScaleY; +in vec4 packedAttribute0; +in vec4 packedAttribute1; +in vec4 color; -varying vec2 v_offset; -varying vec3 v_maximumSize; -varying vec4 v_color; -varying float v_slice; -varying float v_brightness; +out vec2 v_offset; +out vec3 v_maximumSize; +out vec4 v_color; +out float v_slice; +out float v_brightness; void main() { // Unpack attributes. diff --git a/packages/engine/Source/Shaders/CloudNoiseFS.glsl b/packages/engine/Source/Shaders/CloudNoiseFS.glsl index 5631a65000ab..7ea5f3919dd1 100644 --- a/packages/engine/Source/Shaders/CloudNoiseFS.glsl +++ b/packages/engine/Source/Shaders/CloudNoiseFS.glsl @@ -1,10 +1,7 @@ uniform vec3 u_noiseTextureDimensions; uniform float u_noiseDetail; uniform vec3 u_noiseOffset; -varying vec2 v_position; - -float textureSliceWidth = u_noiseTextureDimensions.x; -float inverseNoiseTextureRows = u_noiseTextureDimensions.z; +in vec2 v_position; float wrap(float value, float rangeLength) { if(value < 0.0) { @@ -30,6 +27,7 @@ vec3 random3(vec3 p) { // Frequency corresponds to cell size. // The higher the frequency, the smaller the cell size. vec3 getWorleyCellPoint(vec3 centerCell, vec3 offset, float freq) { + float textureSliceWidth = u_noiseTextureDimensions.x; vec3 cell = centerCell + offset; cell = wrapVec(cell, textureSliceWidth / u_noiseDetail); cell += floor(u_noiseOffset / u_noiseDetail); @@ -78,6 +76,8 @@ float worleyFBMNoise(vec3 p, float octaves, float scale) { } void main() { + float textureSliceWidth = u_noiseTextureDimensions.x; + float inverseNoiseTextureRows = u_noiseTextureDimensions.z; float x = mod(v_position.x, textureSliceWidth); float y = mod(v_position.y, textureSliceWidth); float sliceRow = floor(v_position.y / textureSliceWidth); @@ -88,5 +88,5 @@ void main() { float worley0 = clamp(worleyFBMNoise(position, 3.0, 1.0), 0.0, 1.0); float worley1 = clamp(worleyFBMNoise(position, 3.0, 2.0), 0.0, 1.0); float worley2 = clamp(worleyFBMNoise(position, 3.0, 3.0), 0.0, 1.0); - gl_FragColor = vec4(worley0, worley1, worley2, 1.0); + out_FragColor = vec4(worley0, worley1, worley2, 1.0); } diff --git a/packages/engine/Source/Shaders/CloudNoiseVS.glsl b/packages/engine/Source/Shaders/CloudNoiseVS.glsl index 20619d0d771a..4712618432be 100644 --- a/packages/engine/Source/Shaders/CloudNoiseVS.glsl +++ b/packages/engine/Source/Shaders/CloudNoiseVS.glsl @@ -1,7 +1,7 @@ uniform vec3 u_noiseTextureDimensions; -attribute vec2 position; +in vec2 position; -varying vec2 v_position; +out vec2 v_position; void main() { diff --git a/packages/engine/Source/Shaders/CompareAndPackTranslucentDepth.glsl b/packages/engine/Source/Shaders/CompareAndPackTranslucentDepth.glsl index 448d1c63f0de..29aac669067d 100644 --- a/packages/engine/Source/Shaders/CompareAndPackTranslucentDepth.glsl +++ b/packages/engine/Source/Shaders/CompareAndPackTranslucentDepth.glsl @@ -1,12 +1,12 @@ uniform sampler2D u_opaqueDepthTexture; uniform sampler2D u_translucentDepthTexture; -varying vec2 v_textureCoordinates; +in vec2 v_textureCoordinates; void main() { - float opaqueDepth = texture2D(u_opaqueDepthTexture, v_textureCoordinates).r; - float translucentDepth = texture2D(u_translucentDepthTexture, v_textureCoordinates).r; + float opaqueDepth = texture(u_opaqueDepthTexture, v_textureCoordinates).r; + float translucentDepth = texture(u_translucentDepthTexture, v_textureCoordinates).r; translucentDepth = czm_branchFreeTernary(translucentDepth > opaqueDepth, 1.0, translucentDepth); - gl_FragColor = czm_packDepth(translucentDepth); + out_FragColor = czm_packDepth(translucentDepth); } diff --git a/packages/engine/Source/Shaders/CompositeOITFS.glsl b/packages/engine/Source/Shaders/CompositeOITFS.glsl index dbe6c46d5801..63c284042fec 100644 --- a/packages/engine/Source/Shaders/CompositeOITFS.glsl +++ b/packages/engine/Source/Shaders/CompositeOITFS.glsl @@ -8,13 +8,13 @@ uniform sampler2D u_opaque; uniform sampler2D u_accumulation; uniform sampler2D u_revealage; -varying vec2 v_textureCoordinates; +in vec2 v_textureCoordinates; void main() { - vec4 opaque = texture2D(u_opaque, v_textureCoordinates); - vec4 accum = texture2D(u_accumulation, v_textureCoordinates); - float r = texture2D(u_revealage, v_textureCoordinates).r; + vec4 opaque = texture(u_opaque, v_textureCoordinates); + vec4 accum = texture(u_accumulation, v_textureCoordinates); + float r = texture(u_revealage, v_textureCoordinates).r; #ifdef MRT vec4 transparent = vec4(accum.rgb / clamp(r, 1e-4, 5e4), accum.a); @@ -22,10 +22,10 @@ void main() vec4 transparent = vec4(accum.rgb / clamp(accum.a, 1e-4, 5e4), r); #endif - gl_FragColor = (1.0 - transparent.a) * transparent + transparent.a * opaque; + out_FragColor = (1.0 - transparent.a) * transparent + transparent.a * opaque; if (opaque != czm_backgroundColor) { - gl_FragColor.a = 1.0; + out_FragColor.a = 1.0; } } diff --git a/packages/engine/Source/Shaders/DepthPlaneFS.glsl b/packages/engine/Source/Shaders/DepthPlaneFS.glsl index c6a9602ca1eb..0f28f70853f7 100644 --- a/packages/engine/Source/Shaders/DepthPlaneFS.glsl +++ b/packages/engine/Source/Shaders/DepthPlaneFS.glsl @@ -1,4 +1,4 @@ -varying vec4 positionEC; +in vec4 positionEC; void main() { @@ -25,7 +25,7 @@ void main() czm_raySegment intersection = czm_rayEllipsoidIntersectionInterval(ray, ellipsoid_center, czm_ellipsoidInverseRadii); if (!czm_isEmpty(intersection)) { - gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0); + out_FragColor = vec4(1.0, 1.0, 0.0, 1.0); } else { diff --git a/packages/engine/Source/Shaders/DepthPlaneVS.glsl b/packages/engine/Source/Shaders/DepthPlaneVS.glsl index 028b56c43700..4141585366a6 100644 --- a/packages/engine/Source/Shaders/DepthPlaneVS.glsl +++ b/packages/engine/Source/Shaders/DepthPlaneVS.glsl @@ -1,6 +1,6 @@ -attribute vec4 position; +in vec4 position; -varying vec4 positionEC; +out vec4 positionEC; void main() { diff --git a/packages/engine/Source/Shaders/EllipsoidFS.glsl b/packages/engine/Source/Shaders/EllipsoidFS.glsl index a8a78aa7d5bf..d640c442339e 100644 --- a/packages/engine/Source/Shaders/EllipsoidFS.glsl +++ b/packages/engine/Source/Shaders/EllipsoidFS.glsl @@ -1,13 +1,7 @@ -#ifdef WRITE_DEPTH -#ifdef GL_EXT_frag_depth -#extension GL_EXT_frag_depth : enable -#endif -#endif - uniform vec3 u_radii; uniform vec3 u_oneOverEllipsoidRadiiSquared; -varying vec3 v_positionEC; +in vec3 v_positionEC; vec4 computeEllipsoidColor(czm_ray ray, float intersection, float side) { @@ -89,11 +83,10 @@ void main() // If the viewer either is inside or can see inside, compute insideFaceColor, with normals facing inward. vec4 insideFaceColor = (outsideFaceColor.a < 1.0) ? computeEllipsoidColor(ray, intersection.stop, -1.0) : vec4(0.0); - gl_FragColor = mix(insideFaceColor, outsideFaceColor, outsideFaceColor.a); - gl_FragColor.a = 1.0 - (1.0 - insideFaceColor.a) * (1.0 - outsideFaceColor.a); + out_FragColor = mix(insideFaceColor, outsideFaceColor, outsideFaceColor.a); + out_FragColor.a = 1.0 - (1.0 - insideFaceColor.a) * (1.0 - outsideFaceColor.a); -#ifdef WRITE_DEPTH -#ifdef GL_EXT_frag_depth +#if (defined(WRITE_DEPTH) && (__VERSION__ == 300 || defined(GL_EXT_frag_depth))) t = (intersection.start != 0.0) ? intersection.start : intersection.stop; vec3 positionEC = czm_pointAlongRay(ray, t); vec4 positionCC = czm_projection * vec4(positionEC, 1.0); @@ -105,8 +98,7 @@ void main() float n = czm_depthRange.near; float f = czm_depthRange.far; - gl_FragDepthEXT = (z * (f - n) + f + n) * 0.5; -#endif + gl_FragDepth = (z * (f - n) + f + n) * 0.5; #endif #endif } diff --git a/packages/engine/Source/Shaders/EllipsoidVS.glsl b/packages/engine/Source/Shaders/EllipsoidVS.glsl index 0d3473911761..118b0e721cfb 100644 --- a/packages/engine/Source/Shaders/EllipsoidVS.glsl +++ b/packages/engine/Source/Shaders/EllipsoidVS.glsl @@ -1,8 +1,8 @@ -attribute vec3 position; +in vec3 position; uniform vec3 u_radii; -varying vec3 v_positionEC; +out vec3 v_positionEC; void main() { diff --git a/packages/engine/Source/Shaders/FXAA3_11.glsl b/packages/engine/Source/Shaders/FXAA3_11.glsl index 3499e14f1cfa..f08f7429cf23 100644 --- a/packages/engine/Source/Shaders/FXAA3_11.glsl +++ b/packages/engine/Source/Shaders/FXAA3_11.glsl @@ -48,8 +48,8 @@ // #define FxaaTexTop(t, p) texture2DLod(t, p, 0.0) // #define FxaaTexOff(t, p, o, r) texture2DLod(t, p + (o * r), 0.0) // with -// #define FxaaTexTop(t, p) texture2D(t, p) -// #define FxaaTexOff(t, p, o, r) texture2D(t, p + (o * r)) +// #define FxaaTexTop(t, p) texture(t, p) +// #define FxaaTexOff(t, p, o, r) texture(t, p + (o * r)) // * FXAA_QUALITY_PRESET is prepended in the javascript code. We may want to expose that setting in the future. // * The following parameters to FxaaPixelShader are unused and can be removed: // fxaaConsolePosPos @@ -269,8 +269,8 @@ #define FxaaTex sampler2D #define FxaaSat(x) clamp(x, 0.0, 1.0) -#define FxaaTexTop(t, p) texture2D(t, p) -#define FxaaTexOff(t, p, o, r) texture2D(t, p + (o * r)) +#define FxaaTexTop(t, p) texture(t, p) +#define FxaaTexOff(t, p, o, r) texture(t, p + (o * r)) FxaaFloat FxaaLuma(FxaaFloat4 rgba) { return rgba.y; } diff --git a/packages/engine/Source/Shaders/GlobeFS.glsl b/packages/engine/Source/Shaders/GlobeFS.glsl index 412f7330fc32..903833ac45ed 100644 --- a/packages/engine/Source/Shaders/GlobeFS.glsl +++ b/packages/engine/Source/Shaders/GlobeFS.glsl @@ -105,26 +105,26 @@ uniform float u_lambertDiffuseMultiplier; uniform float u_vertexShadowDarkness; #endif -varying vec3 v_positionMC; -varying vec3 v_positionEC; -varying vec3 v_textureCoordinates; -varying vec3 v_normalMC; -varying vec3 v_normalEC; +in vec3 v_positionMC; +in vec3 v_positionEC; +in vec3 v_textureCoordinates; +in vec3 v_normalMC; +in vec3 v_normalEC; #ifdef APPLY_MATERIAL -varying float v_height; -varying float v_slope; -varying float v_aspect; +in float v_height; +in float v_slope; +in float v_aspect; #endif #if defined(FOG) || defined(GROUND_ATMOSPHERE) || defined(UNDERGROUND_COLOR) || defined(TRANSLUCENT) -varying float v_distance; +in float v_distance; #endif #if defined(GROUND_ATMOSPHERE) || defined(FOG) -varying vec3 v_atmosphereRayleighColor; -varying vec3 v_atmosphereMieColor; -varying float v_atmosphereOpacity; +in vec3 v_atmosphereRayleighColor; +in vec3 v_atmosphereMieColor; +in float v_atmosphereOpacity; #endif #if defined(UNDERGROUND_COLOR) || defined(TRANSLUCENT) @@ -195,7 +195,7 @@ vec4 sampleAndBlend( vec2 translation = textureCoordinateTranslationAndScale.xy; vec2 scale = textureCoordinateTranslationAndScale.zw; vec2 textureCoordinates = tileTextureCoordinates * scale + translation; - vec4 value = texture2D(textureToSample, textureCoordinates); + vec4 value = texture(textureToSample, textureCoordinates); vec3 color = value.rgb; float alpha = value.a; @@ -376,7 +376,7 @@ void main() vec2 waterMaskTextureCoordinates = v_textureCoordinates.xy * waterMaskScale + waterMaskTranslation; waterMaskTextureCoordinates.y = 1.0 - waterMaskTextureCoordinates.y; - float mask = texture2D(u_waterMask, waterMaskTextureCoordinates).r; + float mask = texture(u_waterMask, waterMaskTextureCoordinates).r; if (mask > 0.0) { @@ -545,7 +545,7 @@ void main() } #endif - gl_FragColor = finalColor; + out_FragColor = finalColor; } diff --git a/packages/engine/Source/Shaders/GlobeVS.glsl b/packages/engine/Source/Shaders/GlobeVS.glsl index 2bdda38f5a28..65b4d1547ff1 100644 --- a/packages/engine/Source/Shaders/GlobeVS.glsl +++ b/packages/engine/Source/Shaders/GlobeVS.glsl @@ -1,13 +1,13 @@ #ifdef QUANTIZATION_BITS12 -attribute vec4 compressed0; -attribute float compressed1; +in vec4 compressed0; +in float compressed1; #else -attribute vec4 position3DAndHeight; -attribute vec4 textureCoordAndEncodedNormals; +in vec4 position3DAndHeight; +in vec4 textureCoordAndEncodedNormals; #endif #ifdef GEODETIC_SURFACE_NORMALS -attribute vec3 geodeticSurfaceNormal; +in vec3 geodeticSurfaceNormal; #endif #ifdef EXAGGERATION @@ -23,27 +23,27 @@ uniform vec4 u_tileRectangle; uniform vec2 u_southAndNorthLatitude; uniform vec2 u_southMercatorYAndOneOverHeight; -varying vec3 v_positionMC; -varying vec3 v_positionEC; +out vec3 v_positionMC; +out vec3 v_positionEC; -varying vec3 v_textureCoordinates; -varying vec3 v_normalMC; -varying vec3 v_normalEC; +out vec3 v_textureCoordinates; +out vec3 v_normalMC; +out vec3 v_normalEC; #ifdef APPLY_MATERIAL -varying float v_slope; -varying float v_aspect; -varying float v_height; +out float v_slope; +out float v_aspect; +out float v_height; #endif #if defined(FOG) || defined(GROUND_ATMOSPHERE) || defined(UNDERGROUND_COLOR) || defined(TRANSLUCENT) -varying float v_distance; +out float v_distance; #endif #if defined(FOG) || defined(GROUND_ATMOSPHERE) -varying vec3 v_atmosphereRayleighColor; -varying vec3 v_atmosphereMieColor; -varying float v_atmosphereOpacity; +out vec3 v_atmosphereRayleighColor; +out vec3 v_atmosphereMieColor; +out float v_atmosphereOpacity; #endif // These functions are generated at runtime. diff --git a/packages/engine/Source/Shaders/Materials/AspectRampMaterial.glsl b/packages/engine/Source/Shaders/Materials/AspectRampMaterial.glsl index 6e9ffa75b1d2..dd44320d1323 100644 --- a/packages/engine/Source/Shaders/Materials/AspectRampMaterial.glsl +++ b/packages/engine/Source/Shaders/Materials/AspectRampMaterial.glsl @@ -3,7 +3,7 @@ uniform sampler2D image; czm_material czm_getMaterial(czm_materialInput materialInput) { czm_material material = czm_getDefaultMaterial(materialInput); - vec4 rampColor = texture2D(image, vec2(materialInput.aspect / (2.0 * czm_pi), 0.5)); + vec4 rampColor = texture(image, vec2(materialInput.aspect / (2.0 * czm_pi), 0.5)); rampColor = czm_gammaCorrect(rampColor); material.diffuse = rampColor.rgb; material.alpha = rampColor.a; diff --git a/packages/engine/Source/Shaders/Materials/BumpMapMaterial.glsl b/packages/engine/Source/Shaders/Materials/BumpMapMaterial.glsl index 2316a17fa045..05b41d973818 100644 --- a/packages/engine/Source/Shaders/Materials/BumpMapMaterial.glsl +++ b/packages/engine/Source/Shaders/Materials/BumpMapMaterial.glsl @@ -9,15 +9,15 @@ czm_material czm_getMaterial(czm_materialInput materialInput) vec2 st = materialInput.st; vec2 centerPixel = fract(repeat * st); - float centerBump = texture2D(image, centerPixel).channel; + float centerBump = texture(image, centerPixel).channel; float imageWidth = float(imageDimensions.x); vec2 rightPixel = fract(repeat * (st + vec2(1.0 / imageWidth, 0.0))); - float rightBump = texture2D(image, rightPixel).channel; + float rightBump = texture(image, rightPixel).channel; float imageHeight = float(imageDimensions.y); vec2 leftPixel = fract(repeat * (st + vec2(0.0, 1.0 / imageHeight))); - float topBump = texture2D(image, leftPixel).channel; + float topBump = texture(image, leftPixel).channel; vec3 normalTangentSpace = normalize(vec3(centerBump - rightBump, centerBump - topBump, clamp(1.0 - strength, 0.1, 1.0))); vec3 normalEC = materialInput.tangentToEyeMatrix * normalTangentSpace; diff --git a/packages/engine/Source/Shaders/Materials/ElevationBandMaterial.glsl b/packages/engine/Source/Shaders/Materials/ElevationBandMaterial.glsl index 1e4a4ef53b3f..0def952b86b1 100644 --- a/packages/engine/Source/Shaders/Materials/ElevationBandMaterial.glsl +++ b/packages/engine/Source/Shaders/Materials/ElevationBandMaterial.glsl @@ -7,9 +7,9 @@ float getHeight(int idx, float invTexSize) { vec2 uv = vec2((float(idx) + 0.5) * invTexSize, 0.5); #ifdef OES_texture_float - return texture2D(heights, uv).x; + return texture(heights, uv).x; #else - return czm_unpackFloat(texture2D(heights, uv)); + return czm_unpackFloat(texture(heights, uv)); #endif } @@ -58,7 +58,7 @@ czm_material czm_getMaterial(czm_materialInput materialInput) float lerper = heightBelow == heightAbove ? 1.0 : (height - heightBelow) / (heightAbove - heightBelow); vec2 colorUv = vec2(invTexSize * (float(idxBelow) + 0.5 + lerper), 0.5); - vec4 color = texture2D(colors, colorUv); + vec4 color = texture(colors, colorUv); // undo preumultiplied alpha if (color.a > 0.0) diff --git a/packages/engine/Source/Shaders/Materials/ElevationContourMaterial.glsl b/packages/engine/Source/Shaders/Materials/ElevationContourMaterial.glsl index 9c76667d47e5..23c50dea533a 100644 --- a/packages/engine/Source/Shaders/Materials/ElevationContourMaterial.glsl +++ b/packages/engine/Source/Shaders/Materials/ElevationContourMaterial.glsl @@ -12,12 +12,13 @@ czm_material czm_getMaterial(czm_materialInput materialInput) float distanceToContour = mod(materialInput.height, spacing); -#ifdef GL_OES_standard_derivatives +#if (__VERSION__ == 300 || defined(GL_OES_standard_derivatives)) float dxc = abs(dFdx(materialInput.height)); float dyc = abs(dFdy(materialInput.height)); float dF = max(dxc, dyc) * czm_pixelRatio * width; float alpha = (distanceToContour < dF) ? 1.0 : 0.0; #else + // If no derivatives available (IE 10?), use pixel ratio float alpha = (distanceToContour < (czm_pixelRatio * width)) ? 1.0 : 0.0; #endif diff --git a/packages/engine/Source/Shaders/Materials/ElevationRampMaterial.glsl b/packages/engine/Source/Shaders/Materials/ElevationRampMaterial.glsl index a9680c003f63..f1fcd91643ce 100644 --- a/packages/engine/Source/Shaders/Materials/ElevationRampMaterial.glsl +++ b/packages/engine/Source/Shaders/Materials/ElevationRampMaterial.glsl @@ -6,7 +6,7 @@ czm_material czm_getMaterial(czm_materialInput materialInput) { czm_material material = czm_getDefaultMaterial(materialInput); float scaledHeight = clamp((materialInput.height - minimumHeight) / (maximumHeight - minimumHeight), 0.0, 1.0); - vec4 rampColor = texture2D(image, vec2(scaledHeight, 0.5)); + vec4 rampColor = texture(image, vec2(scaledHeight, 0.5)); rampColor = czm_gammaCorrect(rampColor); material.diffuse = rampColor.rgb; material.alpha = rampColor.a; diff --git a/packages/engine/Source/Shaders/Materials/GridMaterial.glsl b/packages/engine/Source/Shaders/Materials/GridMaterial.glsl index 24df524b134c..a56f6e74e834 100644 --- a/packages/engine/Source/Shaders/Materials/GridMaterial.glsl +++ b/packages/engine/Source/Shaders/Materials/GridMaterial.glsl @@ -20,8 +20,9 @@ czm_material czm_getMaterial(czm_materialInput materialInput) scaledHeight = abs(scaledHeight - floor(scaledHeight + 0.5)); float value; -#ifdef GL_OES_standard_derivatives + // Fuzz Factor - Controls blurriness of lines +#if (__VERSION__ == 300 || defined(GL_OES_standard_derivatives)) const float fuzz = 1.2; vec2 thickness = (lineThickness * czm_pixelRatio) - 1.0; @@ -33,7 +34,7 @@ czm_material czm_getMaterial(czm_materialInput materialInput) smoothstep(dF.s * thickness.s, dF.s * (fuzz + thickness.s), scaledWidth), smoothstep(dF.t * thickness.t, dF.t * (fuzz + thickness.t), scaledHeight)); #else - // Fuzz Factor - Controls blurriness of lines + // If no derivatives available (IE 10?), revert to view-dependent fuzz const float fuzz = 0.05; vec2 range = 0.5 - (lineThickness * 0.05); diff --git a/packages/engine/Source/Shaders/Materials/NormalMapMaterial.glsl b/packages/engine/Source/Shaders/Materials/NormalMapMaterial.glsl index 2d8a9fb2c0b7..919d9027a91e 100644 --- a/packages/engine/Source/Shaders/Materials/NormalMapMaterial.glsl +++ b/packages/engine/Source/Shaders/Materials/NormalMapMaterial.glsl @@ -6,7 +6,7 @@ czm_material czm_getMaterial(czm_materialInput materialInput) { czm_material material = czm_getDefaultMaterial(materialInput); - vec4 textureValue = texture2D(image, fract(repeat * materialInput.st)); + vec4 textureValue = texture(image, fract(repeat * materialInput.st)); vec3 normalTangentSpace = textureValue.channels; normalTangentSpace.xy = normalTangentSpace.xy * 2.0 - 1.0; normalTangentSpace.z = clamp(1.0 - strength, 0.1, 1.0); diff --git a/packages/engine/Source/Shaders/Materials/PolylineArrowMaterial.glsl b/packages/engine/Source/Shaders/Materials/PolylineArrowMaterial.glsl index b01bb6e1dcad..760ac458021b 100644 --- a/packages/engine/Source/Shaders/Materials/PolylineArrowMaterial.glsl +++ b/packages/engine/Source/Shaders/Materials/PolylineArrowMaterial.glsl @@ -16,10 +16,11 @@ czm_material czm_getMaterial(czm_materialInput materialInput) vec2 st = materialInput.st; -#ifdef GL_OES_standard_derivatives +#if (__VERSION__ == 300 || defined(GL_OES_standard_derivatives)) float base = 1.0 - abs(fwidth(st.s)) * 10.0 * czm_pixelRatio; #else - float base = 0.975; // 2.5% of the line will be the arrow head + // If no derivatives available (IE 10?), 2.5% of the line will be the arrow head + float base = 0.975; #endif vec2 center = vec2(1.0, 0.5); diff --git a/packages/engine/Source/Shaders/Materials/PolylineDashMaterial.glsl b/packages/engine/Source/Shaders/Materials/PolylineDashMaterial.glsl index 20a11882f9a3..7d2f9131fad6 100644 --- a/packages/engine/Source/Shaders/Materials/PolylineDashMaterial.glsl +++ b/packages/engine/Source/Shaders/Materials/PolylineDashMaterial.glsl @@ -2,7 +2,7 @@ uniform vec4 color; uniform vec4 gapColor; uniform float dashLength; uniform float dashPattern; -varying float v_polylineAngle; +in float v_polylineAngle; const float maskLength = 16.0; diff --git a/packages/engine/Source/Shaders/Materials/PolylineOutlineMaterial.glsl b/packages/engine/Source/Shaders/Materials/PolylineOutlineMaterial.glsl index 196505bc5891..fc37a2c6af0c 100644 --- a/packages/engine/Source/Shaders/Materials/PolylineOutlineMaterial.glsl +++ b/packages/engine/Source/Shaders/Materials/PolylineOutlineMaterial.glsl @@ -2,7 +2,7 @@ uniform vec4 color; uniform vec4 outlineColor; uniform float outlineWidth; -varying float v_width; +in float v_width; czm_material czm_getMaterial(czm_materialInput materialInput) { diff --git a/packages/engine/Source/Shaders/Materials/SlopeRampMaterial.glsl b/packages/engine/Source/Shaders/Materials/SlopeRampMaterial.glsl index 737191c83e60..3c0caba3eeea 100644 --- a/packages/engine/Source/Shaders/Materials/SlopeRampMaterial.glsl +++ b/packages/engine/Source/Shaders/Materials/SlopeRampMaterial.glsl @@ -3,7 +3,7 @@ uniform sampler2D image; czm_material czm_getMaterial(czm_materialInput materialInput) { czm_material material = czm_getDefaultMaterial(materialInput); - vec4 rampColor = texture2D(image, vec2(materialInput.slope / (czm_pi / 2.0), 0.5)); + vec4 rampColor = texture(image, vec2(materialInput.slope / (czm_pi / 2.0), 0.5)); rampColor = czm_gammaCorrect(rampColor); material.diffuse = rampColor.rgb; material.alpha = rampColor.a; diff --git a/packages/engine/Source/Shaders/Materials/Water.glsl b/packages/engine/Source/Shaders/Materials/Water.glsl index 89b8f8c857ef..6c4be9d19a57 100644 --- a/packages/engine/Source/Shaders/Materials/Water.glsl +++ b/packages/engine/Source/Shaders/Materials/Water.glsl @@ -20,7 +20,7 @@ czm_material czm_getMaterial(czm_materialInput materialInput) // fade is a function of the distance from the fragment and the frequency of the waves float fade = max(1.0, (length(materialInput.positionToEyeEC) / 10000000000.0) * frequency * fadeFactor); - float specularMapValue = texture2D(specularMap, materialInput.st).r; + float specularMapValue = texture(specularMap, materialInput.st).r; // note: not using directional motion at this time, just set the angle to 0.0; vec4 noise = czm_getWaterNoise(normalMap, materialInput.st * frequency, time, 0.0); diff --git a/packages/engine/Source/Shaders/Model/ImageBasedLightingStageFS.glsl b/packages/engine/Source/Shaders/Model/ImageBasedLightingStageFS.glsl index cd940641962e..22fda5197e47 100644 --- a/packages/engine/Source/Shaders/Model/ImageBasedLightingStageFS.glsl +++ b/packages/engine/Source/Shaders/Model/ImageBasedLightingStageFS.glsl @@ -30,7 +30,7 @@ vec3 proceduralIBL( float inverseRoughness = 1.04 - roughness; inverseRoughness *= inverseRoughness; - vec3 sceneSkyBox = textureCube(czm_environmentMap, r).rgb * inverseRoughness; + vec3 sceneSkyBox = czm_textureCube(czm_environmentMap, r).rgb * inverseRoughness; float atmosphereHeight = 0.05; float blendRegionSize = 0.1 * ((1.0 - inverseRoughness) * 8.0 + 1.1 - horizonDotNadir); @@ -67,7 +67,7 @@ vec3 proceduralIBL( float luminance = model_luminanceAtZenith * (numerator / denominator); #endif - vec2 brdfLut = texture2D(czm_brdfLut, vec2(NdotV, roughness)).rg; + vec2 brdfLut = texture(czm_brdfLut, vec2(NdotV, roughness)).rg; vec3 iblColor = (diffuseIrradiance * diffuseColor * model_iblFactor.x) + (specularIrradiance * czm_srgbToLinear(specularColor * brdfLut.x + brdfLut.y) * model_iblFactor.y); float maximumComponent = max(max(lightColorHdr.x, lightColorHdr.y), lightColorHdr.z); vec3 lightColor = lightColorHdr / max(maximumComponent, 1.0); @@ -122,7 +122,7 @@ vec3 textureIBL( vec3 r90 = vec3(clamp(reflectance * 25.0, 0.0, 1.0)); vec3 F = fresnelSchlick2(r0, r90, VdotH); - vec2 brdfLut = texture2D(czm_brdfLut, vec2(NdotV, roughness)).rg; + vec2 brdfLut = texture(czm_brdfLut, vec2(NdotV, roughness)).rg; #ifdef CUSTOM_SPECULAR_IBL vec3 specularIBL = czm_sampleOctahedralProjection(model_specularEnvironmentMaps, model_specularEnvironmentMapsSize, cubeDir, roughness * model_specularEnvironmentMapsMaximumLOD, model_specularEnvironmentMapsMaximumLOD); #else diff --git a/packages/engine/Source/Shaders/Model/MaterialStageFS.glsl b/packages/engine/Source/Shaders/Model/MaterialStageFS.glsl index c4b56f12034e..784c9274b97c 100644 --- a/packages/engine/Source/Shaders/Model/MaterialStageFS.glsl +++ b/packages/engine/Source/Shaders/Model/MaterialStageFS.glsl @@ -34,10 +34,10 @@ vec3 computeNormal(ProcessedAttributes attributes) vec3 t = attributes.tangentEC; vec3 b = attributes.bitangentEC; mat3 tbn = mat3(t, b, ng); - vec3 n = texture2D(u_normalTexture, normalTexCoords).rgb; + vec3 n = texture(u_normalTexture, normalTexCoords).rgb; normal = normalize(tbn * (2.0 * n - 1.0)); - #elif defined(GL_OES_standard_derivatives) - // Compute tangents + #elif (__VERSION__ == 300 || defined(GL_OES_standard_derivatives)) + // If derivatives are available (not IE 10), compute tangents vec3 positionEC = attributes.positionEC; vec3 pos_dx = dFdx(positionEC); vec3 pos_dy = dFdy(positionEC); @@ -47,7 +47,7 @@ vec3 computeNormal(ProcessedAttributes attributes) t = normalize(t - ng * dot(ng, t)); vec3 b = normalize(cross(ng, t)); mat3 tbn = mat3(t, b, ng); - vec3 n = texture2D(u_normalTexture, normalTexCoords).rgb; + vec3 n = texture(u_normalTexture, normalTexCoords).rgb; normal = normalize(tbn * (2.0 * n - 1.0)); #endif #endif @@ -77,7 +77,7 @@ void materialStage(inout czm_modelMaterial material, ProcessedAttributes attribu baseColorTexCoords = computeTextureTransform(baseColorTexCoords, u_baseColorTextureTransform); #endif - baseColorWithAlpha = czm_srgbToLinear(texture2D(u_baseColorTexture, baseColorTexCoords)); + baseColorWithAlpha = czm_srgbToLinear(texture(u_baseColorTexture, baseColorTexCoords)); #ifdef HAS_BASE_COLOR_FACTOR baseColorWithAlpha *= u_baseColorFactor; @@ -109,7 +109,7 @@ void materialStage(inout czm_modelMaterial material, ProcessedAttributes attribu #ifdef HAS_OCCLUSION_TEXTURE_TRANSFORM occlusionTexCoords = computeTextureTransform(occlusionTexCoords, u_occlusionTextureTransform); #endif - material.occlusion = texture2D(u_occlusionTexture, occlusionTexCoords).r; + material.occlusion = texture(u_occlusionTexture, occlusionTexCoords).r; #endif #ifdef HAS_EMISSIVE_TEXTURE @@ -118,7 +118,7 @@ void materialStage(inout czm_modelMaterial material, ProcessedAttributes attribu emissiveTexCoords = computeTextureTransform(emissiveTexCoords, u_emissiveTextureTransform); #endif - vec3 emissive = czm_srgbToLinear(texture2D(u_emissiveTexture, emissiveTexCoords).rgb); + vec3 emissive = czm_srgbToLinear(texture(u_emissiveTexture, emissiveTexCoords).rgb); #ifdef HAS_EMISSIVE_FACTOR emissive *= u_emissiveFactor; #endif @@ -134,7 +134,7 @@ void materialStage(inout czm_modelMaterial material, ProcessedAttributes attribu specularGlossinessTexCoords = computeTextureTransform(specularGlossinessTexCoords, u_specularGlossinessTextureTransform); #endif - vec4 specularGlossiness = czm_srgbToLinear(texture2D(u_specularGlossinessTexture, specularGlossinessTexCoords)); + vec4 specularGlossiness = czm_srgbToLinear(texture(u_specularGlossinessTexture, specularGlossinessTexCoords)); vec3 specular = specularGlossiness.rgb; float glossiness = specularGlossiness.a; #ifdef HAS_SPECULAR_FACTOR @@ -164,7 +164,7 @@ void materialStage(inout czm_modelMaterial material, ProcessedAttributes attribu diffuseTexCoords = computeTextureTransform(diffuseTexCoords, u_diffuseTextureTransform); #endif - vec4 diffuse = czm_srgbToLinear(texture2D(u_diffuseTexture, diffuseTexCoords)); + vec4 diffuse = czm_srgbToLinear(texture(u_diffuseTexture, diffuseTexCoords)); #ifdef HAS_DIFFUSE_FACTOR diffuse *= u_diffuseFactor; #endif @@ -191,7 +191,7 @@ void materialStage(inout czm_modelMaterial material, ProcessedAttributes attribu metallicRoughnessTexCoords = computeTextureTransform(metallicRoughnessTexCoords, u_metallicRoughnessTextureTransform); #endif - vec3 metallicRoughness = texture2D(u_metallicRoughnessTexture, metallicRoughnessTexCoords).rgb; + vec3 metallicRoughness = texture(u_metallicRoughnessTexture, metallicRoughnessTexCoords).rgb; float metalness = clamp(metallicRoughness.b, 0.0, 1.0); float roughness = clamp(metallicRoughness.g, 0.04, 1.0); #ifdef HAS_METALLIC_FACTOR diff --git a/packages/engine/Source/Shaders/Model/ModelClippingPlanesStageFS.glsl b/packages/engine/Source/Shaders/Model/ModelClippingPlanesStageFS.glsl index b09545bcf428..22fdb0cfa350 100644 --- a/packages/engine/Source/Shaders/Model/ModelClippingPlanesStageFS.glsl +++ b/packages/engine/Source/Shaders/Model/ModelClippingPlanesStageFS.glsl @@ -10,7 +10,7 @@ vec4 getClippingPlane( float pixelHeight = 1.0 / float(CLIPPING_PLANES_TEXTURE_HEIGHT); float u = (float(pixX) + 0.5) * pixelWidth; // sample from center of pixel float v = (float(pixY) + 0.5) * pixelHeight; - vec4 plane = texture2D(packedClippingPlanes, vec2(u, v)); + vec4 plane = texture(packedClippingPlanes, vec2(u, v)); return czm_transformPlane(plane, transform); } #else @@ -27,11 +27,11 @@ vec4 getClippingPlane( float pixelHeight = 1.0 / float(CLIPPING_PLANES_TEXTURE_HEIGHT); float u = (float(pixX) + 0.5) * pixelWidth; // sample from center of pixel float v = (float(pixY) + 0.5) * pixelHeight; - vec4 oct32 = texture2D(packedClippingPlanes, vec2(u, v)) * 255.0; + vec4 oct32 = texture(packedClippingPlanes, vec2(u, v)) * 255.0; vec2 oct = vec2(oct32.x * 256.0 + oct32.y, oct32.z * 256.0 + oct32.w); vec4 plane; plane.xyz = czm_octDecode(oct, 65535.0); - plane.w = czm_unpackFloat(texture2D(packedClippingPlanes, vec2(u + pixelWidth, v))); + plane.w = czm_unpackFloat(texture(packedClippingPlanes, vec2(u + pixelWidth, v))); return czm_transformPlane(plane, transform); } #endif diff --git a/packages/engine/Source/Shaders/Model/ModelFS.glsl b/packages/engine/Source/Shaders/Model/ModelFS.glsl index cc68a1f19e5d..a7cde6064978 100644 --- a/packages/engine/Source/Shaders/Model/ModelFS.glsl +++ b/packages/engine/Source/Shaders/Model/ModelFS.glsl @@ -85,5 +85,5 @@ void main() silhouetteStage(color); #endif - gl_FragColor = color; + out_FragColor = color; } diff --git a/packages/engine/Source/Shaders/Model/PrimitiveOutlineStageFS.glsl b/packages/engine/Source/Shaders/Model/PrimitiveOutlineStageFS.glsl index 232634c1c3ea..8b5c9afe784d 100644 --- a/packages/engine/Source/Shaders/Model/PrimitiveOutlineStageFS.glsl +++ b/packages/engine/Source/Shaders/Model/PrimitiveOutlineStageFS.glsl @@ -4,11 +4,11 @@ void primitiveOutlineStage(inout czm_modelMaterial material) { } float outlineX = - texture2D(model_outlineTexture, vec2(v_outlineCoordinates.x, 0.5)).r; + texture(model_outlineTexture, vec2(v_outlineCoordinates.x, 0.5)).r; float outlineY = - texture2D(model_outlineTexture, vec2(v_outlineCoordinates.y, 0.5)).r; + texture(model_outlineTexture, vec2(v_outlineCoordinates.y, 0.5)).r; float outlineZ = - texture2D(model_outlineTexture, vec2(v_outlineCoordinates.z, 0.5)).r; + texture(model_outlineTexture, vec2(v_outlineCoordinates.z, 0.5)).r; float outlineness = max(outlineX, max(outlineY, outlineZ)); material.diffuse = mix(material.diffuse, model_outlineColor.rgb, model_outlineColor.a * outlineness); diff --git a/packages/engine/Source/Shaders/Model/SelectedFeatureIdStageCommon.glsl b/packages/engine/Source/Shaders/Model/SelectedFeatureIdStageCommon.glsl index 372a9cc4ed2a..47367e3e4fb9 100644 --- a/packages/engine/Source/Shaders/Model/SelectedFeatureIdStageCommon.glsl +++ b/packages/engine/Source/Shaders/Model/SelectedFeatureIdStageCommon.glsl @@ -27,7 +27,7 @@ void selectedFeatureIdStage(out SelectedFeature feature, FeatureIds featureIds) feature.id = featureId; feature.st = featureSt; - feature.color = texture2D(model_batchTexture, featureSt); + feature.color = texture(model_batchTexture, featureSt); } // Floating point comparisons can be unreliable in GLSL, so we // increment the feature ID to make sure it's always greater diff --git a/packages/engine/Source/Shaders/OctahedralProjectionAtlasFS.glsl b/packages/engine/Source/Shaders/OctahedralProjectionAtlasFS.glsl index 36015ee95b19..f6d6953e11a5 100644 --- a/packages/engine/Source/Shaders/OctahedralProjectionAtlasFS.glsl +++ b/packages/engine/Source/Shaders/OctahedralProjectionAtlasFS.glsl @@ -1,4 +1,4 @@ -varying vec2 v_textureCoordinates; +in vec2 v_textureCoordinates; uniform float originalSize; uniform sampler2D texture0; @@ -60,30 +60,30 @@ void main() if(mipLevel == 0.0) { - gl_FragColor = texture2D(texture0, uv); + out_FragColor = texture(texture0, uv); } else if(mipLevel == 1.0) { - gl_FragColor = texture2D(texture1, uv); + out_FragColor = texture(texture1, uv); } else if(mipLevel == 2.0) { - gl_FragColor = texture2D(texture2, uv); + out_FragColor = texture(texture2, uv); } else if(mipLevel == 3.0) { - gl_FragColor = texture2D(texture3, uv); + out_FragColor = texture(texture3, uv); } else if(mipLevel == 4.0) { - gl_FragColor = texture2D(texture4, uv); + out_FragColor = texture(texture4, uv); } else if(mipLevel == 5.0) { - gl_FragColor = texture2D(texture5, uv); + out_FragColor = texture(texture5, uv); } else { - gl_FragColor = vec4(0.0); + out_FragColor = vec4(0.0); } } diff --git a/packages/engine/Source/Shaders/OctahedralProjectionFS.glsl b/packages/engine/Source/Shaders/OctahedralProjectionFS.glsl index dca8b7d8236a..ba001b195e80 100644 --- a/packages/engine/Source/Shaders/OctahedralProjectionFS.glsl +++ b/packages/engine/Source/Shaders/OctahedralProjectionFS.glsl @@ -1,14 +1,14 @@ -varying vec3 v_cubeMapCoordinates; +in vec3 v_cubeMapCoordinates; uniform samplerCube cubeMap; void main() { - vec4 rgba = textureCube(cubeMap, v_cubeMapCoordinates); + vec4 rgba = czm_textureCube(cubeMap, v_cubeMapCoordinates); #ifdef RGBA_NORMALIZED - gl_FragColor = vec4(rgba.rgb, 1.0); + out_FragColor = vec4(rgba.rgb, 1.0); #else float m = rgba.a * 16.0; vec3 r = rgba.rgb * m; - gl_FragColor = vec4(r * r, 1.0); + out_FragColor = vec4(r * r, 1.0); #endif } diff --git a/packages/engine/Source/Shaders/OctahedralProjectionVS.glsl b/packages/engine/Source/Shaders/OctahedralProjectionVS.glsl index 67bdbb22a0c6..9c7e6fe669a3 100644 --- a/packages/engine/Source/Shaders/OctahedralProjectionVS.glsl +++ b/packages/engine/Source/Shaders/OctahedralProjectionVS.glsl @@ -1,7 +1,7 @@ -attribute vec4 position; -attribute vec3 cubeMapCoordinates; +in vec4 position; +in vec3 cubeMapCoordinates; -varying vec3 v_cubeMapCoordinates; +out vec3 v_cubeMapCoordinates; void main() { diff --git a/packages/engine/Source/Shaders/PointPrimitiveCollectionFS.glsl b/packages/engine/Source/Shaders/PointPrimitiveCollectionFS.glsl index b7586705435e..69fddf8ba256 100644 --- a/packages/engine/Source/Shaders/PointPrimitiveCollectionFS.glsl +++ b/packages/engine/Source/Shaders/PointPrimitiveCollectionFS.glsl @@ -1,8 +1,8 @@ -varying vec4 v_color; -varying vec4 v_outlineColor; -varying float v_innerPercent; -varying float v_pixelDistance; -varying vec4 v_pickColor; +in vec4 v_color; +in vec4 v_outlineColor; +in float v_innerPercent; +in float v_pixelDistance; +in vec4 v_pickColor; void main() { @@ -38,6 +38,6 @@ void main() #endif #endif - gl_FragColor = czm_gammaCorrect(color); + out_FragColor = czm_gammaCorrect(color); czm_writeLogDepth(); } diff --git a/packages/engine/Source/Shaders/PointPrimitiveCollectionVS.glsl b/packages/engine/Source/Shaders/PointPrimitiveCollectionVS.glsl index 5c5f2a80ae4e..a4028d50ab1c 100644 --- a/packages/engine/Source/Shaders/PointPrimitiveCollectionVS.glsl +++ b/packages/engine/Source/Shaders/PointPrimitiveCollectionVS.glsl @@ -1,17 +1,17 @@ uniform float u_maxTotalPointSize; -attribute vec4 positionHighAndSize; -attribute vec4 positionLowAndOutline; -attribute vec4 compressedAttribute0; // color, outlineColor, pick color -attribute vec4 compressedAttribute1; // show, translucency by distance, some free space -attribute vec4 scaleByDistance; // near, nearScale, far, farScale -attribute vec3 distanceDisplayConditionAndDisableDepth; // near, far, disableDepthTestDistance - -varying vec4 v_color; -varying vec4 v_outlineColor; -varying float v_innerPercent; -varying float v_pixelDistance; -varying vec4 v_pickColor; +in vec4 positionHighAndSize; +in vec4 positionLowAndOutline; +in vec4 compressedAttribute0; // color, outlineColor, pick color +in vec4 compressedAttribute1; // show, translucency by distance, some free space +in vec4 scaleByDistance; // near, nearScale, far, farScale +in vec3 distanceDisplayConditionAndDisableDepth; // near, far, disableDepthTestDistance + +out vec4 v_color; +out vec4 v_outlineColor; +out float v_innerPercent; +out float v_pixelDistance; +out vec4 v_pickColor; const float SHIFT_LEFT8 = 256.0; const float SHIFT_RIGHT8 = 1.0 / 256.0; diff --git a/packages/engine/Source/Shaders/PolylineFS.glsl b/packages/engine/Source/Shaders/PolylineFS.glsl index 4ed0f7931818..0d200c7130ae 100644 --- a/packages/engine/Source/Shaders/PolylineFS.glsl +++ b/packages/engine/Source/Shaders/PolylineFS.glsl @@ -2,7 +2,7 @@ uniform vec4 u_highlightColor; #endif -varying vec2 v_st; +in vec2 v_st; void main() { @@ -16,9 +16,9 @@ void main() materialInput.str = vec3(st, 0.0); czm_material material = czm_getMaterial(materialInput); - gl_FragColor = vec4(material.diffuse + material.emission, material.alpha); + out_FragColor = vec4(material.diffuse + material.emission, material.alpha); #ifdef VECTOR_TILE - gl_FragColor *= u_highlightColor; + out_FragColor *= u_highlightColor; #endif czm_writeLogDepth(); diff --git a/packages/engine/Source/Shaders/PolylineShadowVolumeFS.glsl b/packages/engine/Source/Shaders/PolylineShadowVolumeFS.glsl index b571272aa339..1727d74507dc 100644 --- a/packages/engine/Source/Shaders/PolylineShadowVolumeFS.glsl +++ b/packages/engine/Source/Shaders/PolylineShadowVolumeFS.glsl @@ -1,26 +1,22 @@ -#ifdef GL_EXT_frag_depth -#extension GL_EXT_frag_depth : enable -#endif - -varying vec4 v_startPlaneNormalEcAndHalfWidth; -varying vec4 v_endPlaneNormalEcAndBatchId; -varying vec4 v_rightPlaneEC; // Technically can compute distance for this here -varying vec4 v_endEcAndStartEcX; -varying vec4 v_texcoordNormalizationAndStartEcYZ; +in vec4 v_startPlaneNormalEcAndHalfWidth; +in vec4 v_endPlaneNormalEcAndBatchId; +in vec4 v_rightPlaneEC; // Technically can compute distance for this here +in vec4 v_endEcAndStartEcX; +in vec4 v_texcoordNormalizationAndStartEcYZ; #ifdef PER_INSTANCE_COLOR -varying vec4 v_color; +in vec4 v_color; #endif void main(void) { - float logDepthOrDepth = czm_branchFreeTernary(czm_sceneMode == czm_sceneMode2D, gl_FragCoord.z, czm_unpackDepth(texture2D(czm_globeDepthTexture, gl_FragCoord.xy / czm_viewport.zw))); + float logDepthOrDepth = czm_branchFreeTernary(czm_sceneMode == czm_sceneMode2D, gl_FragCoord.z, czm_unpackDepth(texture(czm_globeDepthTexture, gl_FragCoord.xy / czm_viewport.zw))); vec3 ecStart = vec3(v_endEcAndStartEcX.w, v_texcoordNormalizationAndStartEcYZ.zw); // Discard for sky if (logDepthOrDepth == 0.0) { #ifdef DEBUG_SHOW_VOLUME - gl_FragColor = vec4(1.0, 0.0, 0.0, 0.5); + out_FragColor = vec4(1.0, 0.0, 0.0, 0.5); return; #else // DEBUG_SHOW_VOLUME discard; @@ -40,7 +36,7 @@ void main(void) if (abs(widthwiseDistance) > halfMaxWidth || distanceFromStart < 0.0 || distanceFromEnd < 0.0) { #ifdef DEBUG_SHOW_VOLUME - gl_FragColor = vec4(1.0, 0.0, 0.0, 0.5); + out_FragColor = vec4(1.0, 0.0, 0.0, 0.5); return; #else // DEBUG_SHOW_VOLUME discard; @@ -65,7 +61,7 @@ void main(void) distanceFromEnd = czm_planeDistance(alignedPlaneNormal, -dot(alignedPlaneNormal, v_endEcAndStartEcX.xyz), eyeCoordinate.xyz); #ifdef PER_INSTANCE_COLOR - gl_FragColor = czm_gammaCorrect(v_color); + out_FragColor = czm_gammaCorrect(v_color); #else // PER_INSTANCE_COLOR // Clamp - distance to aligned planes may be negative due to mitering, // so fragment texture coordinate might be out-of-bounds. @@ -80,11 +76,11 @@ void main(void) materialInput.str = vec3(s, t, 0.0); czm_material material = czm_getMaterial(materialInput); - gl_FragColor = vec4(material.diffuse + material.emission, material.alpha); + out_FragColor = vec4(material.diffuse + material.emission, material.alpha); #endif // PER_INSTANCE_COLOR // Premultiply alpha. Required for classification primitives on translucent globe. - gl_FragColor.rgb *= gl_FragColor.a; + out_FragColor.rgb *= out_FragColor.a; czm_writeDepthClamp(); } diff --git a/packages/engine/Source/Shaders/PolylineShadowVolumeMorphFS.glsl b/packages/engine/Source/Shaders/PolylineShadowVolumeMorphFS.glsl index ec3568f98937..e86f61c8cc6c 100644 --- a/packages/engine/Source/Shaders/PolylineShadowVolumeMorphFS.glsl +++ b/packages/engine/Source/Shaders/PolylineShadowVolumeMorphFS.glsl @@ -1,12 +1,12 @@ -varying vec3 v_forwardDirectionEC; -varying vec3 v_texcoordNormalizationAndHalfWidth; -varying float v_batchId; +in vec3 v_forwardDirectionEC; +in vec3 v_texcoordNormalizationAndHalfWidth; +in float v_batchId; #ifdef PER_INSTANCE_COLOR -varying vec4 v_color; +in vec4 v_color; #else -varying vec2 v_alignedPlaneDistances; -varying float v_texcoordT; +in vec2 v_alignedPlaneDistances; +in float v_texcoordT; #endif float rayPlaneDistanceUnsafe(vec3 origin, vec3 direction, vec3 planeNormal, float planeDistance) { @@ -20,7 +20,7 @@ void main(void) eyeCoordinate /= eyeCoordinate.w; #ifdef PER_INSTANCE_COLOR - gl_FragColor = czm_gammaCorrect(v_color); + out_FragColor = czm_gammaCorrect(v_color); #else // PER_INSTANCE_COLOR // Use distances for planes aligned with segment to prevent skew in dashing float distanceFromStart = rayPlaneDistanceUnsafe(eyeCoordinate.xyz, -v_forwardDirectionEC, v_forwardDirectionEC.xyz, v_alignedPlaneDistances.x); @@ -40,6 +40,6 @@ void main(void) materialInput.str = vec3(s, v_texcoordT, 0.0); czm_material material = czm_getMaterial(materialInput); - gl_FragColor = vec4(material.diffuse + material.emission, material.alpha); + out_FragColor = vec4(material.diffuse + material.emission, material.alpha); #endif // PER_INSTANCE_COLOR } diff --git a/packages/engine/Source/Shaders/PolylineShadowVolumeMorphVS.glsl b/packages/engine/Source/Shaders/PolylineShadowVolumeMorphVS.glsl index a2a618919953..ac0614248950 100644 --- a/packages/engine/Source/Shaders/PolylineShadowVolumeMorphVS.glsl +++ b/packages/engine/Source/Shaders/PolylineShadowVolumeMorphVS.glsl @@ -1,35 +1,35 @@ -attribute vec3 position3DHigh; -attribute vec3 position3DLow; +in vec3 position3DHigh; +in vec3 position3DLow; -attribute vec4 startHiAndForwardOffsetX; -attribute vec4 startLoAndForwardOffsetY; -attribute vec4 startNormalAndForwardOffsetZ; -attribute vec4 endNormalAndTextureCoordinateNormalizationX; -attribute vec4 rightNormalAndTextureCoordinateNormalizationY; -attribute vec4 startHiLo2D; -attribute vec4 offsetAndRight2D; -attribute vec4 startEndNormals2D; -attribute vec2 texcoordNormalization2D; +in vec4 startHiAndForwardOffsetX; +in vec4 startLoAndForwardOffsetY; +in vec4 startNormalAndForwardOffsetZ; +in vec4 endNormalAndTextureCoordinateNormalizationX; +in vec4 rightNormalAndTextureCoordinateNormalizationY; +in vec4 startHiLo2D; +in vec4 offsetAndRight2D; +in vec4 startEndNormals2D; +in vec2 texcoordNormalization2D; -attribute float batchId; +in float batchId; -varying vec3 v_forwardDirectionEC; -varying vec3 v_texcoordNormalizationAndHalfWidth; -varying float v_batchId; +out vec3 v_forwardDirectionEC; +out vec3 v_texcoordNormalizationAndHalfWidth; +out float v_batchId; // For materials #ifdef WIDTH_VARYING -varying float v_width; +out float v_width; #endif #ifdef ANGLE_VARYING -varying float v_polylineAngle; +out float v_polylineAngle; #endif #ifdef PER_INSTANCE_COLOR -varying vec4 v_color; +out vec4 v_color; #else -varying vec2 v_alignedPlaneDistances; -varying float v_texcoordT; +out vec2 v_alignedPlaneDistances; +out float v_texcoordT; #endif // Morphing planes using SLERP or NLERP doesn't seem to work, so instead draw the material directly on the shadow volume. diff --git a/packages/engine/Source/Shaders/PolylineShadowVolumeVS.glsl b/packages/engine/Source/Shaders/PolylineShadowVolumeVS.glsl index 61c9f04ed625..831c9562bf80 100644 --- a/packages/engine/Source/Shaders/PolylineShadowVolumeVS.glsl +++ b/packages/engine/Source/Shaders/PolylineShadowVolumeVS.glsl @@ -1,40 +1,40 @@ -attribute vec3 position3DHigh; -attribute vec3 position3DLow; +in vec3 position3DHigh; +in vec3 position3DLow; // In 2D and in 3D, texture coordinate normalization component signs encodes: // * X sign - sidedness relative to right plane // * Y sign - is negative OR magnitude is greater than 1.0 if vertex is on bottom of volume #ifndef COLUMBUS_VIEW_2D -attribute vec4 startHiAndForwardOffsetX; -attribute vec4 startLoAndForwardOffsetY; -attribute vec4 startNormalAndForwardOffsetZ; -attribute vec4 endNormalAndTextureCoordinateNormalizationX; -attribute vec4 rightNormalAndTextureCoordinateNormalizationY; +in vec4 startHiAndForwardOffsetX; +in vec4 startLoAndForwardOffsetY; +in vec4 startNormalAndForwardOffsetZ; +in vec4 endNormalAndTextureCoordinateNormalizationX; +in vec4 rightNormalAndTextureCoordinateNormalizationY; #else -attribute vec4 startHiLo2D; -attribute vec4 offsetAndRight2D; -attribute vec4 startEndNormals2D; -attribute vec2 texcoordNormalization2D; +in vec4 startHiLo2D; +in vec4 offsetAndRight2D; +in vec4 startEndNormals2D; +in vec2 texcoordNormalization2D; #endif -attribute float batchId; +in float batchId; -varying vec4 v_startPlaneNormalEcAndHalfWidth; -varying vec4 v_endPlaneNormalEcAndBatchId; -varying vec4 v_rightPlaneEC; -varying vec4 v_endEcAndStartEcX; -varying vec4 v_texcoordNormalizationAndStartEcYZ; +out vec4 v_startPlaneNormalEcAndHalfWidth; +out vec4 v_endPlaneNormalEcAndBatchId; +out vec4 v_rightPlaneEC; +out vec4 v_endEcAndStartEcX; +out vec4 v_texcoordNormalizationAndStartEcYZ; // For materials #ifdef WIDTH_VARYING -varying float v_width; +out float v_width; #endif #ifdef ANGLE_VARYING -varying float v_polylineAngle; +out float v_polylineAngle; #endif #ifdef PER_INSTANCE_COLOR -varying vec4 v_color; +out vec4 v_color; #endif void main() diff --git a/packages/engine/Source/Shaders/PolylineVS.glsl b/packages/engine/Source/Shaders/PolylineVS.glsl index 5538600e4784..96283f576a94 100644 --- a/packages/engine/Source/Shaders/PolylineVS.glsl +++ b/packages/engine/Source/Shaders/PolylineVS.glsl @@ -1,21 +1,21 @@ -attribute vec3 position3DHigh; -attribute vec3 position3DLow; -attribute vec3 position2DHigh; -attribute vec3 position2DLow; -attribute vec3 prevPosition3DHigh; -attribute vec3 prevPosition3DLow; -attribute vec3 prevPosition2DHigh; -attribute vec3 prevPosition2DLow; -attribute vec3 nextPosition3DHigh; -attribute vec3 nextPosition3DLow; -attribute vec3 nextPosition2DHigh; -attribute vec3 nextPosition2DLow; -attribute vec4 texCoordExpandAndBatchIndex; +in vec3 position3DHigh; +in vec3 position3DLow; +in vec3 position2DHigh; +in vec3 position2DLow; +in vec3 prevPosition3DHigh; +in vec3 prevPosition3DLow; +in vec3 prevPosition2DHigh; +in vec3 prevPosition2DLow; +in vec3 nextPosition3DHigh; +in vec3 nextPosition3DLow; +in vec3 nextPosition2DHigh; +in vec3 nextPosition2DLow; +in vec4 texCoordExpandAndBatchIndex; -varying vec2 v_st; -varying float v_width; -varying vec4 v_pickColor; -varying float v_polylineAngle; +out vec2 v_st; +out float v_width; +out vec4 v_pickColor; +out float v_polylineAngle; void main() { diff --git a/packages/engine/Source/Shaders/PostProcessStages/AcesTonemappingStage.glsl b/packages/engine/Source/Shaders/PostProcessStages/AcesTonemappingStage.glsl index 5fdb1cd2227a..2844ca752f17 100644 --- a/packages/engine/Source/Shaders/PostProcessStages/AcesTonemappingStage.glsl +++ b/packages/engine/Source/Shaders/PostProcessStages/AcesTonemappingStage.glsl @@ -1,6 +1,6 @@ uniform sampler2D colorTexture; -varying vec2 v_textureCoordinates; +in vec2 v_textureCoordinates; #ifdef AUTO_EXPOSURE uniform sampler2D autoExposure; @@ -8,14 +8,14 @@ uniform sampler2D autoExposure; void main() { - vec4 fragmentColor = texture2D(colorTexture, v_textureCoordinates); + vec4 fragmentColor = texture(colorTexture, v_textureCoordinates); vec3 color = fragmentColor.rgb; #ifdef AUTO_EXPOSURE - color /= texture2D(autoExposure, vec2(0.5)).r; + color /= texture(autoExposure, vec2(0.5)).r; #endif color = czm_acesTonemapping(color); color = czm_inverseGamma(color); - gl_FragColor = vec4(color, fragmentColor.a); + out_FragColor = vec4(color, fragmentColor.a); } diff --git a/packages/engine/Source/Shaders/PostProcessStages/AdditiveBlend.glsl b/packages/engine/Source/Shaders/PostProcessStages/AdditiveBlend.glsl index ba1d5fc0a4d1..2cdefa3276ee 100644 --- a/packages/engine/Source/Shaders/PostProcessStages/AdditiveBlend.glsl +++ b/packages/engine/Source/Shaders/PostProcessStages/AdditiveBlend.glsl @@ -4,14 +4,14 @@ uniform sampler2D colorTexture2; uniform vec2 center; uniform float radius; -varying vec2 v_textureCoordinates; +in vec2 v_textureCoordinates; void main() { - vec4 color0 = texture2D(colorTexture, v_textureCoordinates); - vec4 color1 = texture2D(colorTexture2, v_textureCoordinates); + vec4 color0 = texture(colorTexture, v_textureCoordinates); + vec4 color1 = texture(colorTexture2, v_textureCoordinates); float x = length(gl_FragCoord.xy - center) / radius; float t = smoothstep(0.5, 0.8, x); - gl_FragColor = mix(color0 + color1, color1, t); + out_FragColor = mix(color0 + color1, color1, t); } diff --git a/packages/engine/Source/Shaders/PostProcessStages/AmbientOcclusionGenerate.glsl b/packages/engine/Source/Shaders/PostProcessStages/AmbientOcclusionGenerate.glsl index 680bcfe6ed98..d5db2034e6c0 100644 --- a/packages/engine/Source/Shaders/PostProcessStages/AmbientOcclusionGenerate.glsl +++ b/packages/engine/Source/Shaders/PostProcessStages/AmbientOcclusionGenerate.glsl @@ -6,7 +6,7 @@ uniform float lengthCap; uniform float stepSize; uniform float frustumLength; -varying vec2 v_textureCoordinates; +in vec2 v_textureCoordinates; vec4 clipToEye(vec2 uv, float depth) { @@ -42,7 +42,7 @@ void main(void) if (posInCamera.z > frustumLength) { - gl_FragColor = vec4(1.0); + out_FragColor = vec4(1.0); return; } @@ -58,7 +58,7 @@ void main(void) float gapAngle = 90.0 * czm_radiansPerDegree; // RandomNoise - float randomVal = texture2D(randomTexture, v_textureCoordinates).x; + float randomVal = texture(randomTexture, v_textureCoordinates).x; //Loop for each direction for (int i = 0; i < 4; i++) @@ -111,5 +111,5 @@ void main(void) ao /= 4.0; ao = 1.0 - clamp(ao, 0.0, 1.0); ao = pow(ao, intensity); - gl_FragColor = vec4(vec3(ao), 1.0); + out_FragColor = vec4(vec3(ao), 1.0); } diff --git a/packages/engine/Source/Shaders/PostProcessStages/AmbientOcclusionModulate.glsl b/packages/engine/Source/Shaders/PostProcessStages/AmbientOcclusionModulate.glsl index aed428e59b64..694672fc70d9 100644 --- a/packages/engine/Source/Shaders/PostProcessStages/AmbientOcclusionModulate.glsl +++ b/packages/engine/Source/Shaders/PostProcessStages/AmbientOcclusionModulate.glsl @@ -1,11 +1,11 @@ uniform sampler2D colorTexture; uniform sampler2D ambientOcclusionTexture; uniform bool ambientOcclusionOnly; -varying vec2 v_textureCoordinates; +in vec2 v_textureCoordinates; void main(void) { - vec3 color = texture2D(colorTexture, v_textureCoordinates).rgb; - vec3 ao = texture2D(ambientOcclusionTexture, v_textureCoordinates).rgb; - gl_FragColor.rgb = ambientOcclusionOnly ? ao : ao * color; + vec3 color = texture(colorTexture, v_textureCoordinates).rgb; + vec3 ao = texture(ambientOcclusionTexture, v_textureCoordinates).rgb; + out_FragColor.rgb = ambientOcclusionOnly ? ao : ao * color; } diff --git a/packages/engine/Source/Shaders/PostProcessStages/BlackAndWhite.glsl b/packages/engine/Source/Shaders/PostProcessStages/BlackAndWhite.glsl index 01862931fb60..42d51e87d8b7 100644 --- a/packages/engine/Source/Shaders/PostProcessStages/BlackAndWhite.glsl +++ b/packages/engine/Source/Shaders/PostProcessStages/BlackAndWhite.glsl @@ -1,19 +1,19 @@ uniform sampler2D colorTexture; uniform float gradations; -varying vec2 v_textureCoordinates; +in vec2 v_textureCoordinates; void main(void) { - vec3 rgb = texture2D(colorTexture, v_textureCoordinates).rgb; + vec3 rgb = texture(colorTexture, v_textureCoordinates).rgb; #ifdef CZM_SELECTED_FEATURE if (czm_selected()) { - gl_FragColor = vec4(rgb, 1.0); + out_FragColor = vec4(rgb, 1.0); return; } #endif float luminance = czm_luminance(rgb); float darkness = luminance * gradations; darkness = (darkness - fract(darkness)) / gradations; - gl_FragColor = vec4(vec3(darkness), 1.0); + out_FragColor = vec4(vec3(darkness), 1.0); } diff --git a/packages/engine/Source/Shaders/PostProcessStages/BloomComposite.glsl b/packages/engine/Source/Shaders/PostProcessStages/BloomComposite.glsl index de4904ac0bd9..45158b4e7317 100644 --- a/packages/engine/Source/Shaders/PostProcessStages/BloomComposite.glsl +++ b/packages/engine/Source/Shaders/PostProcessStages/BloomComposite.glsl @@ -2,19 +2,19 @@ uniform sampler2D colorTexture; uniform sampler2D bloomTexture; uniform bool glowOnly; -varying vec2 v_textureCoordinates; +in vec2 v_textureCoordinates; void main(void) { - vec4 color = texture2D(colorTexture, v_textureCoordinates); + vec4 color = texture(colorTexture, v_textureCoordinates); #ifdef CZM_SELECTED_FEATURE if (czm_selected()) { - gl_FragColor = color; + out_FragColor = color; return; } #endif - vec4 bloom = texture2D(bloomTexture, v_textureCoordinates); - gl_FragColor = glowOnly ? bloom : bloom + color; + vec4 bloom = texture(bloomTexture, v_textureCoordinates); + out_FragColor = glowOnly ? bloom : bloom + color; } diff --git a/packages/engine/Source/Shaders/PostProcessStages/BrightPass.glsl b/packages/engine/Source/Shaders/PostProcessStages/BrightPass.glsl index a88a4f0d2643..dcf2865e897c 100644 --- a/packages/engine/Source/Shaders/PostProcessStages/BrightPass.glsl +++ b/packages/engine/Source/Shaders/PostProcessStages/BrightPass.glsl @@ -4,7 +4,7 @@ uniform float avgLuminance; uniform float threshold; uniform float offset; -varying vec2 v_textureCoordinates; +in vec2 v_textureCoordinates; float key(float avg) { @@ -17,7 +17,7 @@ float key(float avg) void main() { - vec4 color = texture2D(colorTexture, v_textureCoordinates); + vec4 color = texture(colorTexture, v_textureCoordinates); vec3 xyz = czm_RGBToXYZ(color.rgb); float luminance = xyz.r; @@ -26,5 +26,5 @@ void main() float brightness = brightLum / (offset + brightLum); xyz.r = brightness; - gl_FragColor = vec4(czm_XYZToRGB(xyz), 1.0); + out_FragColor = vec4(czm_XYZToRGB(xyz), 1.0); } diff --git a/packages/engine/Source/Shaders/PostProcessStages/Brightness.glsl b/packages/engine/Source/Shaders/PostProcessStages/Brightness.glsl index 319188ef77f9..4cb5599c2ffe 100644 --- a/packages/engine/Source/Shaders/PostProcessStages/Brightness.glsl +++ b/packages/engine/Source/Shaders/PostProcessStages/Brightness.glsl @@ -1,11 +1,11 @@ uniform sampler2D colorTexture; uniform float brightness; -varying vec2 v_textureCoordinates; +in vec2 v_textureCoordinates; void main(void) { - vec3 rgb = texture2D(colorTexture, v_textureCoordinates).rgb; + vec3 rgb = texture(colorTexture, v_textureCoordinates).rgb; vec3 target = vec3(0.0); - gl_FragColor = vec4(mix(target, rgb, brightness), 1.0); + out_FragColor = vec4(mix(target, rgb, brightness), 1.0); } diff --git a/packages/engine/Source/Shaders/PostProcessStages/CompositeTranslucentClassification.glsl b/packages/engine/Source/Shaders/PostProcessStages/CompositeTranslucentClassification.glsl index cf7ec7cdfbca..12507fbe15e4 100644 --- a/packages/engine/Source/Shaders/PostProcessStages/CompositeTranslucentClassification.glsl +++ b/packages/engine/Source/Shaders/PostProcessStages/CompositeTranslucentClassification.glsl @@ -4,18 +4,18 @@ uniform sampler2D colorTexture; uniform sampler2D u_packedTranslucentDepth; #endif -varying vec2 v_textureCoordinates; +in vec2 v_textureCoordinates; void main() { #ifdef DEBUG_SHOW_DEPTH if (v_textureCoordinates.x < 0.5) { - gl_FragColor.rgb = vec3(czm_unpackDepth(texture2D(u_packedTranslucentDepth, v_textureCoordinates))); - gl_FragColor.a = 1.0; + out_FragColor.rgb = vec3(czm_unpackDepth(texture(u_packedTranslucentDepth, v_textureCoordinates))); + out_FragColor.a = 1.0; } #else - vec4 color = texture2D(colorTexture, v_textureCoordinates); + vec4 color = texture(colorTexture, v_textureCoordinates); #ifdef PICK if (color == vec4(0.0)) @@ -26,6 +26,6 @@ void main() // Reverse premultiplication process to get the correct composited result of the classification primitives color.rgb /= color.a; #endif - gl_FragColor = color; + out_FragColor = color; #endif } diff --git a/packages/engine/Source/Shaders/PostProcessStages/ContrastBias.glsl b/packages/engine/Source/Shaders/PostProcessStages/ContrastBias.glsl index a487516208ff..a6345adf67b3 100644 --- a/packages/engine/Source/Shaders/PostProcessStages/ContrastBias.glsl +++ b/packages/engine/Source/Shaders/PostProcessStages/ContrastBias.glsl @@ -2,16 +2,16 @@ uniform sampler2D colorTexture; uniform float contrast; uniform float brightness; -varying vec2 v_textureCoordinates; +in vec2 v_textureCoordinates; void main(void) { - vec3 sceneColor = texture2D(colorTexture, v_textureCoordinates).xyz; + vec3 sceneColor = texture(colorTexture, v_textureCoordinates).xyz; sceneColor = czm_RGBToHSB(sceneColor); sceneColor.z += brightness; sceneColor = czm_HSBToRGB(sceneColor); float factor = (259.0 * (contrast + 255.0)) / (255.0 * (259.0 - contrast)); sceneColor = factor * (sceneColor - vec3(0.5)) + vec3(0.5); - gl_FragColor = vec4(sceneColor, 1.0); + out_FragColor = vec4(sceneColor, 1.0); } diff --git a/packages/engine/Source/Shaders/PostProcessStages/DepthOfField.glsl b/packages/engine/Source/Shaders/PostProcessStages/DepthOfField.glsl index a9b774dbdacf..6775f910ea8b 100644 --- a/packages/engine/Source/Shaders/PostProcessStages/DepthOfField.glsl +++ b/packages/engine/Source/Shaders/PostProcessStages/DepthOfField.glsl @@ -3,7 +3,7 @@ uniform sampler2D blurTexture; uniform sampler2D depthTexture; uniform float focalDistance; -varying vec2 v_textureCoordinates; +in vec2 v_textureCoordinates; vec4 toEye(vec2 uv, float depth) { @@ -35,5 +35,5 @@ void main(void) float depth = czm_readDepth(depthTexture, v_textureCoordinates); vec4 posInCamera = toEye(v_textureCoordinates, depth); float d = computeDepthBlur(-posInCamera.z); - gl_FragColor = mix(texture2D(colorTexture, v_textureCoordinates), texture2D(blurTexture, v_textureCoordinates), d); + out_FragColor = mix(texture(colorTexture, v_textureCoordinates), texture(blurTexture, v_textureCoordinates), d); } diff --git a/packages/engine/Source/Shaders/PostProcessStages/DepthView.glsl b/packages/engine/Source/Shaders/PostProcessStages/DepthView.glsl index ed2929e8594e..c2a08fa41dae 100644 --- a/packages/engine/Source/Shaders/PostProcessStages/DepthView.glsl +++ b/packages/engine/Source/Shaders/PostProcessStages/DepthView.glsl @@ -1,9 +1,9 @@ uniform sampler2D depthTexture; -varying vec2 v_textureCoordinates; +in vec2 v_textureCoordinates; void main(void) { float depth = czm_readDepth(depthTexture, v_textureCoordinates); - gl_FragColor = vec4(vec3(depth), 1.0); + out_FragColor = vec4(vec3(depth), 1.0); } diff --git a/packages/engine/Source/Shaders/PostProcessStages/DepthViewPacked.glsl b/packages/engine/Source/Shaders/PostProcessStages/DepthViewPacked.glsl index 3f57f4033815..d6c44b190eb3 100644 --- a/packages/engine/Source/Shaders/PostProcessStages/DepthViewPacked.glsl +++ b/packages/engine/Source/Shaders/PostProcessStages/DepthViewPacked.glsl @@ -1,14 +1,14 @@ uniform sampler2D u_depthTexture; -varying vec2 v_textureCoordinates; +in vec2 v_textureCoordinates; void main() { - float z_window = czm_unpackDepth(texture2D(u_depthTexture, v_textureCoordinates)); + float z_window = czm_unpackDepth(texture(u_depthTexture, v_textureCoordinates)); z_window = czm_reverseLogDepth(z_window); float n_range = czm_depthRange.near; float f_range = czm_depthRange.far; float z_ndc = (2.0 * z_window - n_range - f_range) / (f_range - n_range); float scale = pow(z_ndc * 0.5 + 0.5, 8.0); - gl_FragColor = vec4(mix(vec3(0.0), vec3(1.0), scale), 1.0); + out_FragColor = vec4(mix(vec3(0.0), vec3(1.0), scale), 1.0); } diff --git a/packages/engine/Source/Shaders/PostProcessStages/EdgeDetection.glsl b/packages/engine/Source/Shaders/PostProcessStages/EdgeDetection.glsl index 7853a50e0522..ed3206a67e72 100644 --- a/packages/engine/Source/Shaders/PostProcessStages/EdgeDetection.glsl +++ b/packages/engine/Source/Shaders/PostProcessStages/EdgeDetection.glsl @@ -2,7 +2,7 @@ uniform sampler2D depthTexture; uniform float length; uniform vec4 color; -varying vec2 v_textureCoordinates; +in vec2 v_textureCoordinates; void main(void) { @@ -35,7 +35,7 @@ void main(void) } if (!selected) { - gl_FragColor = vec4(color.rgb, 0.0); + out_FragColor = vec4(color.rgb, 0.0); return; } #endif @@ -48,13 +48,13 @@ void main(void) float dir = directions[i]; float scale = scalars[i]; - horizEdge -= texture2D(depthTexture, v_textureCoordinates + vec2(-padx, dir * pady)).x * scale; - horizEdge += texture2D(depthTexture, v_textureCoordinates + vec2(padx, dir * pady)).x * scale; + horizEdge -= texture(depthTexture, v_textureCoordinates + vec2(-padx, dir * pady)).x * scale; + horizEdge += texture(depthTexture, v_textureCoordinates + vec2(padx, dir * pady)).x * scale; - vertEdge -= texture2D(depthTexture, v_textureCoordinates + vec2(dir * padx, -pady)).x * scale; - vertEdge += texture2D(depthTexture, v_textureCoordinates + vec2(dir * padx, pady)).x * scale; + vertEdge -= texture(depthTexture, v_textureCoordinates + vec2(dir * padx, -pady)).x * scale; + vertEdge += texture(depthTexture, v_textureCoordinates + vec2(dir * padx, pady)).x * scale; } float len = sqrt(horizEdge * horizEdge + vertEdge * vertEdge); - gl_FragColor = vec4(color.rgb, len > length ? color.a : 0.0); + out_FragColor = vec4(color.rgb, len > length ? color.a : 0.0); } diff --git a/packages/engine/Source/Shaders/PostProcessStages/FXAA.glsl b/packages/engine/Source/Shaders/PostProcessStages/FXAA.glsl index 52b4b98c39ac..c6026cbf3872 100644 --- a/packages/engine/Source/Shaders/PostProcessStages/FXAA.glsl +++ b/packages/engine/Source/Shaders/PostProcessStages/FXAA.glsl @@ -1,4 +1,4 @@ -varying vec2 v_textureCoordinates; +in vec2 v_textureCoordinates; uniform sampler2D colorTexture; @@ -16,6 +16,6 @@ void main() fxaaQualitySubpix, fxaaQualityEdgeThreshold, fxaaQualityEdgeThresholdMin); - float alpha = texture2D(colorTexture, v_textureCoordinates).a; - gl_FragColor = vec4(color.rgb, alpha); + float alpha = texture(colorTexture, v_textureCoordinates).a; + out_FragColor = vec4(color.rgb, alpha); } diff --git a/packages/engine/Source/Shaders/PostProcessStages/FilmicTonemapping.glsl b/packages/engine/Source/Shaders/PostProcessStages/FilmicTonemapping.glsl index f52206a5d7c2..c226da15727a 100644 --- a/packages/engine/Source/Shaders/PostProcessStages/FilmicTonemapping.glsl +++ b/packages/engine/Source/Shaders/PostProcessStages/FilmicTonemapping.glsl @@ -1,6 +1,6 @@ uniform sampler2D colorTexture; -varying vec2 v_textureCoordinates; +in vec2 v_textureCoordinates; #ifdef AUTO_EXPOSURE uniform sampler2D autoExposure; @@ -11,11 +11,11 @@ uniform sampler2D autoExposure; void main() { - vec4 fragmentColor = texture2D(colorTexture, v_textureCoordinates); + vec4 fragmentColor = texture(colorTexture, v_textureCoordinates); vec3 color = fragmentColor.rgb; #ifdef AUTO_EXPOSURE - float exposure = texture2D(autoExposure, vec2(0.5)).r; + float exposure = texture(autoExposure, vec2(0.5)).r; color /= exposure; #endif @@ -32,5 +32,5 @@ void main() float w = ((white * (A * white + C * B) + D * E) / (white * ( A * white + B) + D * F)) - E / F; c = czm_inverseGamma(c / w); - gl_FragColor = vec4(c, fragmentColor.a); + out_FragColor = vec4(c, fragmentColor.a); } diff --git a/packages/engine/Source/Shaders/PostProcessStages/GaussianBlur1D.glsl b/packages/engine/Source/Shaders/PostProcessStages/GaussianBlur1D.glsl index 43faf0c0be35..82e8a43a26db 100644 --- a/packages/engine/Source/Shaders/PostProcessStages/GaussianBlur1D.glsl +++ b/packages/engine/Source/Shaders/PostProcessStages/GaussianBlur1D.glsl @@ -12,7 +12,7 @@ uniform float stepSize; uniform vec2 step; #endif -varying vec2 v_textureCoordinates; +in vec2 v_textureCoordinates; // Incremental Computation of the Gaussian: // https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch40.html @@ -33,15 +33,15 @@ void main() g.y = exp((-0.5 * delta * delta) / (sigma * sigma)); g.z = g.y * g.y; - vec4 result = texture2D(colorTexture, st) * g.x; + vec4 result = texture(colorTexture, st) * g.x; for (int i = 1; i < SAMPLES; ++i) { g.xy *= g.yz; vec2 offset = float(i) * dir * step; - result += texture2D(colorTexture, st - offset) * g.x; - result += texture2D(colorTexture, st + offset) * g.x; + result += texture(colorTexture, st - offset) * g.x; + result += texture(colorTexture, st + offset) * g.x; } - gl_FragColor = result; + out_FragColor = result; } diff --git a/packages/engine/Source/Shaders/PostProcessStages/LensFlare.glsl b/packages/engine/Source/Shaders/PostProcessStages/LensFlare.glsl index 28259df2c905..b0704a04c8cd 100644 --- a/packages/engine/Source/Shaders/PostProcessStages/LensFlare.glsl +++ b/packages/engine/Source/Shaders/PostProcessStages/LensFlare.glsl @@ -9,7 +9,7 @@ uniform float dirtAmount; uniform float earthRadius; uniform float intensity; -varying vec2 v_textureCoordinates; +in vec2 v_textureCoordinates; // whether it is in space or not // 6500000.0 is empirical value @@ -46,22 +46,22 @@ vec4 textureDistorted(sampler2D tex, vec2 texcoord, vec2 direction, vec3 distort vec3 color; if(isSpace) { - color.r = isInEarth(texcoord + direction * distortion.r, sceneSize) * texture2D(tex, texcoord + direction * distortion.r).r; - color.g = isInEarth(texcoord + direction * distortion.g, sceneSize) * texture2D(tex, texcoord + direction * distortion.g).g; - color.b = isInEarth(texcoord + direction * distortion.b, sceneSize) * texture2D(tex, texcoord + direction * distortion.b).b; + color.r = isInEarth(texcoord + direction * distortion.r, sceneSize) * texture(tex, texcoord + direction * distortion.r).r; + color.g = isInEarth(texcoord + direction * distortion.g, sceneSize) * texture(tex, texcoord + direction * distortion.g).g; + color.b = isInEarth(texcoord + direction * distortion.b, sceneSize) * texture(tex, texcoord + direction * distortion.b).b; } else { - color.r = texture2D(tex, texcoord + direction * distortion.r).r; - color.g = texture2D(tex, texcoord + direction * distortion.g).g; - color.b = texture2D(tex, texcoord + direction * distortion.b).b; + color.r = texture(tex, texcoord + direction * distortion.r).r; + color.g = texture(tex, texcoord + direction * distortion.g).g; + color.b = texture(tex, texcoord + direction * distortion.b).b; } return vec4(clamp(color, 0.0, 1.0), 0.0); } void main(void) { - vec4 originalColor = texture2D(colorTexture, v_textureCoordinates); + vec4 originalColor = texture(colorTexture, v_textureCoordinates); vec3 rgb = originalColor.rgb; bool isSpace = length(czm_viewerPositionWC.xyz) > DISTANCE_TO_SPACE; @@ -76,7 +76,7 @@ void main(void) { // Lens flare is disabled when not in space until #5932 is fixed. // https://github.com/CesiumGS/cesium/issues/5932 - gl_FragColor = originalColor; + out_FragColor = originalColor; return; } @@ -117,7 +117,7 @@ void main(void) { dirtTexCoords.y = mod(floor(dirtTexCoords.y), 2.0) == 1.0 ? 1.0 - fract(dirtTexCoords.y) : fract(dirtTexCoords.y); } - result += dirtAmount * texture2D(dirtTexture, dirtTexCoords); + result += dirtAmount * texture(dirtTexture, dirtTexCoords); // Rotating starburst texture's coordinate // dot(czm_view[0].xyz, vec3(0.0, 0.0, 1.0)) + dot(czm_view[1].xyz, vec3(0.0, 1.0, 0.0)) @@ -144,10 +144,10 @@ void main(void) else { result *= oneMinusWeightForLensFlare * intensity; - result *= texture2D(starTexture, lensStarTexcoord) * pow(weightForLensFlare, 1.0) * max((1.0 - length(vec3(st1.xy, 0.0))), 0.0) * 2.0; + result *= texture(starTexture, lensStarTexcoord) * pow(weightForLensFlare, 1.0) * max((1.0 - length(vec3(st1.xy, 0.0))), 0.0) * 2.0; } - result += texture2D(colorTexture, v_textureCoordinates); + result += texture(colorTexture, v_textureCoordinates); - gl_FragColor = result; + out_FragColor = result; } diff --git a/packages/engine/Source/Shaders/PostProcessStages/ModifiedReinhardTonemapping.glsl b/packages/engine/Source/Shaders/PostProcessStages/ModifiedReinhardTonemapping.glsl index 65d8bc0eaa10..7547560177f5 100644 --- a/packages/engine/Source/Shaders/PostProcessStages/ModifiedReinhardTonemapping.glsl +++ b/packages/engine/Source/Shaders/PostProcessStages/ModifiedReinhardTonemapping.glsl @@ -1,7 +1,7 @@ uniform sampler2D colorTexture; uniform vec3 white; -varying vec2 v_textureCoordinates; +in vec2 v_textureCoordinates; #ifdef AUTO_EXPOSURE uniform sampler2D autoExposure; @@ -12,13 +12,13 @@ uniform sampler2D autoExposure; void main() { - vec4 fragmentColor = texture2D(colorTexture, v_textureCoordinates); + vec4 fragmentColor = texture(colorTexture, v_textureCoordinates); vec3 color = fragmentColor.rgb; #ifdef AUTO_EXPOSURE - float exposure = texture2D(autoExposure, vec2(0.5)).r; + float exposure = texture(autoExposure, vec2(0.5)).r; color /= exposure; #endif color = (color * (1.0 + color / white)) / (1.0 + color); color = czm_inverseGamma(color); - gl_FragColor = vec4(color, fragmentColor.a); + out_FragColor = vec4(color, fragmentColor.a); } diff --git a/packages/engine/Source/Shaders/PostProcessStages/NightVision.glsl b/packages/engine/Source/Shaders/PostProcessStages/NightVision.glsl index 4aa29eaaad6e..da0bd4c2cbf8 100644 --- a/packages/engine/Source/Shaders/PostProcessStages/NightVision.glsl +++ b/packages/engine/Source/Shaders/PostProcessStages/NightVision.glsl @@ -1,6 +1,6 @@ uniform sampler2D colorTexture; -varying vec2 v_textureCoordinates; +in vec2 v_textureCoordinates; float rand(vec2 co) { @@ -10,7 +10,7 @@ float rand(vec2 co) void main(void) { float noiseValue = rand(v_textureCoordinates + sin(czm_frameNumber)) * 0.1; - vec3 rgb = texture2D(colorTexture, v_textureCoordinates).rgb; + vec3 rgb = texture(colorTexture, v_textureCoordinates).rgb; vec3 green = vec3(0.0, 1.0, 0.0); - gl_FragColor = vec4((noiseValue + rgb) * green, 1.0); + out_FragColor = vec4((noiseValue + rgb) * green, 1.0); } diff --git a/packages/engine/Source/Shaders/PostProcessStages/PassThrough.glsl b/packages/engine/Source/Shaders/PostProcessStages/PassThrough.glsl index 2ddd654b3ef4..206cca374b48 100644 --- a/packages/engine/Source/Shaders/PostProcessStages/PassThrough.glsl +++ b/packages/engine/Source/Shaders/PostProcessStages/PassThrough.glsl @@ -1,8 +1,8 @@ uniform sampler2D colorTexture; -varying vec2 v_textureCoordinates; +in vec2 v_textureCoordinates; void main() { - gl_FragColor = texture2D(colorTexture, v_textureCoordinates); + out_FragColor = texture(colorTexture, v_textureCoordinates); } diff --git a/packages/engine/Source/Shaders/PostProcessStages/PassThroughDepth.glsl b/packages/engine/Source/Shaders/PostProcessStages/PassThroughDepth.glsl index e04fce01cdbb..fdcfbeb5aa02 100644 --- a/packages/engine/Source/Shaders/PostProcessStages/PassThroughDepth.glsl +++ b/packages/engine/Source/Shaders/PostProcessStages/PassThroughDepth.glsl @@ -1,8 +1,8 @@ uniform highp sampler2D u_depthTexture; -varying vec2 v_textureCoordinates; +in vec2 v_textureCoordinates; void main() { - gl_FragColor = czm_packDepth(texture2D(u_depthTexture, v_textureCoordinates).r); + out_FragColor = czm_packDepth(texture(u_depthTexture, v_textureCoordinates).r); } diff --git a/packages/engine/Source/Shaders/PostProcessStages/PointCloudEyeDomeLighting.glsl b/packages/engine/Source/Shaders/PostProcessStages/PointCloudEyeDomeLighting.glsl index c82cad4ff47f..11d7255f4bfd 100644 --- a/packages/engine/Source/Shaders/PostProcessStages/PointCloudEyeDomeLighting.glsl +++ b/packages/engine/Source/Shaders/PostProcessStages/PointCloudEyeDomeLighting.glsl @@ -1,9 +1,7 @@ -#extension GL_EXT_frag_depth : enable - uniform sampler2D u_pointCloud_colorGBuffer; uniform sampler2D u_pointCloud_depthGBuffer; uniform vec2 u_distanceAndEdlStrength; -varying vec2 v_textureCoordinates; +in vec2 v_textureCoordinates; vec2 neighborContribution(float log2Depth, vec2 offset) { @@ -12,8 +10,8 @@ vec2 neighborContribution(float log2Depth, vec2 offset) vec2 texCoord0 = v_textureCoordinates + offset * floor(dist); vec2 texCoord1 = v_textureCoordinates + offset * ceil(dist); - float depthOrLogDepth0 = czm_unpackDepth(texture2D(u_pointCloud_depthGBuffer, texCoord0)); - float depthOrLogDepth1 = czm_unpackDepth(texture2D(u_pointCloud_depthGBuffer, texCoord1)); + float depthOrLogDepth0 = czm_unpackDepth(texture(u_pointCloud_depthGBuffer, texCoord0)); + float depthOrLogDepth1 = czm_unpackDepth(texture(u_pointCloud_depthGBuffer, texCoord1)); // ignore depth values that are the clear depth if (depthOrLogDepth0 == 0.0 || depthOrLogDepth1 == 0.0) { @@ -28,7 +26,7 @@ vec2 neighborContribution(float log2Depth, vec2 offset) void main() { - float depthOrLogDepth = czm_unpackDepth(texture2D(u_pointCloud_depthGBuffer, v_textureCoordinates)); + float depthOrLogDepth = czm_unpackDepth(texture(u_pointCloud_depthGBuffer, v_textureCoordinates)); vec4 eyeCoordinate = czm_windowToEyeCoordinates(gl_FragCoord.xy, depthOrLogDepth); eyeCoordinate /= eyeCoordinate.w; @@ -40,7 +38,7 @@ void main() discard; } - vec4 color = texture2D(u_pointCloud_colorGBuffer, v_textureCoordinates); + vec4 color = texture(u_pointCloud_colorGBuffer, v_textureCoordinates); // sample from neighbors left, right, down, up vec2 texelSize = 1.0 / czm_viewport.zw; @@ -56,8 +54,8 @@ void main() float strength = u_distanceAndEdlStrength.y; float shade = exp(-response * 300.0 * strength); color.rgb *= shade; - gl_FragColor = vec4(color); + out_FragColor = vec4(color); // Input and output depth are the same. - gl_FragDepthEXT = depthOrLogDepth; + gl_FragDepth = depthOrLogDepth; } diff --git a/packages/engine/Source/Shaders/PostProcessStages/ReinhardTonemapping.glsl b/packages/engine/Source/Shaders/PostProcessStages/ReinhardTonemapping.glsl index 07bc9c239c6c..582c92e8ec3b 100644 --- a/packages/engine/Source/Shaders/PostProcessStages/ReinhardTonemapping.glsl +++ b/packages/engine/Source/Shaders/PostProcessStages/ReinhardTonemapping.glsl @@ -1,6 +1,6 @@ uniform sampler2D colorTexture; -varying vec2 v_textureCoordinates; +in vec2 v_textureCoordinates; #ifdef AUTO_EXPOSURE uniform sampler2D autoExposure; @@ -11,13 +11,13 @@ uniform sampler2D autoExposure; void main() { - vec4 fragmentColor = texture2D(colorTexture, v_textureCoordinates); + vec4 fragmentColor = texture(colorTexture, v_textureCoordinates); vec3 color = fragmentColor.rgb; #ifdef AUTO_EXPOSURE - float exposure = texture2D(autoExposure, vec2(0.5)).r; + float exposure = texture(autoExposure, vec2(0.5)).r; color /= exposure; #endif color = color / (1.0 + color); color = czm_inverseGamma(color); - gl_FragColor = vec4(color, fragmentColor.a); + out_FragColor = vec4(color, fragmentColor.a); } diff --git a/packages/engine/Source/Shaders/PostProcessStages/Silhouette.glsl b/packages/engine/Source/Shaders/PostProcessStages/Silhouette.glsl index a7abe0337c0f..6832f9c5dfb7 100644 --- a/packages/engine/Source/Shaders/PostProcessStages/Silhouette.glsl +++ b/packages/engine/Source/Shaders/PostProcessStages/Silhouette.glsl @@ -1,11 +1,11 @@ uniform sampler2D colorTexture; uniform sampler2D silhouetteTexture; -varying vec2 v_textureCoordinates; +in vec2 v_textureCoordinates; void main(void) { - vec4 silhouetteColor = texture2D(silhouetteTexture, v_textureCoordinates); - vec4 color = texture2D(colorTexture, v_textureCoordinates); - gl_FragColor = mix(color, silhouetteColor, silhouetteColor.a); + vec4 silhouetteColor = texture(silhouetteTexture, v_textureCoordinates); + vec4 color = texture(colorTexture, v_textureCoordinates); + out_FragColor = mix(color, silhouetteColor, silhouetteColor.a); } diff --git a/packages/engine/Source/Shaders/ReprojectWebMercatorFS.glsl b/packages/engine/Source/Shaders/ReprojectWebMercatorFS.glsl index 58852482c392..065efe3c5cda 100644 --- a/packages/engine/Source/Shaders/ReprojectWebMercatorFS.glsl +++ b/packages/engine/Source/Shaders/ReprojectWebMercatorFS.glsl @@ -1,8 +1,8 @@ uniform sampler2D u_texture; -varying vec2 v_textureCoordinates; +in vec2 v_textureCoordinates; void main() { - gl_FragColor = texture2D(u_texture, v_textureCoordinates); + out_FragColor = texture(u_texture, v_textureCoordinates); } diff --git a/packages/engine/Source/Shaders/ReprojectWebMercatorVS.glsl b/packages/engine/Source/Shaders/ReprojectWebMercatorVS.glsl index 3699fcf618a4..b2a8aed34443 100644 --- a/packages/engine/Source/Shaders/ReprojectWebMercatorVS.glsl +++ b/packages/engine/Source/Shaders/ReprojectWebMercatorVS.glsl @@ -1,9 +1,9 @@ -attribute vec4 position; -attribute float webMercatorT; +in vec4 position; +in float webMercatorT; uniform vec2 u_textureDimensions; -varying vec2 v_textureCoordinates; +out vec2 v_textureCoordinates; void main() { diff --git a/packages/engine/Source/Shaders/ShadowVolumeAppearanceFS.glsl b/packages/engine/Source/Shaders/ShadowVolumeAppearanceFS.glsl index 44f41477e100..a2d6963d0909 100644 --- a/packages/engine/Source/Shaders/ShadowVolumeAppearanceFS.glsl +++ b/packages/engine/Source/Shaders/ShadowVolumeAppearanceFS.glsl @@ -1,22 +1,18 @@ -#ifdef GL_EXT_frag_depth -#extension GL_EXT_frag_depth : enable -#endif - #ifdef TEXTURE_COORDINATES #ifdef SPHERICAL -varying vec4 v_sphericalExtents; +in vec4 v_sphericalExtents; #else // SPHERICAL -varying vec2 v_inversePlaneExtents; -varying vec4 v_westPlane; -varying vec4 v_southPlane; +in vec2 v_inversePlaneExtents; +in vec4 v_westPlane; +in vec4 v_southPlane; #endif // SPHERICAL -varying vec3 v_uvMinAndSphericalLongitudeRotation; -varying vec3 v_uMaxAndInverseDistance; -varying vec3 v_vMaxAndInverseDistance; +in vec3 v_uvMinAndSphericalLongitudeRotation; +in vec3 v_uMaxAndInverseDistance; +in vec3 v_vMaxAndInverseDistance; #endif // TEXTURE_COORDINATES #ifdef PER_INSTANCE_COLOR -varying vec4 v_color; +in vec4 v_color; #endif #ifdef NORMAL_EC @@ -28,8 +24,8 @@ vec3 getEyeCoordinate3FromWindowCoordinate(vec2 fragCoord, float logDepthOrDepth vec3 vectorFromOffset(vec4 eyeCoordinate, vec2 positiveOffset) { vec2 glFragCoordXY = gl_FragCoord.xy; // Sample depths at both offset and negative offset - float upOrRightLogDepth = czm_unpackDepth(texture2D(czm_globeDepthTexture, (glFragCoordXY + positiveOffset) / czm_viewport.zw)); - float downOrLeftLogDepth = czm_unpackDepth(texture2D(czm_globeDepthTexture, (glFragCoordXY - positiveOffset) / czm_viewport.zw)); + float upOrRightLogDepth = czm_unpackDepth(texture(czm_globeDepthTexture, (glFragCoordXY + positiveOffset) / czm_viewport.zw)); + float downOrLeftLogDepth = czm_unpackDepth(texture(czm_globeDepthTexture, (glFragCoordXY - positiveOffset) / czm_viewport.zw)); // Explicitly evaluate both paths // Necessary for multifrustum and for edges of the screen bvec2 upOrRightInBounds = lessThan(glFragCoordXY + positiveOffset, czm_viewport.zw); @@ -44,7 +40,7 @@ vec3 vectorFromOffset(vec4 eyeCoordinate, vec2 positiveOffset) { void main(void) { #ifdef REQUIRES_EC - float logDepthOrDepth = czm_unpackDepth(texture2D(czm_globeDepthTexture, gl_FragCoord.xy / czm_viewport.zw)); + float logDepthOrDepth = czm_unpackDepth(texture(czm_globeDepthTexture, gl_FragCoord.xy / czm_viewport.zw)); vec4 eyeCoordinate = czm_windowToEyeCoordinates(gl_FragCoord.xy, logDepthOrDepth); #endif @@ -76,11 +72,11 @@ void main(void) // being opaque pixels there in another buffer. // Check for logDepthOrDepth != 0.0 to make sure this should be classified. if (0.0 <= uv.x && uv.x <= 1.0 && 0.0 <= uv.y && uv.y <= 1.0 || logDepthOrDepth != 0.0) { - gl_FragColor.a = 1.0; // 0.0 alpha leads to discard from ShaderSource.createPickFragmentShaderSource + out_FragColor.a = 1.0; // 0.0 alpha leads to discard from ShaderSource.createPickFragmentShaderSource czm_writeDepthClamp(); } #else // CULL_FRAGMENTS - gl_FragColor.a = 1.0; + out_FragColor.a = 1.0; #endif // CULL_FRAGMENTS #else // PICK @@ -105,7 +101,7 @@ void main(void) vec4 color = czm_gammaCorrect(v_color); #ifdef FLAT - gl_FragColor = color; + out_FragColor = color; #else // FLAT czm_materialInput materialInput; materialInput.normalEC = normalEC; @@ -114,11 +110,11 @@ void main(void) material.diffuse = color.rgb; material.alpha = color.a; - gl_FragColor = czm_phong(normalize(-eyeCoordinate.xyz), material, czm_lightDirectionEC); + out_FragColor = czm_phong(normalize(-eyeCoordinate.xyz), material, czm_lightDirectionEC); #endif // FLAT // Premultiply alpha. Required for classification primitives on translucent globe. - gl_FragColor.rgb *= gl_FragColor.a; + out_FragColor.rgb *= out_FragColor.a; #else // PER_INSTANCE_COLOR @@ -151,13 +147,13 @@ void main(void) czm_material material = czm_getMaterial(materialInput); #ifdef FLAT - gl_FragColor = vec4(material.diffuse + material.emission, material.alpha); + out_FragColor = vec4(material.diffuse + material.emission, material.alpha); #else // FLAT - gl_FragColor = czm_phong(normalize(-eyeCoordinate.xyz), material, czm_lightDirectionEC); + out_FragColor = czm_phong(normalize(-eyeCoordinate.xyz), material, czm_lightDirectionEC); #endif // FLAT // Premultiply alpha. Required for classification primitives on translucent globe. - gl_FragColor.rgb *= gl_FragColor.a; + out_FragColor.rgb *= out_FragColor.a; #endif // PER_INSTANCE_COLOR czm_writeDepthClamp(); diff --git a/packages/engine/Source/Shaders/ShadowVolumeAppearanceVS.glsl b/packages/engine/Source/Shaders/ShadowVolumeAppearanceVS.glsl index 8938a0447469..a9288f9241ac 100644 --- a/packages/engine/Source/Shaders/ShadowVolumeAppearanceVS.glsl +++ b/packages/engine/Source/Shaders/ShadowVolumeAppearanceVS.glsl @@ -1,28 +1,28 @@ -attribute vec3 position3DHigh; -attribute vec3 position3DLow; -attribute float batchId; +in vec3 position3DHigh; +in vec3 position3DLow; +in float batchId; #ifdef EXTRUDED_GEOMETRY -attribute vec3 extrudeDirection; +in vec3 extrudeDirection; uniform float u_globeMinimumAltitude; #endif // EXTRUDED_GEOMETRY #ifdef PER_INSTANCE_COLOR -varying vec4 v_color; +out vec4 v_color; #endif // PER_INSTANCE_COLOR #ifdef TEXTURE_COORDINATES #ifdef SPHERICAL -varying vec4 v_sphericalExtents; +out vec4 v_sphericalExtents; #else // SPHERICAL -varying vec2 v_inversePlaneExtents; -varying vec4 v_westPlane; -varying vec4 v_southPlane; +out vec2 v_inversePlaneExtents; +out vec4 v_westPlane; +out vec4 v_southPlane; #endif // SPHERICAL -varying vec3 v_uvMinAndSphericalLongitudeRotation; -varying vec3 v_uMaxAndInverseDistance; -varying vec3 v_vMaxAndInverseDistance; +out vec3 v_uvMinAndSphericalLongitudeRotation; +out vec3 v_uMaxAndInverseDistance; +out vec3 v_vMaxAndInverseDistance; #endif // TEXTURE_COORDINATES void main() diff --git a/packages/engine/Source/Shaders/ShadowVolumeFS.glsl b/packages/engine/Source/Shaders/ShadowVolumeFS.glsl index 267d55b6fa87..0e8950ac2492 100644 --- a/packages/engine/Source/Shaders/ShadowVolumeFS.glsl +++ b/packages/engine/Source/Shaders/ShadowVolumeFS.glsl @@ -1,7 +1,3 @@ -#ifdef GL_EXT_frag_depth -#extension GL_EXT_frag_depth : enable -#endif - #ifdef VECTOR_TILE uniform vec4 u_highlightColor; #endif @@ -9,9 +5,9 @@ uniform vec4 u_highlightColor; void main(void) { #ifdef VECTOR_TILE - gl_FragColor = czm_gammaCorrect(u_highlightColor); + out_FragColor = czm_gammaCorrect(u_highlightColor); #else - gl_FragColor = vec4(1.0); + out_FragColor = vec4(1.0); #endif czm_writeDepthClamp(); } diff --git a/packages/engine/Source/Shaders/SkyAtmosphereFS.glsl b/packages/engine/Source/Shaders/SkyAtmosphereFS.glsl index 0d52fa8666bc..d0c67c94d440 100644 --- a/packages/engine/Source/Shaders/SkyAtmosphereFS.glsl +++ b/packages/engine/Source/Shaders/SkyAtmosphereFS.glsl @@ -1,12 +1,12 @@ -varying vec3 v_outerPositionWC; +in vec3 v_outerPositionWC; uniform vec3 u_hsbShift; #ifndef PER_FRAGMENT_ATMOSPHERE -varying vec3 v_mieColor; -varying vec3 v_rayleighColor; -varying float v_opacity; -varying float v_translucent; +in vec3 v_mieColor; +in vec3 v_rayleighColor; +in float v_opacity; +in float v_translucent; #endif void main (void) @@ -60,5 +60,5 @@ void main (void) color.a = mix(color.b, 1.0, color.a) * smoothstep(0.0, 1.0, czm_morphTime); } - gl_FragColor = color; + out_FragColor = color; } diff --git a/packages/engine/Source/Shaders/SkyAtmosphereVS.glsl b/packages/engine/Source/Shaders/SkyAtmosphereVS.glsl index e95e53fd924d..88d0bf59bcf8 100644 --- a/packages/engine/Source/Shaders/SkyAtmosphereVS.glsl +++ b/packages/engine/Source/Shaders/SkyAtmosphereVS.glsl @@ -1,12 +1,12 @@ -attribute vec4 position; +in vec4 position; -varying vec3 v_outerPositionWC; +out vec3 v_outerPositionWC; #ifndef PER_FRAGMENT_ATMOSPHERE -varying vec3 v_mieColor; -varying vec3 v_rayleighColor; -varying float v_opacity; -varying float v_translucent; +out vec3 v_mieColor; +out vec3 v_rayleighColor; +out float v_opacity; +out float v_translucent; #endif void main(void) diff --git a/packages/engine/Source/Shaders/SkyBoxFS.glsl b/packages/engine/Source/Shaders/SkyBoxFS.glsl index d40f8a4e59c7..948340d1a881 100644 --- a/packages/engine/Source/Shaders/SkyBoxFS.glsl +++ b/packages/engine/Source/Shaders/SkyBoxFS.glsl @@ -1,9 +1,9 @@ uniform samplerCube u_cubeMap; -varying vec3 v_texCoord; +in vec3 v_texCoord; void main() { - vec4 color = textureCube(u_cubeMap, normalize(v_texCoord)); - gl_FragColor = vec4(czm_gammaCorrect(color).rgb, czm_morphTime); + vec4 color = czm_textureCube(u_cubeMap, normalize(v_texCoord)); + out_FragColor = vec4(czm_gammaCorrect(color).rgb, czm_morphTime); } diff --git a/packages/engine/Source/Shaders/SkyBoxVS.glsl b/packages/engine/Source/Shaders/SkyBoxVS.glsl index a5cfbcbbf2cb..b883f5112ab3 100644 --- a/packages/engine/Source/Shaders/SkyBoxVS.glsl +++ b/packages/engine/Source/Shaders/SkyBoxVS.glsl @@ -1,6 +1,6 @@ -attribute vec3 position; +in vec3 position; -varying vec3 v_texCoord; +out vec3 v_texCoord; void main() { diff --git a/packages/engine/Source/Shaders/SunFS.glsl b/packages/engine/Source/Shaders/SunFS.glsl index 68abd170627f..1483af53104c 100644 --- a/packages/engine/Source/Shaders/SunFS.glsl +++ b/packages/engine/Source/Shaders/SunFS.glsl @@ -1,9 +1,9 @@ uniform sampler2D u_texture; -varying vec2 v_textureCoordinates; +in vec2 v_textureCoordinates; void main() { - vec4 color = texture2D(u_texture, v_textureCoordinates); - gl_FragColor = czm_gammaCorrect(color); + vec4 color = texture(u_texture, v_textureCoordinates); + out_FragColor = czm_gammaCorrect(color); } diff --git a/packages/engine/Source/Shaders/SunTextureFS.glsl b/packages/engine/Source/Shaders/SunTextureFS.glsl index d211be042ef5..0cc5c7ca7bdb 100644 --- a/packages/engine/Source/Shaders/SunTextureFS.glsl +++ b/packages/engine/Source/Shaders/SunTextureFS.glsl @@ -1,6 +1,6 @@ uniform float u_radiusTS; -varying vec2 v_textureCoordinates; +in vec2 v_textureCoordinates; vec2 rotate(vec2 p, vec2 direction) { @@ -51,5 +51,5 @@ void main() color += clamp(burst, vec4(0.0), vec4(1.0)) * 0.15; - gl_FragColor = clamp(color, vec4(0.0), vec4(1.0)); + out_FragColor = clamp(color, vec4(0.0), vec4(1.0)); } diff --git a/packages/engine/Source/Shaders/SunVS.glsl b/packages/engine/Source/Shaders/SunVS.glsl index f2f2fbc5ee55..72fe50af46ea 100644 --- a/packages/engine/Source/Shaders/SunVS.glsl +++ b/packages/engine/Source/Shaders/SunVS.glsl @@ -1,8 +1,8 @@ -attribute vec2 direction; +in vec2 direction; uniform float u_size; -varying vec2 v_textureCoordinates; +out vec2 v_textureCoordinates; void main() { diff --git a/packages/engine/Source/Shaders/Vector3DTileClampedPolylinesFS.glsl b/packages/engine/Source/Shaders/Vector3DTileClampedPolylinesFS.glsl index 0fa201cbd80e..8b7adfa23ff4 100644 --- a/packages/engine/Source/Shaders/Vector3DTileClampedPolylinesFS.glsl +++ b/packages/engine/Source/Shaders/Vector3DTileClampedPolylinesFS.glsl @@ -1,22 +1,18 @@ -#ifdef GL_EXT_frag_depth -#extension GL_EXT_frag_depth : enable -#endif - -varying vec4 v_startPlaneEC; -varying vec4 v_endPlaneEC; -varying vec4 v_rightPlaneEC; -varying float v_halfWidth; -varying vec3 v_volumeUpEC; +in vec4 v_startPlaneEC; +in vec4 v_endPlaneEC; +in vec4 v_rightPlaneEC; +in float v_halfWidth; +in vec3 v_volumeUpEC; uniform vec4 u_highlightColor; void main() { - float logDepthOrDepth = czm_branchFreeTernary(czm_sceneMode == czm_sceneMode2D, gl_FragCoord.z, czm_unpackDepth(texture2D(czm_globeDepthTexture, gl_FragCoord.xy / czm_viewport.zw))); + float logDepthOrDepth = czm_branchFreeTernary(czm_sceneMode == czm_sceneMode2D, gl_FragCoord.z, czm_unpackDepth(texture(czm_globeDepthTexture, gl_FragCoord.xy / czm_viewport.zw))); // Discard for sky if (logDepthOrDepth == 0.0) { #ifdef DEBUG_SHOW_VOLUME - gl_FragColor = vec4(0.0, 0.0, 1.0, 0.5); + out_FragColor = vec4(0.0, 0.0, 1.0, 0.5); return; #else // DEBUG_SHOW_VOLUME discard; @@ -40,13 +36,13 @@ void main() if (abs(widthwiseDistance) > halfMaxWidth || distanceFromStart < 0.0 || distanceFromEnd < 0.0) { #ifdef DEBUG_SHOW_VOLUME - gl_FragColor = vec4(logDepthOrDepth, 0.0, 0.0, 0.5); + out_FragColor = vec4(logDepthOrDepth, 0.0, 0.0, 0.5); return; #else // DEBUG_SHOW_VOLUME discard; #endif // DEBUG_SHOW_VOLUME } - gl_FragColor = u_highlightColor; + out_FragColor = u_highlightColor; czm_writeDepthClamp(); } diff --git a/packages/engine/Source/Shaders/Vector3DTileClampedPolylinesVS.glsl b/packages/engine/Source/Shaders/Vector3DTileClampedPolylinesVS.glsl index 07668ffbe52a..fb554260fa02 100644 --- a/packages/engine/Source/Shaders/Vector3DTileClampedPolylinesVS.glsl +++ b/packages/engine/Source/Shaders/Vector3DTileClampedPolylinesVS.glsl @@ -1,19 +1,19 @@ -attribute vec3 startEllipsoidNormal; -attribute vec3 endEllipsoidNormal; -attribute vec4 startPositionAndHeight; -attribute vec4 endPositionAndHeight; -attribute vec4 startFaceNormalAndVertexCorner; -attribute vec4 endFaceNormalAndHalfWidth; -attribute float a_batchId; +in vec3 startEllipsoidNormal; +in vec3 endEllipsoidNormal; +in vec4 startPositionAndHeight; +in vec4 endPositionAndHeight; +in vec4 startFaceNormalAndVertexCorner; +in vec4 endFaceNormalAndHalfWidth; +in float a_batchId; uniform mat4 u_modifiedModelView; uniform vec2 u_minimumMaximumVectorHeights; -varying vec4 v_startPlaneEC; -varying vec4 v_endPlaneEC; -varying vec4 v_rightPlaneEC; -varying float v_halfWidth; -varying vec3 v_volumeUpEC; +out vec4 v_startPlaneEC; +out vec4 v_endPlaneEC; +out vec4 v_rightPlaneEC; +out float v_halfWidth; +out vec3 v_volumeUpEC; void main() { diff --git a/packages/engine/Source/Shaders/Vector3DTilePolylinesVS.glsl b/packages/engine/Source/Shaders/Vector3DTilePolylinesVS.glsl index e30c2559ee63..aaade8a1f4e0 100644 --- a/packages/engine/Source/Shaders/Vector3DTilePolylinesVS.glsl +++ b/packages/engine/Source/Shaders/Vector3DTilePolylinesVS.glsl @@ -1,8 +1,8 @@ -attribute vec4 currentPosition; -attribute vec4 previousPosition; -attribute vec4 nextPosition; -attribute vec2 expandAndWidth; -attribute float a_batchId; +in vec4 currentPosition; +in vec4 previousPosition; +in vec4 nextPosition; +in vec2 expandAndWidth; +in float a_batchId; uniform mat4 u_modifiedModelView; diff --git a/packages/engine/Source/Shaders/VectorTileVS.glsl b/packages/engine/Source/Shaders/VectorTileVS.glsl index 179f3dc69be4..94fd476d9753 100644 --- a/packages/engine/Source/Shaders/VectorTileVS.glsl +++ b/packages/engine/Source/Shaders/VectorTileVS.glsl @@ -1,5 +1,5 @@ -attribute vec3 position; -attribute float a_batchId; +in vec3 position; +in float a_batchId; uniform mat4 u_modifiedModelViewProjection; diff --git a/packages/engine/Source/Shaders/ViewportQuadFS.glsl b/packages/engine/Source/Shaders/ViewportQuadFS.glsl index da9be0f30564..3330a7775f39 100644 --- a/packages/engine/Source/Shaders/ViewportQuadFS.glsl +++ b/packages/engine/Source/Shaders/ViewportQuadFS.glsl @@ -1,5 +1,5 @@ -varying vec2 v_textureCoordinates; +in vec2 v_textureCoordinates; void main() { @@ -12,5 +12,5 @@ void main() czm_material material = czm_getMaterial(materialInput); - gl_FragColor = vec4(material.diffuse + material.emission, material.alpha); + out_FragColor = vec4(material.diffuse + material.emission, material.alpha); } diff --git a/packages/engine/Source/Shaders/ViewportQuadVS.glsl b/packages/engine/Source/Shaders/ViewportQuadVS.glsl index 9d4d6690f527..e42d9a48957f 100644 --- a/packages/engine/Source/Shaders/ViewportQuadVS.glsl +++ b/packages/engine/Source/Shaders/ViewportQuadVS.glsl @@ -1,7 +1,7 @@ -attribute vec4 position; -attribute vec2 textureCoordinates; +in vec4 position; +in vec2 textureCoordinates; -varying vec2 v_textureCoordinates; +out vec2 v_textureCoordinates; void main() { diff --git a/packages/engine/Source/Shaders/Voxels/IntersectDepth.glsl b/packages/engine/Source/Shaders/Voxels/IntersectDepth.glsl index 179caf52c038..24a272290320 100644 --- a/packages/engine/Source/Shaders/Voxels/IntersectDepth.glsl +++ b/packages/engine/Source/Shaders/Voxels/IntersectDepth.glsl @@ -8,7 +8,7 @@ uniform mat4 u_transformPositionViewToUv; void intersectDepth(vec2 screenCoord, Ray ray, inout Intersections ix) { - float logDepthOrDepth = czm_unpackDepth(texture2D(czm_globeDepthTexture, screenCoord)); + float logDepthOrDepth = czm_unpackDepth(texture(czm_globeDepthTexture, screenCoord)); if (logDepthOrDepth != 0.0) { // Calculate how far the ray must travel before it hits the depth buffer. vec4 eyeCoordinateDepth = czm_screenToEyeCoordinates(screenCoord, logDepthOrDepth); diff --git a/packages/engine/Source/Shaders/Voxels/Octree.glsl b/packages/engine/Source/Shaders/Voxels/Octree.glsl index a60ca38b8b36..1bf13eab5e03 100644 --- a/packages/engine/Source/Shaders/Voxels/Octree.glsl +++ b/packages/engine/Source/Shaders/Voxels/Octree.glsl @@ -49,7 +49,7 @@ float normU8x2_toFloat(in vec2 value) { } OctreeNodeData getOctreeNodeData(in vec2 octreeUv) { - vec4 texData = texture2D(u_octreeInternalNodeTexture, octreeUv); + vec4 texData = texture(u_octreeInternalNodeTexture, octreeUv); OctreeNodeData data; data.data = normU8x2_toInt(texData.xy); @@ -69,7 +69,7 @@ int getOctreeParentIndex(in int octreeIndex) { int octreeCoordX = intMod(octreeIndex, u_octreeInternalNodeTilesPerRow) * 9; int octreeCoordY = octreeIndex / u_octreeInternalNodeTilesPerRow; vec2 octreeUv = u_octreeInternalNodeTexelSizeUv * vec2(float(octreeCoordX) + 0.5, float(octreeCoordY) + 0.5); - vec4 parentData = texture2D(u_octreeInternalNodeTexture, octreeUv); + vec4 parentData = texture(u_octreeInternalNodeTexture, octreeUv); int parentOctreeIndex = normU8x2_toInt(parentData.xy); return parentOctreeIndex; } @@ -106,8 +106,8 @@ void getOctreeLeafSampleDatas(in OctreeNodeData data, out SampleData sampleData0 vec2 leafUv0 = u_octreeLeafNodeTexelSizeUv * vec2(leafCoordXStart + 0.0, leafCoordY); vec2 leafUv1 = u_octreeLeafNodeTexelSizeUv * vec2(leafCoordXStart + 1.0, leafCoordY); - vec4 leafData0 = texture2D(u_octreeLeafNodeTexture, leafUv0); - vec4 leafData1 = texture2D(u_octreeLeafNodeTexture, leafUv1); + vec4 leafData0 = texture(u_octreeLeafNodeTexture, leafUv0); + vec4 leafData1 = texture(u_octreeLeafNodeTexture, leafUv1); float lerp = normU8x2_toFloat(leafData0.xy); diff --git a/packages/engine/Source/Shaders/Voxels/VoxelFS.glsl b/packages/engine/Source/Shaders/Voxels/VoxelFS.glsl index a02e831cf1d4..e8215e63972c 100644 --- a/packages/engine/Source/Shaders/Voxels/VoxelFS.glsl +++ b/packages/engine/Source/Shaders/Voxels/VoxelFS.glsl @@ -143,8 +143,8 @@ void main() if (colorAccum.a == 0.0) { discard; } - gl_FragColor = u_pickColor; + out_FragColor = u_pickColor; #else - gl_FragColor = colorAccum; + out_FragColor = colorAccum; #endif } diff --git a/packages/engine/Source/Shaders/Voxels/VoxelVS.glsl b/packages/engine/Source/Shaders/Voxels/VoxelVS.glsl index 6c29c959b1c2..e620073edc7c 100644 --- a/packages/engine/Source/Shaders/Voxels/VoxelVS.glsl +++ b/packages/engine/Source/Shaders/Voxels/VoxelVS.glsl @@ -1,4 +1,4 @@ -attribute vec2 position; +in vec2 position; uniform vec4 u_ndcSpaceAxisAlignedBoundingBox; diff --git a/packages/engine/Specs/Renderer/AutomaticUniformSpec.js b/packages/engine/Specs/Renderer/AutomaticUniformSpec.js index 481b263a5b98..1ccb4e45b7e3 100644 --- a/packages/engine/Specs/Renderer/AutomaticUniformSpec.js +++ b/packages/engine/Specs/Renderer/AutomaticUniformSpec.js @@ -84,7 +84,7 @@ describe( it("can declare automatic uniforms", function () { const fs = "void main() { " + - " gl_FragColor = vec4((czm_viewport.x == 0.0) && (czm_viewport.y == 0.0) && (czm_viewport.z == 1.0) && (czm_viewport.w == 1.0)); " + + " out_FragColor = vec4((czm_viewport.x == 0.0) && (czm_viewport.y == 0.0) && (czm_viewport.z == 1.0) && (czm_viewport.w == 1.0)); " + "}"; expect({ context: context, @@ -95,7 +95,7 @@ describe( it("has czm_viewport", function () { const fs = "void main() { " + - " gl_FragColor = vec4((czm_viewport.x == 0.0) && (czm_viewport.y == 0.0) && (czm_viewport.z == 1.0) && (czm_viewport.w == 1.0)); " + + " out_FragColor = vec4((czm_viewport.x == 0.0) && (czm_viewport.y == 0.0) && (czm_viewport.z == 1.0) && (czm_viewport.w == 1.0)); " + "}"; expect({ context: context, @@ -110,7 +110,7 @@ describe( " bool b1 = (czm_viewportOrthographic[0][1] == 0.0) && (czm_viewportOrthographic[1][1] != 0.0) && (czm_viewportOrthographic[2][1] == 0.0) && (czm_viewportOrthographic[3][1] != 0.0); " + " bool b2 = (czm_viewportOrthographic[0][2] == 0.0) && (czm_viewportOrthographic[1][2] == 0.0) && (czm_viewportOrthographic[2][2] != 0.0) && (czm_viewportOrthographic[3][2] != 0.0); " + " bool b3 = (czm_viewportOrthographic[0][3] == 0.0) && (czm_viewportOrthographic[1][3] == 0.0) && (czm_viewportOrthographic[2][3] == 0.0) && (czm_viewportOrthographic[3][3] == 1.0); " + - " gl_FragColor = vec4(b0 && b1 && b2 && b3); " + + " out_FragColor = vec4(b0 && b1 && b2 && b3); " + "}"; expect({ context: context, @@ -125,7 +125,7 @@ describe( " bool b1 = (czm_viewportTransformation[0][1] == 0.0) && (czm_viewportTransformation[1][1] != 0.0) && (czm_viewportTransformation[2][1] == 0.0) && (czm_viewportTransformation[3][1] != 0.0); " + " bool b2 = (czm_viewportTransformation[0][2] == 0.0) && (czm_viewportTransformation[1][2] == 0.0) && (czm_viewportTransformation[2][2] != 0.0) && (czm_viewportTransformation[3][2] != 0.0); " + " bool b3 = (czm_viewportTransformation[0][3] == 0.0) && (czm_viewportTransformation[1][3] == 0.0) && (czm_viewportTransformation[2][3] == 0.0) && (czm_viewportTransformation[3][3] == 1.0); " + - " gl_FragColor = vec4(b0 && b1 && b2 && b3); " + + " out_FragColor = vec4(b0 && b1 && b2 && b3); " + "}"; expect({ context: context, @@ -144,7 +144,7 @@ describe( }); const fs = "void main() { " + - " gl_FragColor = vec4(texture2D(czm_globeDepthTexture, vec2(0.5, 0.5)).r == 1.0);" + + " out_FragColor = vec4(texture(czm_globeDepthTexture, vec2(0.5, 0.5)).r == 1.0);" + "}"; expect({ context: context, @@ -159,7 +159,7 @@ describe( " bool b1 = (czm_model[0][1] == 5.0) && (czm_model[1][1] == 6.0) && (czm_model[2][1] == 7.0) && (czm_model[3][1] == 8.0); " + " bool b2 = (czm_model[0][2] == 9.0) && (czm_model[1][2] == 10.0) && (czm_model[2][2] == 11.0) && (czm_model[3][2] == 12.0); " + " bool b3 = (czm_model[0][3] == 13.0) && (czm_model[1][3] == 14.0) && (czm_model[2][3] == 15.0) && (czm_model[3][3] == 16.0); " + - " gl_FragColor = vec4(b0 && b1 && b2 && b3); " + + " out_FragColor = vec4(b0 && b1 && b2 && b3); " + "}"; const m = new Matrix4( 1.0, @@ -193,7 +193,7 @@ describe( " bool b1 = (czm_inverseModel[0][1] == -1.0) && (czm_inverseModel[1][1] == 0.0) && (czm_inverseModel[2][1] == 0.0) && (czm_inverseModel[3][1] == 1.0); " + " bool b2 = (czm_inverseModel[0][2] == 0.0) && (czm_inverseModel[1][2] == 0.0) && (czm_inverseModel[2][2] == 1.0) && (czm_inverseModel[3][2] == 0.0); " + " bool b3 = (czm_inverseModel[0][3] == 0.0) && (czm_inverseModel[1][3] == 0.0) && (czm_inverseModel[2][3] == 0.0) && (czm_inverseModel[3][3] == 1.0); " + - " gl_FragColor = vec4(b0 && b1 && b2 && b3); " + + " out_FragColor = vec4(b0 && b1 && b2 && b3); " + "}"; const m = new Matrix4( 0.0, @@ -254,7 +254,7 @@ describe( " bool b1 = (czm_view[0][1] == 5.0) && (czm_view[1][1] == 6.0) && (czm_view[2][1] == 7.0) && (czm_view[3][1] == 8.0); " + " bool b2 = (czm_view[0][2] == 9.0) && (czm_view[1][2] == 10.0) && (czm_view[2][2] == 11.0) && (czm_view[3][2] == 12.0); " + " bool b3 = (czm_view[0][3] == 13.0) && (czm_view[1][3] == 14.0) && (czm_view[2][3] == 15.0) && (czm_view[3][3] == 16.0); " + - " gl_FragColor = vec4(b0 && b1 && b2 && b3); " + + " out_FragColor = vec4(b0 && b1 && b2 && b3); " + "}"; expect({ context: context, @@ -296,7 +296,7 @@ describe( " bool b1 = (czm_view3D[0][1] == 5.0) && (czm_view3D[1][1] == 6.0) && (czm_view3D[2][1] == 7.0) && (czm_view3D[3][1] == 8.0); " + " bool b2 = (czm_view3D[0][2] == 9.0) && (czm_view3D[1][2] == 10.0) && (czm_view3D[2][2] == 11.0) && (czm_view3D[3][2] == 12.0); " + " bool b3 = (czm_view3D[0][3] == 13.0) && (czm_view3D[1][3] == 14.0) && (czm_view3D[2][3] == 15.0) && (czm_view3D[3][3] == 16.0); " + - " gl_FragColor = vec4(b0 && b1 && b2 && b3); " + + " out_FragColor = vec4(b0 && b1 && b2 && b3); " + "}"; expect({ context: context, @@ -337,7 +337,7 @@ describe( " bool b0 = (czm_viewRotation[0][0] == 1.0) && (czm_viewRotation[1][0] == 2.0) && (czm_viewRotation[2][0] == 3.0); " + " bool b1 = (czm_viewRotation[0][1] == 5.0) && (czm_viewRotation[1][1] == 6.0) && (czm_viewRotation[2][1] == 7.0); " + " bool b2 = (czm_viewRotation[0][2] == 9.0) && (czm_viewRotation[1][2] == 10.0) && (czm_viewRotation[2][2] == 11.0); " + - " gl_FragColor = vec4(b0 && b1 && b2); " + + " out_FragColor = vec4(b0 && b1 && b2); " + "}"; expect({ context: context, @@ -378,7 +378,7 @@ describe( " bool b0 = (czm_viewRotation3D[0][0] == 1.0) && (czm_viewRotation3D[1][0] == 2.0) && (czm_viewRotation3D[2][0] == 3.0); " + " bool b1 = (czm_viewRotation3D[0][1] == 5.0) && (czm_viewRotation3D[1][1] == 6.0) && (czm_viewRotation3D[2][1] == 7.0); " + " bool b2 = (czm_viewRotation3D[0][2] == 9.0) && (czm_viewRotation3D[1][2] == 10.0) && (czm_viewRotation3D[2][2] == 11.0); " + - " gl_FragColor = vec4(b0 && b1 && b2); " + + " out_FragColor = vec4(b0 && b1 && b2); " + "}"; expect({ context: context, @@ -416,7 +416,7 @@ describe( const fs = "void main() { " + - " gl_FragColor = vec4(" + + " out_FragColor = vec4(" + " (czm_inverseView[0][0] == 0.0) && (czm_inverseView[1][0] == 1.0) && (czm_inverseView[2][0] == 0.0) && (czm_inverseView[3][0] == -8.0) &&" + " (czm_inverseView[0][1] == -1.0) && (czm_inverseView[1][1] == 0.0) && (czm_inverseView[2][1] == 0.0) && (czm_inverseView[3][1] == 7.0) &&" + " (czm_inverseView[0][2] == 0.0) && (czm_inverseView[1][2] == 0.0) && (czm_inverseView[2][2] == 1.0) && (czm_inverseView[3][2] == 0.0)" + @@ -458,7 +458,7 @@ describe( const fs = "void main() { " + - " gl_FragColor = vec4(" + + " out_FragColor = vec4(" + " (czm_inverseView3D[0][0] == 0.0) && (czm_inverseView3D[1][0] == 1.0) && (czm_inverseView3D[2][0] == 0.0) && (czm_inverseView3D[3][0] == -8.0) &&" + " (czm_inverseView3D[0][1] == -1.0) && (czm_inverseView3D[1][1] == 0.0) && (czm_inverseView3D[2][1] == 0.0) && (czm_inverseView3D[3][1] == 7.0) &&" + " (czm_inverseView3D[0][2] == 0.0) && (czm_inverseView3D[1][2] == 0.0) && (czm_inverseView3D[2][2] == 1.0) && (czm_inverseView3D[3][2] == 0.0)" + @@ -500,7 +500,7 @@ describe( const fs = "void main() { " + - " gl_FragColor = vec4(" + + " out_FragColor = vec4(" + " (czm_inverseViewRotation[0][0] == 0.0) && (czm_inverseViewRotation[1][0] == 1.0) && (czm_inverseViewRotation[2][0] == 0.0) && " + " (czm_inverseViewRotation[0][1] == -1.0) && (czm_inverseViewRotation[1][1] == 0.0) && (czm_inverseViewRotation[2][1] == 0.0) && " + " (czm_inverseViewRotation[0][2] == 0.0) && (czm_inverseViewRotation[1][2] == 0.0) && (czm_inverseViewRotation[2][2] == 1.0) " + @@ -542,7 +542,7 @@ describe( const fs = "void main() { " + - " gl_FragColor = vec4(" + + " out_FragColor = vec4(" + " (czm_inverseViewRotation3D[0][0] == 0.0) && (czm_inverseViewRotation3D[1][0] == 1.0) && (czm_inverseViewRotation3D[2][0] == 0.0) && " + " (czm_inverseViewRotation3D[0][1] == -1.0) && (czm_inverseViewRotation3D[1][1] == 0.0) && (czm_inverseViewRotation3D[2][1] == 0.0) && " + " (czm_inverseViewRotation3D[0][2] == 0.0) && (czm_inverseViewRotation3D[1][2] == 0.0) && (czm_inverseViewRotation3D[2][2] == 1.0) " + @@ -589,7 +589,7 @@ describe( " bool b1 = (czm_projection[0][1] == 5.0) && (czm_projection[1][1] == 6.0) && (czm_projection[2][1] == 7.0) && (czm_projection[3][1] == 8.0); " + " bool b2 = (czm_projection[0][2] == 9.0) && (czm_projection[1][2] == 10.0) && (czm_projection[2][2] == 11.0) && (czm_projection[3][2] == 12.0); " + " bool b3 = (czm_projection[0][3] == 13.0) && (czm_projection[1][3] == 14.0) && (czm_projection[2][3] == 15.0) && (czm_projection[3][3] == 16.0); " + - " gl_FragColor = vec4(b0 && b1 && b2 && b3); " + + " out_FragColor = vec4(b0 && b1 && b2 && b3); " + "}"; expect({ context: context, @@ -632,7 +632,7 @@ describe( " bool b1 = (czm_inverseProjection[0][1] == -1.0) && (czm_inverseProjection[1][1] == 0.0) && (czm_inverseProjection[2][1] == 0.0) && (czm_inverseProjection[3][1] == 1.0); " + " bool b2 = (czm_inverseProjection[0][2] == 0.0) && (czm_inverseProjection[1][2] == 0.0) && (czm_inverseProjection[2][2] == 1.0) && (czm_inverseProjection[3][2] == 0.0); " + " bool b3 = (czm_inverseProjection[0][3] == 0.0) && (czm_inverseProjection[1][3] == 0.0) && (czm_inverseProjection[2][3] == 0.0) && (czm_inverseProjection[3][3] == 1.0); " + - " gl_FragColor = vec4(b0 && b1 && b2 && b3); " + + " out_FragColor = vec4(b0 && b1 && b2 && b3); " + "}"; expect({ context: context, @@ -676,7 +676,7 @@ describe( " bool b1 = (czm_inverseProjection[0][1] == 0.0) && (czm_inverseProjection[1][1] == 0.0) && (czm_inverseProjection[2][1] == 0.0) && (czm_inverseProjection[3][1] == 0.0); " + " bool b2 = (czm_inverseProjection[0][2] == 0.0) && (czm_inverseProjection[1][2] == 0.0) && (czm_inverseProjection[2][2] == 0.0) && (czm_inverseProjection[3][2] == 0.0); " + " bool b3 = (czm_inverseProjection[0][3] == 0.0) && (czm_inverseProjection[1][3] == 0.0) && (czm_inverseProjection[2][3] == 0.0) && (czm_inverseProjection[3][3] == 0.0); " + - " gl_FragColor = vec4(b0 && b1 && b2 && b3); " + + " out_FragColor = vec4(b0 && b1 && b2 && b3); " + "}"; expect({ context: context, @@ -723,7 +723,7 @@ describe( " bool b1 = (czm_inverseProjection[0][1] == 0.0) && (czm_inverseProjection[1][1] == 0.0) && (czm_inverseProjection[2][1] == 0.0) && (czm_inverseProjection[3][1] == 0.0); " + " bool b2 = (czm_inverseProjection[0][2] == 0.0) && (czm_inverseProjection[1][2] == 0.0) && (czm_inverseProjection[2][2] == 0.0) && (czm_inverseProjection[3][2] == 0.0); " + " bool b3 = (czm_inverseProjection[0][3] == 0.0) && (czm_inverseProjection[1][3] == 0.0) && (czm_inverseProjection[2][3] == 0.0) && (czm_inverseProjection[3][3] == 0.0); " + - " gl_FragColor = vec4(b0 && b1 && b2 && b3); " + + " out_FragColor = vec4(b0 && b1 && b2 && b3); " + "}"; expect({ context: context, @@ -767,7 +767,7 @@ describe( " bool b1 = (czm_infiniteProjection[0][1] == 5.0) && (czm_infiniteProjection[1][1] == 6.0) && (czm_infiniteProjection[2][1] == 7.0) && (czm_infiniteProjection[3][1] == 8.0); " + " bool b2 = (czm_infiniteProjection[0][2] == 9.0) && (czm_infiniteProjection[1][2] == 10.0) && (czm_infiniteProjection[2][2] == 11.0) && (czm_infiniteProjection[3][2] == 12.0); " + " bool b3 = (czm_infiniteProjection[0][3] == 13.0) && (czm_infiniteProjection[1][3] == 14.0) && (czm_infiniteProjection[2][3] == 15.0) && (czm_infiniteProjection[3][3] == 16.0); " + - " gl_FragColor = vec4(b0 && b1 && b2 && b3); " + + " out_FragColor = vec4(b0 && b1 && b2 && b3); " + "}"; expect({ context: context, @@ -809,7 +809,7 @@ describe( " bool b1 = (czm_modelView[0][1] == 0.0) && (czm_modelView[1][1] == 2.0) && (czm_modelView[2][1] == 0.0) && (czm_modelView[3][1] == 1.0); " + " bool b2 = (czm_modelView[0][2] == 0.0) && (czm_modelView[1][2] == 0.0) && (czm_modelView[2][2] == 2.0) && (czm_modelView[3][2] == 1.0); " + " bool b3 = (czm_modelView[0][3] == 0.0) && (czm_modelView[1][3] == 0.0) && (czm_modelView[2][3] == 0.0) && (czm_modelView[3][3] == 1.0); " + - " gl_FragColor = vec4(b0 && b1 && b2 && b3); " + + " out_FragColor = vec4(b0 && b1 && b2 && b3); " + "}"; const m = new Matrix4( 2.0, @@ -870,7 +870,7 @@ describe( " bool b1 = (czm_modelView3D[0][1] == 0.0) && (czm_modelView3D[1][1] == 2.0) && (czm_modelView3D[2][1] == 0.0) && (czm_modelView3D[3][1] == 1.0); " + " bool b2 = (czm_modelView3D[0][2] == 0.0) && (czm_modelView3D[1][2] == 0.0) && (czm_modelView3D[2][2] == 2.0) && (czm_modelView3D[3][2] == 1.0); " + " bool b3 = (czm_modelView3D[0][3] == 0.0) && (czm_modelView3D[1][3] == 0.0) && (czm_modelView3D[2][3] == 0.0) && (czm_modelView3D[3][3] == 1.0); " + - " gl_FragColor = vec4(b0 && b1 && b2 && b3); " + + " out_FragColor = vec4(b0 && b1 && b2 && b3); " + "}"; const m = new Matrix4( 2.0, @@ -931,7 +931,7 @@ describe( " bool b1 = (czm_modelViewRelativeToEye[0][1] == 0.0) && (czm_modelViewRelativeToEye[1][1] == 2.0) && (czm_modelViewRelativeToEye[2][1] == 0.0) && (czm_modelViewRelativeToEye[3][1] == 0.0); " + " bool b2 = (czm_modelViewRelativeToEye[0][2] == 0.0) && (czm_modelViewRelativeToEye[1][2] == 0.0) && (czm_modelViewRelativeToEye[2][2] == 2.0) && (czm_modelViewRelativeToEye[3][2] == 0.0); " + " bool b3 = (czm_modelViewRelativeToEye[0][3] == 0.0) && (czm_modelViewRelativeToEye[1][3] == 0.0) && (czm_modelViewRelativeToEye[2][3] == 0.0) && (czm_modelViewRelativeToEye[3][3] == 1.0); " + - " gl_FragColor = vec4(b0 && b1 && b2 && b3); " + + " out_FragColor = vec4(b0 && b1 && b2 && b3); " + "}"; const m = new Matrix4( 2.0, @@ -973,7 +973,7 @@ describe( " bool b1 = (czm_inverseModelView[0][1] == -1.0) && (czm_inverseModelView[1][1] == 0.0) && (czm_inverseModelView[2][1] == 0.0) && (czm_inverseModelView[3][1] == 1.0); " + " bool b2 = (czm_inverseModelView[0][2] == 0.0) && (czm_inverseModelView[1][2] == 0.0) && (czm_inverseModelView[2][2] == 1.0) && (czm_inverseModelView[3][2] == 0.0); " + " bool b3 = (czm_inverseModelView[0][3] == 0.0) && (czm_inverseModelView[1][3] == 0.0) && (czm_inverseModelView[2][3] == 0.0) && (czm_inverseModelView[3][3] == 1.0); " + - " gl_FragColor = vec4(b0 && b1 && b2 && b3); " + + " out_FragColor = vec4(b0 && b1 && b2 && b3); " + "}"; const m = new Matrix4( 0.0, @@ -1015,7 +1015,7 @@ describe( " bool b1 = (czm_inverseModelView3D[0][1] == -1.0) && (czm_inverseModelView3D[1][1] == 0.0) && (czm_inverseModelView3D[2][1] == 0.0) && (czm_inverseModelView3D[3][1] == 1.0); " + " bool b2 = (czm_inverseModelView3D[0][2] == 0.0) && (czm_inverseModelView3D[1][2] == 0.0) && (czm_inverseModelView3D[2][2] == 1.0) && (czm_inverseModelView3D[3][2] == 0.0); " + " bool b3 = (czm_inverseModelView3D[0][3] == 0.0) && (czm_inverseModelView3D[1][3] == 0.0) && (czm_inverseModelView3D[2][3] == 0.0) && (czm_inverseModelView3D[3][3] == 1.0); " + - " gl_FragColor = vec4(b0 && b1 && b2 && b3); " + + " out_FragColor = vec4(b0 && b1 && b2 && b3); " + "}"; const m = new Matrix4( 0.0, @@ -1094,7 +1094,7 @@ describe( " bool b1 = (czm_viewProjection[0][1] == 0.0) && (czm_viewProjection[1][1] == 1.0) && (czm_viewProjection[2][1] == 0.0) && (czm_viewProjection[3][1] == 8.0); " + " bool b2 = (czm_viewProjection[0][2] == 0.0) && (czm_viewProjection[1][2] == 0.0) && (czm_viewProjection[2][2] == 1.0) && (czm_viewProjection[3][2] == 9.0); " + " bool b3 = (czm_viewProjection[0][3] == 0.0) && (czm_viewProjection[1][3] == 0.0) && (czm_viewProjection[2][3] == 0.0) && (czm_viewProjection[3][3] == 1.0); " + - " gl_FragColor = vec4(b0 && b1 && b2 && b3); " + + " out_FragColor = vec4(b0 && b1 && b2 && b3); " + "}"; expect({ @@ -1155,7 +1155,7 @@ describe( " bool b1 = (czm_inverseViewProjection[0][1] == 0.0) && (czm_inverseViewProjection[1][1] == 1.0) && (czm_inverseViewProjection[2][1] == 0.0) && (czm_inverseViewProjection[3][1] == -8.0); " + " bool b2 = (czm_inverseViewProjection[0][2] == 0.0) && (czm_inverseViewProjection[1][2] == 0.0) && (czm_inverseViewProjection[2][2] == 1.0) && (czm_inverseViewProjection[3][2] == -9.0); " + " bool b3 = (czm_inverseViewProjection[0][3] == 0.0) && (czm_inverseViewProjection[1][3] == 0.0) && (czm_inverseViewProjection[2][3] == 0.0) && (czm_inverseViewProjection[3][3] == 1.0); " + - " gl_FragColor = vec4(b0 && b1 && b2 && b3); " + + " out_FragColor = vec4(b0 && b1 && b2 && b3); " + "}"; expect({ @@ -1216,7 +1216,7 @@ describe( " bool b1 = (czm_modelViewProjection[0][1] == 0.0) && (czm_modelViewProjection[1][1] == 1.0) && (czm_modelViewProjection[2][1] == 0.0) && (czm_modelViewProjection[3][1] == 8.0); " + " bool b2 = (czm_modelViewProjection[0][2] == 0.0) && (czm_modelViewProjection[1][2] == 0.0) && (czm_modelViewProjection[2][2] == 1.0) && (czm_modelViewProjection[3][2] == 9.0); " + " bool b3 = (czm_modelViewProjection[0][3] == 0.0) && (czm_modelViewProjection[1][3] == 0.0) && (czm_modelViewProjection[2][3] == 0.0) && (czm_modelViewProjection[3][3] == 1.0); " + - " gl_FragColor = vec4(b0 && b1 && b2 && b3); " + + " out_FragColor = vec4(b0 && b1 && b2 && b3); " + "}"; const m = new Matrix4( @@ -1296,7 +1296,7 @@ describe( " bool b1 = (czm_inverseModelViewProjection[0][1] == 0.0) && (czm_inverseModelViewProjection[1][1] == 1.0) && (czm_inverseModelViewProjection[2][1] == 0.0) && (czm_inverseModelViewProjection[3][1] == -8.0); " + " bool b2 = (czm_inverseModelViewProjection[0][2] == 0.0) && (czm_inverseModelViewProjection[1][2] == 0.0) && (czm_inverseModelViewProjection[2][2] == 1.0) && (czm_inverseModelViewProjection[3][2] == -9.0); " + " bool b3 = (czm_inverseModelViewProjection[0][3] == 0.0) && (czm_inverseModelViewProjection[1][3] == 0.0) && (czm_inverseModelViewProjection[2][3] == 0.0) && (czm_inverseModelViewProjection[3][3] == 1.0); " + - " gl_FragColor = vec4(b0 && b1 && b2 && b3); " + + " out_FragColor = vec4(b0 && b1 && b2 && b3); " + "}"; const m = new Matrix4( @@ -1376,7 +1376,7 @@ describe( " bool b1 = (czm_modelViewProjectionRelativeToEye[0][1] == 0.0) && (czm_modelViewProjectionRelativeToEye[1][1] == 1.0) && (czm_modelViewProjectionRelativeToEye[2][1] == 0.0) && (czm_modelViewProjectionRelativeToEye[3][1] == 0.0); " + " bool b2 = (czm_modelViewProjectionRelativeToEye[0][2] == 0.0) && (czm_modelViewProjectionRelativeToEye[1][2] == 0.0) && (czm_modelViewProjectionRelativeToEye[2][2] == 1.0) && (czm_modelViewProjectionRelativeToEye[3][2] == 9.0); " + " bool b3 = (czm_modelViewProjectionRelativeToEye[0][3] == 0.0) && (czm_modelViewProjectionRelativeToEye[1][3] == 0.0) && (czm_modelViewProjectionRelativeToEye[2][3] == 0.0) && (czm_modelViewProjectionRelativeToEye[3][3] == 1.0); " + - " gl_FragColor = vec4(b0 && b1 && b2 && b3); " + + " out_FragColor = vec4(b0 && b1 && b2 && b3); " + "}"; const m = new Matrix4( @@ -1457,7 +1457,7 @@ describe( " bool b1 = (czm_modelViewInfiniteProjection[0][1] == 0.0) && (czm_modelViewInfiniteProjection[1][1] == 1.0) && (czm_modelViewInfiniteProjection[2][1] == 0.0) && (czm_modelViewInfiniteProjection[3][1] == 8.0); " + " bool b2 = (czm_modelViewInfiniteProjection[0][2] == 0.0) && (czm_modelViewInfiniteProjection[1][2] == 0.0) && (czm_modelViewInfiniteProjection[2][2] == 1.0) && (czm_modelViewInfiniteProjection[3][2] == 9.0); " + " bool b3 = (czm_modelViewInfiniteProjection[0][3] == 0.0) && (czm_modelViewInfiniteProjection[1][3] == 0.0) && (czm_modelViewInfiniteProjection[2][3] == 0.0) && (czm_modelViewInfiniteProjection[3][3] == 1.0); " + - " gl_FragColor = vec4(b0 && b1 && b2 && b3); " + + " out_FragColor = vec4(b0 && b1 && b2 && b3); " + "}"; const m = new Matrix4( @@ -1488,7 +1488,7 @@ describe( it("has czm_normal", function () { const fs = "void main() { " + - " gl_FragColor = vec4(" + + " out_FragColor = vec4(" + " (czm_normal[0][0] == 1.0) && (czm_normal[1][0] == 0.0) && (czm_normal[2][0] == 0.0) && " + " (czm_normal[0][1] == 0.0) && (czm_normal[1][1] == 1.0) && (czm_normal[2][1] == 0.0) && " + " (czm_normal[0][2] == 0.0) && (czm_normal[1][2] == 0.0) && (czm_normal[2][2] == 1.0) " + @@ -1522,7 +1522,7 @@ describe( it("has czm_inverseNormal", function () { const fs = "void main() { " + - " gl_FragColor = vec4(" + + " out_FragColor = vec4(" + " (czm_inverseNormal[0][0] == 0.0) && (czm_inverseNormal[1][0] == 1.0) && (czm_inverseNormal[2][0] == 0.0) && " + " (czm_inverseNormal[0][1] == -1.0) && (czm_inverseNormal[1][1] == 0.0) && (czm_inverseNormal[2][1] == 0.0) && " + " (czm_inverseNormal[0][2] == 0.0) && (czm_inverseNormal[1][2] == 0.0) && (czm_inverseNormal[2][2] == 1.0) " + @@ -1556,7 +1556,7 @@ describe( it("has czm_normal3D", function () { const fs = "void main() { " + - " gl_FragColor = vec4(" + + " out_FragColor = vec4(" + " (czm_normal3D[0][0] == 1.0) && (czm_normal3D[1][0] == 0.0) && (czm_normal3D[2][0] == 0.0) && " + " (czm_normal3D[0][1] == 0.0) && (czm_normal3D[1][1] == 1.0) && (czm_normal3D[2][1] == 0.0) && " + " (czm_normal3D[0][2] == 0.0) && (czm_normal3D[1][2] == 0.0) && (czm_normal3D[2][2] == 1.0) " + @@ -1590,7 +1590,7 @@ describe( it("has czm_inverseNormal3D", function () { const fs = "void main() { " + - " gl_FragColor = vec4(" + + " out_FragColor = vec4(" + " (czm_inverseNormal3D[0][0] == 0.0) && (czm_inverseNormal3D[1][0] == 1.0) && (czm_inverseNormal3D[2][0] == 0.0) && " + " (czm_inverseNormal3D[0][1] == -1.0) && (czm_inverseNormal3D[1][1] == 0.0) && (czm_inverseNormal3D[2][1] == 0.0) && " + " (czm_inverseNormal3D[0][2] == 0.0) && (czm_inverseNormal3D[1][2] == 0.0) && (czm_inverseNormal3D[2][2] == 1.0) " + @@ -1638,7 +1638,7 @@ describe( const fs = "void main() { " + " bool b = (czm_encodedCameraPositionMCHigh + czm_encodedCameraPositionMCLow == vec3(-1000.0, 0.0, 100000.0)); " + - " gl_FragColor = vec4(b); " + + " out_FragColor = vec4(b); " + "}"; expect({ @@ -1652,7 +1652,7 @@ describe( us.update(createFrameState(context, createMockCamera())); const fs = - "void main() { gl_FragColor = vec4((czm_entireFrustum.x == 1.0) && (czm_entireFrustum.y == 1000.0)); }"; + "void main() { out_FragColor = vec4((czm_entireFrustum.x == 1.0) && (czm_entireFrustum.y == 1000.0)); }"; expect({ context: context, fragmentShader: fs, @@ -1664,7 +1664,7 @@ describe( us.update(createFrameState(context, createMockCamera())); const fs = - "void main() { gl_FragColor = vec4(equal(czm_frustumPlanes, vec4(2.0, -2.0, -1.0, 1.0))); }"; + "void main() { out_FragColor = vec4(equal(czm_frustumPlanes, vec4(2.0, -2.0, -1.0, 1.0))); }"; expect({ context: context, fragmentShader: fs, @@ -1676,7 +1676,7 @@ describe( us.update(createFrameState(context, createMockCamera())); const fs = - "void main() { gl_FragColor = vec4(czm_sunPositionWC != vec3(0.0)); }"; + "void main() { out_FragColor = vec4(czm_sunPositionWC != vec3(0.0)); }"; expect({ context: context, fragmentShader: fs, @@ -1688,7 +1688,7 @@ describe( us.update(createFrameState(context, createMockCamera())); const fs = - "void main() { gl_FragColor = vec4(czm_sunPositionColumbusView != vec3(0.0)); }"; + "void main() { out_FragColor = vec4(czm_sunPositionColumbusView != vec3(0.0)); }"; expect({ context: context, fragmentShader: fs, @@ -1700,7 +1700,7 @@ describe( us.update(createFrameState(context, createMockCamera())); const fs = - "void main() { gl_FragColor = vec4(czm_sunDirectionEC != vec3(0.0)); }"; + "void main() { out_FragColor = vec4(czm_sunDirectionEC != vec3(0.0)); }"; expect({ context: context, fragmentShader: fs, @@ -1712,7 +1712,7 @@ describe( us.update(createFrameState(context, createMockCamera())); const fs = - "void main() { gl_FragColor = vec4(czm_sunDirectionWC != vec3(0.0)); }"; + "void main() { out_FragColor = vec4(czm_sunDirectionWC != vec3(0.0)); }"; expect({ context: context, fragmentShader: fs, @@ -1724,7 +1724,7 @@ describe( us.update(createFrameState(context, createMockCamera())); const fs = - "void main() { gl_FragColor = vec4(czm_moonDirectionEC != vec3(0.0)); }"; + "void main() { out_FragColor = vec4(czm_moonDirectionEC != vec3(0.0)); }"; expect({ context: context, fragmentShader: fs, @@ -1736,7 +1736,7 @@ describe( us.update(createFrameState(context, createMockCamera())); const fs = - "void main() { gl_FragColor = vec4(czm_viewerPositionWC == vec3(0.0)); }"; + "void main() { out_FragColor = vec4(czm_viewerPositionWC == vec3(0.0)); }"; expect({ context: context, fragmentShader: fs, @@ -1746,7 +1746,7 @@ describe( it("has czm_frameNumber", function () { const fs = "void main() { " + - " gl_FragColor = vec4(czm_frameNumber != 0.0); " + + " out_FragColor = vec4(czm_frameNumber != 0.0); " + "}"; expect({ context: context, @@ -1757,7 +1757,7 @@ describe( it("has czm_morphTime", function () { const fs = "void main() { " + - " gl_FragColor = vec4(czm_morphTime == 1.0); " + // 3D + " out_FragColor = vec4(czm_morphTime == 1.0); " + // 3D "}"; expect({ context: context, @@ -1771,7 +1771,7 @@ describe( const fs = "void main() { " + - " gl_FragColor = vec4(" + + " out_FragColor = vec4(" + " (czm_temeToPseudoFixed[0][0] != 0.0) && (czm_temeToPseudoFixed[1][0] != 0.0) && (czm_temeToPseudoFixed[2][0] == 0.0) && " + " (czm_temeToPseudoFixed[0][1] != 0.0) && (czm_temeToPseudoFixed[1][1] != 0.0) && (czm_temeToPseudoFixed[2][1] == 0.0) && " + " (czm_temeToPseudoFixed[0][2] == 0.0) && (czm_temeToPseudoFixed[1][2] == 0.0) && (czm_temeToPseudoFixed[2][2] == 1.0) " + @@ -1789,7 +1789,7 @@ describe( const fs = "void main() { " + - " gl_FragColor = vec4(czm_pass == czm_passEnvironment);" + + " out_FragColor = vec4(czm_pass == czm_passEnvironment);" + "}"; expect({ context: context, @@ -1803,7 +1803,7 @@ describe( const fs = "void main() { " + - " gl_FragColor = vec4(czm_pass == czm_passCompute);" + + " out_FragColor = vec4(czm_pass == czm_passCompute);" + "}"; expect({ context: context, @@ -1817,7 +1817,7 @@ describe( const fs = "void main() { " + - " gl_FragColor = vec4(czm_pass == czm_passGlobe);" + + " out_FragColor = vec4(czm_pass == czm_passGlobe);" + "}"; expect({ context: context, @@ -1831,7 +1831,7 @@ describe( const fs = "void main() { " + - " gl_FragColor = vec4(czm_pass == czm_passTerrainClassification);" + + " out_FragColor = vec4(czm_pass == czm_passTerrainClassification);" + "}"; expect({ context: context, @@ -1845,7 +1845,7 @@ describe( const fs = "void main() { " + - " gl_FragColor = vec4(czm_pass == czm_passCesium3DTileClassification);" + + " out_FragColor = vec4(czm_pass == czm_passCesium3DTileClassification);" + "}"; expect({ context: context, @@ -1859,7 +1859,7 @@ describe( const fs = "void main() { " + - " gl_FragColor = vec4(czm_pass == czm_passOpaque);" + + " out_FragColor = vec4(czm_pass == czm_passOpaque);" + "}"; expect({ context: context, @@ -1873,7 +1873,7 @@ describe( const fs = "void main() { " + - " gl_FragColor = vec4(czm_pass == czm_passTranslucent);" + + " out_FragColor = vec4(czm_pass == czm_passTranslucent);" + "}"; expect({ context: context, @@ -1887,7 +1887,7 @@ describe( const fs = "void main() { " + - " gl_FragColor = vec4(czm_pass == czm_passOverlay);" + + " out_FragColor = vec4(czm_pass == czm_passOverlay);" + "}"; expect({ context: context, @@ -1898,7 +1898,7 @@ describe( it("has czm_sceneMode", function () { const fs = "void main() { " + - " gl_FragColor = vec4(czm_sceneMode == 3.0); " + // 3D + " out_FragColor = vec4(czm_sceneMode == 3.0); " + // 3D "}"; expect({ context: context, @@ -1909,7 +1909,7 @@ describe( it("has czm_sceneMode2D", function () { const fs = "void main() { " + - " gl_FragColor = vec4(czm_sceneMode2D == 2.0); " + + " out_FragColor = vec4(czm_sceneMode2D == 2.0); " + "}"; expect({ context: context, @@ -1920,7 +1920,7 @@ describe( it("has czm_sceneModeColumbusView", function () { const fs = "void main() { " + - " gl_FragColor = vec4(czm_sceneModeColumbusView == 1.0); " + + " out_FragColor = vec4(czm_sceneModeColumbusView == 1.0); " + "}"; expect({ context: context, @@ -1931,7 +1931,7 @@ describe( it("has czm_sceneMode3D", function () { const fs = "void main() { " + - " gl_FragColor = vec4(czm_sceneMode3D == 3.0); " + + " out_FragColor = vec4(czm_sceneMode3D == 3.0); " + "}"; expect({ context: context, @@ -1942,7 +1942,7 @@ describe( it("has czm_sceneModeMorphing", function () { const fs = "void main() { " + - " gl_FragColor = vec4(czm_sceneModeMorphing == 0.0); " + + " out_FragColor = vec4(czm_sceneModeMorphing == 0.0); " + "}"; expect({ context: context, @@ -1956,7 +1956,7 @@ describe( const fs = "void main() { " + - " gl_FragColor = vec4(czm_eyeHeight == 10.0); " + + " out_FragColor = vec4(czm_eyeHeight == 10.0); " + "}"; expect({ context: context, @@ -1967,7 +1967,7 @@ describe( it("has czm_eyeHeight2D == 0,0 in Scene3D", function () { const fs = "void main() { " + - " gl_FragColor = vec4(czm_eyeHeight2D.x == 0.0, czm_eyeHeight2D.y == 0.0, 1.0, 1.0); " + + " out_FragColor = vec4(czm_eyeHeight2D.x == 0.0, czm_eyeHeight2D.y == 0.0, 1.0, 1.0); " + "}"; expect({ context: context, @@ -1992,7 +1992,7 @@ describe( us.update(frameState); const fs = "void main() { " + - " gl_FragColor = vec4(czm_eyeHeight2D.x == 2.0, czm_eyeHeight2D.y == 4.0, 1.0, 1.0); " + + " out_FragColor = vec4(czm_eyeHeight2D.x == 2.0, czm_eyeHeight2D.y == 4.0, 1.0, 1.0); " + "}"; expect({ context: context, @@ -2003,7 +2003,7 @@ describe( it("has czm_splitPosition", function () { const fs = "void main() { " + - " gl_FragColor = vec4(czm_splitPosition == 0.0); " + + " out_FragColor = vec4(czm_splitPosition == 0.0); " + "}"; expect({ context: context, @@ -2018,7 +2018,7 @@ describe( const fs = "void main() { " + - " gl_FragColor = vec4(czm_backgroundColor.r == 0.0, czm_backgroundColor.g == 0.25, czm_backgroundColor.b == 0.75, czm_backgroundColor.a == 1.0); " + + " out_FragColor = vec4(czm_backgroundColor.r == 0.0, czm_backgroundColor.g == 0.25, czm_backgroundColor.b == 0.75, czm_backgroundColor.a == 1.0); " + "}"; expect({ context: context, @@ -2031,7 +2031,7 @@ describe( context.uniformState.update(frameState); const fs = "void main() {" + - " gl_FragColor = vec4(czm_minimumDisableDepthTestDistance == 0.0);" + + " out_FragColor = vec4(czm_minimumDisableDepthTestDistance == 0.0);" + "}"; expect({ context: context, @@ -2044,7 +2044,7 @@ describe( context.uniformState.update(frameState); let fs = "void main() {" + - " gl_FragColor = vec4(czm_orthographicIn3D == 0.0);" + + " out_FragColor = vec4(czm_orthographicIn3D == 0.0);" + "}"; expect({ context: context, @@ -2058,7 +2058,7 @@ describe( context.uniformState.update(frameState); fs = "void main() {" + - " gl_FragColor = vec4(czm_orthographicIn3D == 1.0);" + + " out_FragColor = vec4(czm_orthographicIn3D == 1.0);" + "}"; expect({ context: context, @@ -2069,7 +2069,7 @@ describe( it("has czm_gamma", function () { context.uniformState.gamma = 1.0; const fs = - "void main() {" + " gl_FragColor = vec4(czm_gamma == 1.0);" + "}"; + "void main() {" + " out_FragColor = vec4(czm_gamma == 1.0);" + "}"; expect({ context: context, fragmentShader: fs, @@ -2084,7 +2084,7 @@ describe( }); us.update(frameState); const fs = - "void main() { gl_FragColor = vec4(czm_lightDirectionEC != vec3(0.0)); }"; + "void main() { out_FragColor = vec4(czm_lightDirectionEC != vec3(0.0)); }"; expect({ context: context, fragmentShader: fs, @@ -2099,7 +2099,7 @@ describe( }); us.update(frameState); const fs = - "void main() { gl_FragColor = vec4(czm_lightDirectionWC == vec3(0.0, 0.0, -1.0)); }"; + "void main() { out_FragColor = vec4(czm_lightDirectionWC == vec3(0.0, 0.0, -1.0)); }"; expect({ context: context, fragmentShader: fs, @@ -2120,7 +2120,7 @@ describe( " bool b0 = czm_lightColor.x == 0.25;" + " bool b1 = czm_lightColor.y == 0.5;" + " bool b2 = czm_lightColor.z == 1.0;" + - " gl_FragColor = vec4(b0 && b1 && b2);" + + " out_FragColor = vec4(b0 && b1 && b2);" + "}"; expect({ context: context, @@ -2142,7 +2142,7 @@ describe( " bool b0 = czm_lightColorHdr.x == 0.5;" + " bool b1 = czm_lightColorHdr.y == 1.0;" + " bool b2 = czm_lightColorHdr.z == 2.0;" + - " gl_FragColor = vec4(b0 && b1 && b2);" + + " out_FragColor = vec4(b0 && b1 && b2);" + "}"; expect({ context: context, @@ -2161,7 +2161,7 @@ describe( " bool b0 = czm_ellipsoidRadii.x == 1.0;" + " bool b1 = czm_ellipsoidRadii.y == 2.0;" + " bool b2 = czm_ellipsoidRadii.z == 3.0;" + - " gl_FragColor = vec4(b0 && b1 && b2);" + + " out_FragColor = vec4(b0 && b1 && b2);" + "}"; expect({ context: context, @@ -2181,7 +2181,7 @@ describe( " bool b0 = roundNumber(czm_ellipsoidInverseRadii.x) == 1.0;" + " bool b1 = roundNumber(czm_ellipsoidInverseRadii.y) == 2.0;" + " bool b2 = roundNumber(czm_ellipsoidInverseRadii.z) == 3.0;" + - " gl_FragColor = vec4(b0 && b1 && b2);" + + " out_FragColor = vec4(b0 && b1 && b2);" + "}"; expect({ context: context, diff --git a/packages/engine/Specs/Renderer/BufferSpec.js b/packages/engine/Specs/Renderer/BufferSpec.js index 41d5e84bfead..18bbbd0cc9bc 100644 --- a/packages/engine/Specs/Renderer/BufferSpec.js +++ b/packages/engine/Specs/Renderer/BufferSpec.js @@ -6,10 +6,10 @@ describe( "Renderer/Buffer", function () { createBufferSpecs({}); - const c = createContext({ requestWebgl1: false }); + const c = createContext({}); // Don't repeat WebGL 1 tests when WebGL 2 is not supported if (c.webgl2) { - createBufferSpecs({ requestWebgl1: false }); + createBufferSpecs({}); } c.destroyForSpecs(); diff --git a/packages/engine/Specs/Renderer/BuiltinFunctionsSpec.js b/packages/engine/Specs/Renderer/BuiltinFunctionsSpec.js index 224c6c1e6fc9..c4457c832e13 100644 --- a/packages/engine/Specs/Renderer/BuiltinFunctionsSpec.js +++ b/packages/engine/Specs/Renderer/BuiltinFunctionsSpec.js @@ -27,7 +27,7 @@ describe( "void main() { " + " mat2 m = mat2(1.0, 2.0, 3.0, 4.0); " + " mat2 mt = mat2(1.0, 3.0, 2.0, 4.0); " + - " gl_FragColor = vec4(czm_transpose(m) == mt); " + + " out_FragColor = vec4(czm_transpose(m) == mt); " + "}"; expect({ @@ -41,7 +41,7 @@ describe( "void main() { " + " mat3 m = mat3(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0); " + " mat3 mt = mat3(1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0); " + - " gl_FragColor = vec4(czm_transpose(m) == mt); " + + " out_FragColor = vec4(czm_transpose(m) == mt); " + "}"; expect({ @@ -55,7 +55,7 @@ describe( "void main() { " + " mat4 m = mat4(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0);" + " mat4 mt = mat4(1.0, 5.0, 9.0, 13.0, 2.0, 6.0, 10.0, 14.0, 3.0, 7.0, 11.0, 15.0, 4.0, 8.0, 12.0, 16.0);" + - " gl_FragColor = vec4(czm_transpose(m) == mt); " + + " out_FragColor = vec4(czm_transpose(m) == mt); " + "}"; expect({ @@ -84,7 +84,7 @@ describe( " vec2 fragCoord = vec2(0.0, 0.0);" + " vec4 actual = czm_eyeToWindowCoordinates(pointEC);" + " vec2 diff = actual.xy - fragCoord;" + - " gl_FragColor = vec4(all(lessThan(diff, vec2(czm_epsilon6))));" + + " out_FragColor = vec4(all(lessThan(diff, vec2(czm_epsilon6))));" + "}"; expect({ @@ -113,7 +113,7 @@ describe( " vec4 fragCoord = vec4(0.0, 0.0, 0.0, -z);" + " vec4 actual = czm_windowToEyeCoordinates(fragCoord);" + " vec3 diff = actual.xyz - pointEC;" + - " gl_FragColor = vec4(all(lessThan(diff, vec3(czm_epsilon6))));" + + " out_FragColor = vec4(all(lessThan(diff, vec3(czm_epsilon6))));" + "}"; expect({ @@ -129,7 +129,7 @@ describe( " vec3 pointEC = vec3(x, y, z);" + " vec4 actual = czm_windowToEyeCoordinates(vec2(0.0, 0.0), 0.0);" + " vec3 diff = actual.xyz - pointEC;" + - " gl_FragColor = vec4(all(lessThan(diff, vec3(czm_epsilon6))));" + + " out_FragColor = vec4(all(lessThan(diff, vec3(czm_epsilon6))));" + "}"; expect({ @@ -145,7 +145,7 @@ describe( " vec3 point = vec3(1.0, 0.0, 0.0); " + " float expected = 1.0; " + " float actual = czm_planeDistance(plane, point); " + - " gl_FragColor = vec4(actual == expected); " + + " out_FragColor = vec4(actual == expected); " + "}"; expect({ context: context, @@ -158,7 +158,7 @@ describe( " vec3 point = vec3(1.0, 0.0, 0.0); " + " float expected = 1.0; " + " float actual = czm_planeDistance(plane.xyz, plane.w, point); " + - " gl_FragColor = vec4(actual == expected); " + + " out_FragColor = vec4(actual == expected); " + "}"; expect({ context: context, @@ -174,7 +174,7 @@ describe( " vec2 point = vec2(0.5, 1.0); " + " float expected = 1.0; " + " float actual = czm_lineDistance(point1, point2, point); " + - " gl_FragColor = vec4(actual == expected); " + + " out_FragColor = vec4(actual == expected); " + "}"; expect({ context: context, @@ -190,7 +190,7 @@ describe( " vec3 normal = vec3(0.0, 0.0, 1.0); " + " mat3 expected = mat3(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0); " + " mat3 actual = czm_tangentToEyeSpaceMatrix(normal, tangent, bitangent); " + - " gl_FragColor = vec4(actual == expected); " + + " out_FragColor = vec4(actual == expected); " + "}"; expect({ context: context, @@ -221,7 +221,7 @@ describe( "uniform vec3 u_low;" + "void main() { " + " vec4 p = czm_translateRelativeToEye(u_high, u_low);" + - " gl_FragColor = vec4(p == vec4(5.0, 3.0, 1.0, 1.0)); " + + " out_FragColor = vec4(p == vec4(5.0, 3.0, 1.0, 1.0)); " + "}"; expect({ @@ -237,7 +237,7 @@ describe( " vec4 color0 = vec4(1.0, 0.0, 0.0, 1.0);" + " vec4 color1 = vec4(0.0, 1.0, 0.0, 1.0);" + " vec4 result = czm_antialias(color0, color1, color1, 0.5);" + - " gl_FragColor = vec4(result == color1);" + + " out_FragColor = vec4(result == color1);" + "}"; expect({ context: context, @@ -248,7 +248,7 @@ describe( it("czm_pointAlongRay: point at ray origin", function () { const fs = "void main() { " + - " gl_FragColor = vec4(czm_pointAlongRay(czm_ray(vec3(0.0), vec3(1.0, 0.0, 0.0)), 0.0) == vec3(0.0)); " + + " out_FragColor = vec4(czm_pointAlongRay(czm_ray(vec3(0.0), vec3(1.0, 0.0, 0.0)), 0.0) == vec3(0.0)); " + "}"; expect({ context: context, @@ -259,7 +259,7 @@ describe( it("czm_pointAlongRay: point in front of ray origin", function () { const fs = "void main() { " + - " gl_FragColor = vec4(czm_pointAlongRay(czm_ray(vec3(0.0), vec3(1.0, 0.0, 0.0)), 2.0) == vec3(2.0, 0.0, 0.0)); " + + " out_FragColor = vec4(czm_pointAlongRay(czm_ray(vec3(0.0), vec3(1.0, 0.0, 0.0)), 2.0) == vec3(2.0, 0.0, 0.0)); " + "}"; expect({ context: context, @@ -270,7 +270,7 @@ describe( it("czm_pointAlongRay: point behind ray origin", function () { const fs = "void main() { " + - " gl_FragColor = vec4(czm_pointAlongRay(czm_ray(vec3(0.0), vec3(0.0, 1.0, 0.0)), -2.0) == vec3(0.0, -2.0, 0.0)); " + + " out_FragColor = vec4(czm_pointAlongRay(czm_ray(vec3(0.0), vec3(0.0, 1.0, 0.0)), -2.0) == vec3(0.0, -2.0, 0.0)); " + "}"; expect({ context: context, @@ -281,7 +281,7 @@ describe( it("has czm_octDecode(vec2)", function () { const fs = "void main() { " + - " gl_FragColor = vec4(all(lessThanEqual(abs(czm_octDecode(vec2(128.0, 128.0)) - vec3(0.0, 0.0, 1.0)), vec3(0.01)))); " + + " out_FragColor = vec4(all(lessThanEqual(abs(czm_octDecode(vec2(128.0, 128.0)) - vec3(0.0, 0.0, 1.0)), vec3(0.01)))); " + "}"; expect({ context: context, @@ -292,7 +292,7 @@ describe( it("has czm_octDecode(float)", function () { const fs = "void main() { " + - " gl_FragColor = vec4(all(lessThanEqual(abs(czm_octDecode(32896.0) - vec3(0.0, 0.0, 1.0)), vec3(0.01)))); " + + " out_FragColor = vec4(all(lessThanEqual(abs(czm_octDecode(32896.0) - vec3(0.0, 0.0, 1.0)), vec3(0.01)))); " + "}"; expect({ context: context, @@ -308,7 +308,7 @@ describe( " bool decoded = all(lessThanEqual(abs(a - vec3(1.0, 0.0, 0.0)), vec3(0.01)));" + " decoded = decoded && all(lessThanEqual(abs(b - vec3(0.0, 1.0, 0.0)), vec3(0.01)));" + " decoded = decoded && all(lessThanEqual(abs(c - vec3(0.0, 0.0, 1.0)), vec3(0.01)));" + - " gl_FragColor = vec4(decoded);" + + " out_FragColor = vec4(decoded);" + "}"; expect({ context: context, @@ -321,7 +321,7 @@ describe( "void main() { " + " vec2 coords = czm_decompressTextureCoordinates(8386559.0); " + " vec2 expected = vec2(0.4998779, 0.4998779);" + - " gl_FragColor = vec4(all(lessThanEqual(abs(coords - expected), vec2(0.00000005)))); " + + " out_FragColor = vec4(all(lessThanEqual(abs(coords - expected), vec2(0.00000005)))); " + "}"; expect({ context: context, @@ -332,7 +332,7 @@ describe( it("has signNotZero : float", function () { const fs = "void main() { " + - " gl_FragColor = vec4(czm_signNotZero(0.0) == 1.0, " + + " out_FragColor = vec4(czm_signNotZero(0.0) == 1.0, " + " czm_signNotZero(5.0) == 1.0, " + " czm_signNotZero(-5.0) == -1.0, 1.0); " + "}"; @@ -345,7 +345,7 @@ describe( it("has signNotZero : vec2", function () { const fs = "void main() { " + - " gl_FragColor = vec4(czm_signNotZero(vec2(0.0, 0.0)) == vec2(1.0, 1.0), " + + " out_FragColor = vec4(czm_signNotZero(vec2(0.0, 0.0)) == vec2(1.0, 1.0), " + " czm_signNotZero(vec2(1.0, 1.0)) == vec2(1.0, 1.0), " + " czm_signNotZero(vec2(-1.0, -1.0)) == vec2(-1.0, -1.0), " + " czm_signNotZero(vec2(-1.0, 0.0)) == vec2(-1.0, 1.0)); " + @@ -359,7 +359,7 @@ describe( it("has signNotZero : vec3", function () { const fs = "void main() { " + - " gl_FragColor = vec4(czm_signNotZero(vec3(0.0, 0.0, 0.0)) == vec3(1.0, 1.0, 1.0), " + + " out_FragColor = vec4(czm_signNotZero(vec3(0.0, 0.0, 0.0)) == vec3(1.0, 1.0, 1.0), " + " czm_signNotZero(vec3(1.0, 1.0, 1.0)) == vec3(1.0, 1.0, 1.0), " + " czm_signNotZero(vec3(-1.0, -1.0, -1.0)) == vec3(-1.0, -1.0, -1.0), " + " czm_signNotZero(vec3(-1.0, 0.0, 1.0)) == vec3(-1.0, 1.0, 1.0)); " + @@ -373,7 +373,7 @@ describe( it("has signNotZero : vec4", function () { const fs = "void main() { " + - " gl_FragColor = vec4(czm_signNotZero(vec4(0.0, 0.0, 0.0, 0.0)) == vec4(1.0), " + + " out_FragColor = vec4(czm_signNotZero(vec4(0.0, 0.0, 0.0, 0.0)) == vec4(1.0), " + " czm_signNotZero(vec4(1.0, 1.0, 1.0, 1.0)) == vec4(1.0), " + " czm_signNotZero(vec4(-1.0, -1.0, -1.0, -1.0)) == vec4(-1.0), " + " czm_signNotZero(vec4(-1.0, 0.0, 1.0, -10.0)) == vec4(-1.0, 1.0, 1.0, -1.0)); " + @@ -390,7 +390,7 @@ describe( " return ((value < max) && (value > min)); " + "}" + "void main() { " + - " gl_FragColor = vec4(isBounded(czm_cosineAndSine(czm_piOverFour).x, 0.707106, 0.707107) && isBounded(czm_cosineAndSine(czm_piOverFour).y, 0.707106, 0.707107), " + + " out_FragColor = vec4(isBounded(czm_cosineAndSine(czm_piOverFour).x, 0.707106, 0.707107) && isBounded(czm_cosineAndSine(czm_piOverFour).y, 0.707106, 0.707107), " + " isBounded(czm_cosineAndSine(czm_pi - czm_piOverFour).x, -0.707107, -0.707106) && isBounded(czm_cosineAndSine(czm_pi - czm_piOverFour).y, 0.707106, 0.707107), " + " isBounded(czm_cosineAndSine(-czm_piOverFour).x, 0.707106, 0.707107) && isBounded(czm_cosineAndSine(-czm_piOverFour).y, -0.707107, -0.707106), " + " isBounded(czm_cosineAndSine(-czm_pi + czm_piOverFour).x, -0.707107, -0.707106) && isBounded(czm_cosineAndSine(-czm_pi + czm_piOverFour).y, -0.707107, -0.707106)); " + @@ -405,7 +405,7 @@ describe( const fs = "vec4 testNearFarScalar = vec4(10.0, 1.0, 20.0, 0.0);" + "void main() { " + - " gl_FragColor = vec4(czm_nearFarScalar(testNearFarScalar, 5.0 * 5.0) == 1.0, " + + " out_FragColor = vec4(czm_nearFarScalar(testNearFarScalar, 5.0 * 5.0) == 1.0, " + " czm_nearFarScalar(testNearFarScalar, 10.0 * 10.0) == 1.0, " + " czm_nearFarScalar(testNearFarScalar, 20.0 * 20.0) == 0.0, " + " czm_nearFarScalar(testNearFarScalar, 50.0 * 50.0) == 0.0); " + @@ -419,7 +419,7 @@ describe( it("has czm_cascadeColor", function () { const fs = "void main() { " + - " gl_FragColor = vec4(all(equal(czm_cascadeColor(vec4(0.5)), vec4(1.0, 0.5, 1.0, 2.0))));" + + " out_FragColor = vec4(all(equal(czm_cascadeColor(vec4(0.5)), vec4(1.0, 0.5, 1.0, 2.0))));" + "}"; expect({ context: context, @@ -430,7 +430,7 @@ describe( it("has czm_approximateSphericalCoordinates", function () { const fs = "void main() { " + - " gl_FragColor = vec4(all(equal(czm_approximateSphericalCoordinates(vec3(1.0, 0.0, 0.0)), vec2(0.0, 0.0))));" + + " out_FragColor = vec4(all(equal(czm_approximateSphericalCoordinates(vec3(1.0, 0.0, 0.0)), vec2(0.0, 0.0))));" + "}"; expect({ context: context, @@ -445,7 +445,7 @@ describe( " 0.0, 0.5, 0.0, 0.0," + " 0.0, 0.0, 0.5, 0.0," + " 0.0, 0.0, 0.0, 1.0);" + - " gl_FragColor = vec4(all(equal(czm_transformPlane(vec4(1.0, 0.0, 0.0, 10.0), uniformScale2), vec4(1.0, 0.0, 0.0, 20.0))));" + + " out_FragColor = vec4(all(equal(czm_transformPlane(vec4(1.0, 0.0, 0.0, 10.0), uniformScale2), vec4(1.0, 0.0, 0.0, 20.0))));" + "}"; expect({ context: context, @@ -459,7 +459,7 @@ describe( const vec4 = `vec4(${packed.x}, ${packed.y}, ${packed.z}, ${packed.w})`; const fs = `${ - "void main() { " + " gl_FragColor = vec4(czm_unpackFloat(" + "void main() { " + " out_FragColor = vec4(czm_unpackFloat(" }${vec4}));` + `}`; expect({ context: context, @@ -470,7 +470,7 @@ describe( it("has czm_branchFreeTernary", function () { let fs = "void main() { " + - " gl_FragColor = vec4(czm_branchFreeTernary(true, 1.0, 0.0));" + + " out_FragColor = vec4(czm_branchFreeTernary(true, 1.0, 0.0));" + "}"; expect({ context: context, @@ -479,7 +479,7 @@ describe( fs = "void main() { " + - " gl_FragColor = vec4(czm_branchFreeTernary(true, vec2(1.0), vec2(0.0)), 1.0, 1.0);" + + " out_FragColor = vec4(czm_branchFreeTernary(true, vec2(1.0), vec2(0.0)), 1.0, 1.0);" + "}"; expect({ context: context, @@ -488,7 +488,7 @@ describe( fs = "void main() { " + - " gl_FragColor = vec4(czm_branchFreeTernary(true, vec3(1.0), vec3(0.0)), 1.0);" + + " out_FragColor = vec4(czm_branchFreeTernary(true, vec3(1.0), vec3(0.0)), 1.0);" + "}"; expect({ context: context, @@ -497,7 +497,7 @@ describe( fs = "void main() { " + - " gl_FragColor = czm_branchFreeTernary(true, vec4(1.0), vec4(0.0));" + + " out_FragColor = czm_branchFreeTernary(true, vec4(1.0), vec4(0.0));" + "}"; expect({ context: context, @@ -508,7 +508,7 @@ describe( it("has czm_fastApproximateAtan", function () { const fsAtan = "void main() { " + - " gl_FragColor = vec4(czm_fastApproximateAtan(0.0) == 0.0);" + + " out_FragColor = vec4(czm_fastApproximateAtan(0.0) == 0.0);" + "}"; expect({ context: context, @@ -517,7 +517,7 @@ describe( const fsAtan2 = "void main() { " + - " gl_FragColor = vec4(czm_fastApproximateAtan(1.0, 0.0) == 0.0);" + + " out_FragColor = vec4(czm_fastApproximateAtan(1.0, 0.0) == 0.0);" + "}"; expect({ context: context, diff --git a/packages/engine/Specs/Renderer/ComputeCommandSpec.js b/packages/engine/Specs/Renderer/ComputeCommandSpec.js index f501f9767513..b164a2ed2dfc 100644 --- a/packages/engine/Specs/Renderer/ComputeCommandSpec.js +++ b/packages/engine/Specs/Renderer/ComputeCommandSpec.js @@ -58,7 +58,7 @@ describe( it("throws if no output texture is provided", function () { const computeCommand = new ComputeCommand({ - fragmentShaderSource: "void main() { gl_FragColor = vec4(1.0); }", + fragmentShaderSource: "void main() { out_FragColor = vec4(1.0); }", }); scene.primitives.add(new CommandMockPrimitive(computeCommand)); @@ -69,8 +69,8 @@ describe( it("renderer resources are preserved or destroyed based on the persists flag", function () { const vertexShader = - "attribute vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; - const fragmentShader = "void main() { gl_FragColor = vec4(1.0); }"; + "in vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; + const fragmentShader = "void main() { out_FragColor = vec4(1.0); }"; const shaderProgram = ShaderProgram.fromCache({ context: context, vertexShaderSource: vertexShader, @@ -140,7 +140,7 @@ describe( pixelFormat: PixelFormat.RGBA, }); const computeCommand = new ComputeCommand({ - fragmentShaderSource: "void main() { gl_FragColor = vec4(1.0); }", + fragmentShaderSource: "void main() { out_FragColor = vec4(1.0); }", outputTexture: outputTexture, }); diff --git a/packages/engine/Specs/Renderer/ContextSpec.js b/packages/engine/Specs/Renderer/ContextSpec.js index b6cf81316f8e..7cb308cbcb8f 100644 --- a/packages/engine/Specs/Renderer/ContextSpec.js +++ b/packages/engine/Specs/Renderer/ContextSpec.js @@ -131,9 +131,9 @@ describe( fs += "void main()\n" + "{\n"; if (context.standardDerivatives) { - fs += " gl_FragColor = vec4(dFdx(1.0), dFdy(1.0), 1.0, 1.0);\n"; + fs += " out_FragColor = vec4(dFdx(1.0), dFdy(1.0), 1.0, 1.0);\n"; } else { - fs += " gl_FragColor = vec4(1.0);\n"; + fs += " out_FragColor = vec4(1.0);\n"; } fs += "}"; @@ -207,7 +207,7 @@ describe( const fs = "void main()\n" + "{\n" + - " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n" + + " out_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n" + "}"; expect({ @@ -221,7 +221,7 @@ describe( fsFragDepth += "void main()\n" + "{\n" + - " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"; + " out_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"; if (context.fragmentDepth) { fsFragDepth += " gl_FragDepth"; diff --git a/packages/engine/Specs/Renderer/CubeMapSpec.js b/packages/engine/Specs/Renderer/CubeMapSpec.js index 361bc0bd723b..5803c10912b6 100644 --- a/packages/engine/Specs/Renderer/CubeMapSpec.js +++ b/packages/engine/Specs/Renderer/CubeMapSpec.js @@ -30,7 +30,7 @@ describe( const fs = "uniform samplerCube u_texture;" + "uniform mediump vec3 u_direction;" + - "void main() { gl_FragColor = textureCube(u_texture, normalize(u_direction)); }"; + "void main() { out_FragColor = czm_textureCube(u_texture, normalize(u_direction)); }"; let faceDirections = options.faceDirections; if (!defined(faceDirections)) { @@ -596,7 +596,7 @@ describe( const fs = "uniform samplerCube u_texture;" + - "void main() { gl_FragColor = textureCube(u_texture, normalize(vec3(1.0, 1.0, 0.0))); }"; + "void main() { out_FragColor = czm_textureCube(u_texture, normalize(vec3(1.0, 1.0, 0.0))); }"; const uniformMap = { u_texture: function () { @@ -753,7 +753,7 @@ describe( const fs = "uniform samplerCube u_texture;" + - "void main() { gl_FragColor = textureCube(u_texture, normalize(vec3(1.0, 1.0, 0.0))); }"; + "void main() { out_FragColor = czm_textureCube(u_texture, normalize(vec3(1.0, 1.0, 0.0))); }"; const uniformMap = { u_texture: function () { @@ -1053,7 +1053,7 @@ describe( const fs = "uniform samplerCube u_cubeMap;" + - "void main() { gl_FragColor = textureCube(u_cubeMap, vec3(1.0, 0.0, 0.0)); }"; + "void main() { out_FragColor = czm_textureCube(u_cubeMap, vec3(1.0, 0.0, 0.0)); }"; const uniformMap = { u_cubeMap: function () { @@ -1111,7 +1111,7 @@ describe( const fs = "uniform samplerCube u_cubeMap;" + "uniform sampler2D u_texture;" + - "void main() { gl_FragColor = textureCube(u_cubeMap, vec3(1.0, 0.0, 0.0)) + texture2D(u_texture, vec2(0.0)); }"; + "void main() { out_FragColor = czm_textureCube(u_cubeMap, vec3(1.0, 0.0, 0.0)) + texture(u_texture, vec2(0.0)); }"; const uniformMap = { u_cubeMap: function () { @@ -1151,7 +1151,7 @@ describe( const fs = "uniform samplerCube u_cubeMap;" + - "void main() { gl_FragColor = textureCube(u_cubeMap, vec3(1.0, 0.0, 0.0)); }"; + "void main() { out_FragColor = czm_textureCube(u_cubeMap, vec3(1.0, 0.0, 0.0)); }"; const uniformMap = { u_cubeMap: function () { diff --git a/packages/engine/Specs/Renderer/DrawSpec.js b/packages/engine/Specs/Renderer/DrawSpec.js index 274b00956b5f..ea4a508eddc1 100644 --- a/packages/engine/Specs/Renderer/DrawSpec.js +++ b/packages/engine/Specs/Renderer/DrawSpec.js @@ -40,7 +40,7 @@ describe( }); it("draws a white point", function () { - const fs = "void main() { gl_FragColor = vec4(1.0); }"; + const fs = "void main() { out_FragColor = vec4(1.0); }"; expect({ context: context, fragmentShader: fs, @@ -52,8 +52,8 @@ describe( const context = createContext(); const vs = - "attribute vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; - const fs = "void main() { gl_FragColor = vec4(1.0); }"; + "in vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; + const fs = "void main() { out_FragColor = vec4(1.0); }"; sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -106,16 +106,16 @@ describe( it("draws a red point with two vertex buffers", function () { const vs = - "attribute vec4 position;" + - "attribute mediump float intensity;" + - "varying mediump float fs_intensity;" + + "in vec4 position;" + + "in mediump float intensity;" + + "out mediump float fs_intensity;" + "void main() {" + " gl_PointSize = 1.0; " + " gl_Position = position;" + " fs_intensity = intensity;" + "}"; const fs = - "varying mediump float fs_intensity; void main() { gl_FragColor = vec4(fs_intensity, 0.0, 0.0, 1.0); }"; + "in mediump float fs_intensity; void main() { out_FragColor = vec4(fs_intensity, 0.0, 0.0, 1.0); }"; sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -164,16 +164,16 @@ describe( it("draws a red point with one interleaved vertex buffers", function () { const vs = - "attribute vec4 position;" + - "attribute mediump float intensity;" + - "varying mediump float fs_intensity;" + + "in vec4 position;" + + "in mediump float intensity;" + + "out mediump float fs_intensity;" + "void main() {" + " gl_PointSize = 1.0; " + " gl_Position = position;" + " fs_intensity = intensity;" + "}"; const fs = - "varying mediump float fs_intensity; void main() { gl_FragColor = vec4(fs_intensity, 0.0, 0.0, 1.0); }"; + "in mediump float fs_intensity; void main() { out_FragColor = vec4(fs_intensity, 0.0, 0.0, 1.0); }"; sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -225,8 +225,8 @@ describe( it("draws with scissor test", function () { const vs = - "attribute vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; - const fs = "void main() { gl_FragColor = vec4(1.0); }"; + "in vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; + const fs = "void main() { out_FragColor = vec4(1.0); }"; sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -288,8 +288,8 @@ describe( it("draws with color mask", function () { const vs = - "attribute vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; - const fs = "void main() { gl_FragColor = vec4(1.0); }"; + "in vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; + const fs = "void main() { out_FragColor = vec4(1.0); }"; sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -361,8 +361,8 @@ describe( }); const vs = - "attribute vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; - const fs = "void main() { gl_FragColor = vec4(0.5); }"; + "in vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; + const fs = "void main() { out_FragColor = vec4(0.5); }"; const sp = ShaderProgram.fromCache({ context: cxt, vertexShaderSource: vs, @@ -435,8 +435,8 @@ describe( }); const vs = - "attribute vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; - const fs = "void main() { gl_FragColor = vec4(1.0, 1.0, 1.0, 0.5); }"; + "in vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; + const fs = "void main() { out_FragColor = vec4(1.0, 1.0, 1.0, 0.5); }"; const sp = ShaderProgram.fromCache({ context: cxt, vertexShaderSource: vs, @@ -503,8 +503,8 @@ describe( it("draws with blend color", function () { const vs = - "attribute vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; - const fs = "void main() { gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); }"; + "in vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; + const fs = "void main() { out_FragColor = vec4(1.0, 1.0, 1.0, 1.0); }"; sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -565,9 +565,8 @@ describe( }); it("draws with culling", function () { - const vs = - "attribute vec4 position; void main() { gl_Position = position; }"; - const fs = "void main() { gl_FragColor = vec4(1.0); }"; + const vs = "in vec4 position; void main() { gl_Position = position; }"; + const fs = "void main() { out_FragColor = vec4(1.0); }"; sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -645,9 +644,8 @@ describe( }); it("draws with front face winding order", function () { - const vs = - "attribute vec4 position; void main() { gl_Position = position; }"; - const fs = "void main() { gl_FragColor = vec4(1.0); }"; + const vs = "in vec4 position; void main() { gl_Position = position; }"; + const fs = "void main() { out_FragColor = vec4(1.0); }"; sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -727,9 +725,8 @@ describe( }); it("draws with the depth test", function () { - const vs = - "attribute vec4 position; void main() { gl_Position = position; }"; - const fs = "void main() { gl_FragColor = vec4(1.0); }"; + const vs = "in vec4 position; void main() { gl_Position = position; }"; + const fs = "void main() { out_FragColor = vec4(1.0); }"; sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -808,9 +805,9 @@ describe( it("draws with depth range", function () { const vs = - "attribute vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; + "in vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; const fs = - "void main() { gl_FragColor = vec4(gl_DepthRange.near, gl_DepthRange.far, 0.0, 1.0); }"; + "void main() { out_FragColor = vec4(gl_DepthRange.near, gl_DepthRange.far, 0.0, 1.0); }"; sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -854,9 +851,8 @@ describe( }); it("draws with line width", function () { - const vs = - "attribute vec4 position; void main() { gl_Position = position; }"; - const fs = "void main() { gl_FragColor = vec4(1.0); }"; + const vs = "in vec4 position; void main() { gl_Position = position; }"; + const fs = "void main() { out_FragColor = vec4(1.0); }"; sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -912,8 +908,8 @@ describe( it("draws with polygon offset", function () { const vs = - "attribute vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; - const fs = "void main() { gl_FragColor = vec4(1.0); }"; + "in vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; + const fs = "void main() { out_FragColor = vec4(1.0); }"; sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -964,8 +960,8 @@ describe( } const vs = - "attribute vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; - const fs = "void main() { gl_FragColor = vec4(1.0); }"; + "in vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; + const fs = "void main() { out_FragColor = vec4(1.0); }"; sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -1028,8 +1024,8 @@ describe( } const vs = - "attribute vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; - const fs = "void main() { gl_FragColor = vec4(1.0); }"; + "in vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; + const fs = "void main() { out_FragColor = vec4(1.0); }"; sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -1133,9 +1129,8 @@ describe( return; } - const vs = - "attribute vec4 position; void main() { gl_Position = position; }"; - const fs = "void main() { gl_FragColor = vec4(1.0); }"; + const vs = "in vec4 position; void main() { gl_Position = position; }"; + const fs = "void main() { out_FragColor = vec4(1.0); }"; sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -1237,8 +1232,8 @@ describe( it("draws with an offset and count", function () { const vs = - "attribute vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; - const fs = "void main() { gl_FragColor = vec4(1.0); }"; + "in vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; + const fs = "void main() { out_FragColor = vec4(1.0); }"; sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -1290,16 +1285,15 @@ describe( it("draws two instances of a point with different per-instance colors", function () { const vs = - "attribute vec4 position;" + - "attribute vec4 color;" + - "varying vec4 v_color;" + + "in vec4 position;" + + "in vec4 color;" + + "out vec4 v_color;" + "void main() {" + " gl_PointSize = 1.0; " + " gl_Position = position;" + " v_color = color;" + "}"; - const fs = - "varying vec4 v_color; void main() { gl_FragColor = v_color; }"; + const fs = "in vec4 v_color; void main() { out_FragColor = v_color; }"; sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -1369,8 +1363,8 @@ describe( it("fails to draw (missing primitiveType)", function () { const vs = - "attribute vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; - const fs = "void main() { gl_FragColor = vec4(1.0); }"; + "in vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; + const fs = "void main() { out_FragColor = vec4(1.0); }"; sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -1386,8 +1380,8 @@ describe( it("fails to draw (primitiveType)", function () { const vs = - "attribute vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; - const fs = "void main() { gl_FragColor = vec4(1.0); }"; + "in vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; + const fs = "void main() { out_FragColor = vec4(1.0); }"; sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -1404,8 +1398,8 @@ describe( it("fails to draw (missing vertexArray)", function () { const vs = - "attribute vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; - const fs = "void main() { gl_FragColor = vec4(1.0); }"; + "in vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; + const fs = "void main() { out_FragColor = vec4(1.0); }"; sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -1422,8 +1416,8 @@ describe( it("fails to draw (negative offset)", function () { const vs = - "attribute vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; - const fs = "void main() { gl_FragColor = vec4(1.0); }"; + "in vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; + const fs = "void main() { out_FragColor = vec4(1.0); }"; sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -1445,8 +1439,8 @@ describe( it("throws if instanceCount is less than one", function () { const vs = - "attribute vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; - const fs = "void main() { gl_FragColor = vec4(1.0); }"; + "in vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; + const fs = "void main() { out_FragColor = vec4(1.0); }"; sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -1483,49 +1477,66 @@ describe( }).toThrowDeveloperError(); }); - it("throws when instanceCount is greater than one and instancing is disabled", function () { - // disable extension - const instancedArrays = context._instancedArrays; - context._instancedArrays = undefined; + describe("WebGL1", function () { + let webgl1Context; - const vs = - "attribute vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; - const fs = "void main() { gl_FragColor = vec4(1.0); }"; - sp = ShaderProgram.fromCache({ - context: context, - vertexShaderSource: vs, - fragmentShaderSource: fs, - attributeLocations: { - position: 0, - }, + beforeAll(() => { + webgl1Context = createContext({ + requestWebgl1: true, + }); }); - va = new VertexArray({ - context: context, - attributes: [ - { - index: 0, - vertexBuffer: Buffer.createVertexBuffer({ - context: context, - typedArray: new Float32Array([0, 0, 0, 1]), - usage: BufferUsage.STATIC_DRAW, - }), - componentsPerAttribute: 4, - }, - ], + afterAll(() => { + webgl1Context.destroyForSpecs(); }); - const command = new DrawCommand({ - primitiveType: PrimitiveType.POINTS, - shaderProgram: sp, - vertexArray: va, - instanceCount: 2, - }); + it("throws when instanceCount is greater than one and instancing is disabled", function () { + const webgl1Context = createContext({ + requestWebgl1: true, + }); + // disable extension + const instancedArrays = webgl1Context._instancedArrays; + webgl1Context._instancedArrays = undefined; + + const vs = + "in vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; + const fs = "void main() { out_FragColor = vec4(1.0); }"; + sp = ShaderProgram.fromCache({ + context: webgl1Context, + vertexShaderSource: vs, + fragmentShaderSource: fs, + attributeLocations: { + position: 0, + }, + }); - expect(function () { - command.execute(context); - }).toThrowDeveloperError(); - context._instancedArrays = instancedArrays; + va = new VertexArray({ + context: webgl1Context, + attributes: [ + { + index: 0, + vertexBuffer: Buffer.createVertexBuffer({ + context: webgl1Context, + typedArray: new Float32Array([0, 0, 0, 1]), + usage: BufferUsage.STATIC_DRAW, + }), + componentsPerAttribute: 4, + }, + ], + }); + + const command = new DrawCommand({ + primitiveType: PrimitiveType.POINTS, + shaderProgram: sp, + vertexArray: va, + instanceCount: 2, + }); + + expect(function () { + command.execute(webgl1Context); + }).toThrowDeveloperError(); + context._instancedArrays = instancedArrays; + }); }); }, "WebGL" diff --git a/packages/engine/Specs/Renderer/FramebufferManagerSpec.js b/packages/engine/Specs/Renderer/FramebufferManagerSpec.js index ff9ddaee7dca..12ddd6966f4d 100644 --- a/packages/engine/Specs/Renderer/FramebufferManagerSpec.js +++ b/packages/engine/Specs/Renderer/FramebufferManagerSpec.js @@ -20,7 +20,7 @@ describe( let fbm; beforeAll(function () { - context = createContext({ requestWebgl1: false }); + context = createContext(); }); afterAll(function () { @@ -467,7 +467,7 @@ describe( fbm.clear(context, clearCommand); const fs = - "uniform sampler2D u_texture; void main() { gl_FragColor = texture2D(u_texture, vec2(0.0)); }"; + "uniform sampler2D u_texture; void main() { out_FragColor = texture(u_texture, vec2(0.0)); }"; const uniformMap = { u_texture: function () { return fbm.getColorTexture(); @@ -500,7 +500,7 @@ describe( expect(clearCommand.framebuffer).toBe(fb); const fs = - "uniform sampler2D u_texture; void main() { gl_FragColor = texture2D(u_texture, vec2(0.0)); }"; + "uniform sampler2D u_texture; void main() { out_FragColor = texture(u_texture, vec2(0.0)); }"; const uniformMap = { u_texture: function () { return fbm.getColorTexture(); diff --git a/packages/engine/Specs/Renderer/FramebufferSpec.js b/packages/engine/Specs/Renderer/FramebufferSpec.js index d92aef5da199..c1dbe5f2c022 100644 --- a/packages/engine/Specs/Renderer/FramebufferSpec.js +++ b/packages/engine/Specs/Renderer/FramebufferSpec.js @@ -176,7 +176,7 @@ describe( // 3 of 3. Render green to default color buffer by reading from previous color attachment const fs = - "uniform sampler2D u_texture; void main() { gl_FragColor = texture2D(u_texture, vec2(0.0)); }"; + "uniform sampler2D u_texture; void main() { out_FragColor = texture(u_texture, vec2(0.0)); }"; const uniformMap = { u_texture: function () { return colorTexture; @@ -216,7 +216,7 @@ describe( // 3 of 3. Render green to default color buffer by reading from previous color attachment const fs = - "uniform samplerCube u_cubeMap; void main() { gl_FragColor = textureCube(u_cubeMap, vec3(1.0, 0.0, 0.0)); }"; + "uniform samplerCube u_cubeMap; void main() { out_FragColor = czm_textureCube(u_cubeMap, vec3(1.0, 0.0, 0.0)); }"; const uniformMap = { u_cubeMap: function () { return cubeMap; @@ -234,8 +234,8 @@ describe( function renderColorTexture(framebuffer, color, expectedColor) { const vs = - "attribute vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; - const fs = "uniform vec4 color; void main() { gl_FragColor = color; }"; + "in vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; + const fs = "uniform vec4 color; void main() { out_FragColor = color; }"; sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -360,8 +360,8 @@ describe( // 1 of 3. Render green point into color attachment. const vs = - "attribute vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; - const fs = "void main() { gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); }"; + "in vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; + const fs = "void main() { out_FragColor = vec4(0.0, 1.0, 0.0, 1.0); }"; sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -404,9 +404,9 @@ describe( // 3 of 3. Render green to default color buffer by reading from previous color attachment const vs2 = - "attribute vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; + "in vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; const fs2 = - "uniform sampler2D u_texture; void main() { gl_FragColor = texture2D(u_texture, vec2(0.0)).rrrr; }"; + "uniform sampler2D u_texture; void main() { out_FragColor = texture(u_texture, vec2(0.0)).rrrr; }"; let sp2 = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs2, @@ -509,8 +509,8 @@ describe( }); const vs = - "attribute vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; - const fs = "void main() { gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); }"; + "in vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; + const fs = "void main() { out_FragColor = vec4(1.0, 1.0, 1.0, 1.0); }"; sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -619,9 +619,9 @@ describe( // 2 of 5. Render red point into color attachment 0 and green point to color attachment 1. const vs = - "attribute vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; + "in vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; const fs = - "#extension GL_EXT_draw_buffers : enable \n void main() { gl_FragData[0] = vec4(1.0, 0.0, 0.0, 1.0); gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0); }"; + "layout (location = 0) out vec4 out_FragData_0;\n layout (location = 1) out vec4 out_FragData_1; \n void main() { out_FragData_0 = vec4(1.0, 0.0, 0.0, 1.0); out_FragData_1 = vec4(0.0, 1.0, 0.0, 1.0); }"; sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -659,9 +659,9 @@ describe( // 4 of 5. Render yellow to default color buffer by reading from previous color attachments const vs2 = - "attribute vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; + "in vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; const fs2 = - "uniform sampler2D u_texture0; uniform sampler2D u_texture1; void main() { gl_FragColor = texture2D(u_texture0, vec2(0.0)) + texture2D(u_texture1, vec2(0.0)); }"; + "uniform sampler2D u_texture0; uniform sampler2D u_texture1; void main() { out_FragColor = texture(u_texture0, vec2(0.0)) + texture(u_texture1, vec2(0.0)); }"; let sp2 = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs2, @@ -879,8 +879,8 @@ describe( }); const vs = - "attribute vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; - const fs = "void main() { gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); }"; + "in vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; + const fs = "void main() { out_FragColor = vec4(1.0, 1.0, 1.0, 1.0); }"; sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, diff --git a/packages/engine/Specs/Renderer/MultisampleFramebufferSpec.js b/packages/engine/Specs/Renderer/MultisampleFramebufferSpec.js index 9b3943708b25..faf90872bbe0 100644 --- a/packages/engine/Specs/Renderer/MultisampleFramebufferSpec.js +++ b/packages/engine/Specs/Renderer/MultisampleFramebufferSpec.js @@ -27,7 +27,7 @@ describe( let framebuffer; beforeAll(function () { - context = createContext({ requestWebgl1: false }); + context = createContext(); }); afterAll(function () { @@ -124,8 +124,8 @@ describe( function renderColor(framebuffer, color) { const vs = - "attribute vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; - const fs = "uniform vec4 color; void main() { gl_FragColor = color; }"; + "in vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; + const fs = "uniform vec4 color; void main() { out_FragColor = color; }"; sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -215,8 +215,8 @@ describe( // 1 of 3. Render green point into color attachment. const vs = - "attribute vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; - const fs = "void main() { gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); }"; + "in vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; + const fs = "void main() { out_FragColor = vec4(0.0, 1.0, 0.0, 1.0); }"; sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -261,9 +261,9 @@ describe( // 3 of 3. Render green to default color buffer by reading from blitted color attachment const vs2 = - "attribute vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; + "in vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; const fs2 = - "uniform sampler2D u_texture; void main() { gl_FragColor = texture2D(u_texture, vec2(0.0)).rrrr; }"; + "uniform sampler2D u_texture; void main() { out_FragColor = texture(u_texture, vec2(0.0)).rrrr; }"; let sp2 = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs2, diff --git a/packages/engine/Specs/Renderer/ShaderBuilderSpec.js b/packages/engine/Specs/Renderer/ShaderBuilderSpec.js index b2383ac6b5fb..8f83492a9fd1 100644 --- a/packages/engine/Specs/Renderer/ShaderBuilderSpec.js +++ b/packages/engine/Specs/Renderer/ShaderBuilderSpec.js @@ -598,10 +598,7 @@ describe( expect(positionLocation).toBe(0); expect(normalLocation).toBe(1); const shaderProgram = shaderBuilder.buildShaderProgram(context); - const expectedAttributes = [ - "attribute vec3 a_position;", - "attribute vec3 a_normal;", - ]; + const expectedAttributes = ["in vec3 a_position;", "in vec3 a_normal;"]; checkVertexShader(shaderProgram, [], expectedAttributes); checkFragmentShader(shaderProgram, [], []); @@ -661,10 +658,7 @@ describe( expect(colorLocation).toBe(1); expect(normalLocation).toBe(2); const shaderProgram = shaderBuilder.buildShaderProgram(context); - const expectedAttributes = [ - "attribute vec4 a_color;", - "attribute vec3 a_normal;", - ]; + const expectedAttributes = ["in vec4 a_color;", "in vec3 a_normal;"]; checkVertexShader(shaderProgram, [], expectedAttributes); checkFragmentShader(shaderProgram, [], []); const expectedLocations = { @@ -685,10 +679,7 @@ describe( // this is 4 because the mat3 takes up locations 1, 2 and 3 expect(colorLocation).toBe(4); const shaderProgram = shaderBuilder.buildShaderProgram(context); - const expectedAttributes = [ - "attribute mat3 a_warpMatrix;", - "attribute vec3 a_color;", - ]; + const expectedAttributes = ["in mat3 a_warpMatrix;", "in vec3 a_color;"]; checkVertexShader(shaderProgram, [], expectedAttributes); checkFragmentShader(shaderProgram, [], []); const expectedLocations = { @@ -730,10 +721,18 @@ describe( it("addVarying adds varyings to both shaders", function () { const shaderBuilder = new ShaderBuilder(); shaderBuilder.addVarying("vec2", "v_uv"); - const expectedLines = ["varying vec2 v_uv;"]; + + const expectedVaryings = ["vec2 v_uv;"]; + const expectedVertexVaryings = expectedVaryings.map( + (varying) => `out ${varying}` + ); + const expectedFragmentVaryings = expectedVaryings.map( + (varying) => `in ${varying}` + ); + const shaderProgram = shaderBuilder.buildShaderProgram(context); - checkVertexShader(shaderProgram, [], expectedLines); - checkFragmentShader(shaderProgram, [], expectedLines); + checkVertexShader(shaderProgram, [], expectedVertexVaryings); + checkFragmentShader(shaderProgram, [], expectedFragmentVaryings); }); it("addVertexLines throws for undefined lines", function () { @@ -789,7 +788,7 @@ describe( const fragmentLines = [ "void main()", "{", - " gl_FragColor = vec4(1.0, 0.5, 0.0, 1.0);", + " out_FragColor = vec4(1.0, 0.5, 0.0, 1.0);", "}", ]; shaderBuilder.addFragmentLines(fragmentLines); @@ -829,28 +828,31 @@ describe( const fragmentLines = [ "void main()", "{", - " gl_FragColor = vec4(v_uv, BLUE_TINT, 1.0);", + " out_FragColor = vec4(v_uv, BLUE_TINT, 1.0);", "}", ]; shaderBuilder.addFragmentLines(fragmentLines); - const expectedAttributes = [ - "attribute vec3 a_position;", - "attribute vec3 a_uv;", - ]; + const expectedAttributes = ["in vec3 a_position;", "in vec3 a_uv;"]; - const expectedVaryings = ["varying vec2 v_uv;"]; + const expectedVaryings = ["vec2 v_uv;"]; + const expectedVertexVaryings = expectedVaryings.map( + (varying) => `out ${varying}` + ); + const expectedFragmentVaryings = expectedVaryings.map( + (varying) => `in ${varying}` + ); const shaderProgram = shaderBuilder.buildShaderProgram(context); checkVertexShader( shaderProgram, [], - expectedAttributes.concat(expectedVaryings, vertexLines) + expectedAttributes.concat(expectedVertexVaryings, vertexLines) ); checkFragmentShader( shaderProgram, ["BLUE_TINT 0.5"], - expectedVaryings.concat(fragmentLines) + expectedFragmentVaryings.concat(fragmentLines) ); }); }, diff --git a/packages/engine/Specs/Renderer/ShaderCacheSpec.js b/packages/engine/Specs/Renderer/ShaderCacheSpec.js index bebd61bc18fe..3a71abfea11d 100644 --- a/packages/engine/Specs/Renderer/ShaderCacheSpec.js +++ b/packages/engine/Specs/Renderer/ShaderCacheSpec.js @@ -15,9 +15,8 @@ describe( }); it("adds and removes", function () { - const vs = - "attribute vec4 position; void main() { gl_Position = position; }"; - const fs = "void main() { gl_FragColor = vec4(1.0); }"; + const vs = "in vec4 position; void main() { gl_Position = position; }"; + const fs = "void main() { out_FragColor = vec4(1.0); }"; const cache = new ShaderCache(context); @@ -44,9 +43,8 @@ describe( }); it("adds and removes 2", function () { - const vs = - "attribute vec4 position; void main() { gl_Position = position; }"; - const fs = "void main() { gl_FragColor = vec4(1.0); }"; + const vs = "in vec4 position; void main() { gl_Position = position; }"; + const fs = "void main() { out_FragColor = vec4(1.0); }"; const cache = new ShaderCache(context); const sp = cache.getShaderProgram({ @@ -68,9 +66,8 @@ describe( }); it("has a cache hit", function () { - const vs = - "attribute vec4 position; void main() { gl_Position = position; }"; - const fs = "void main() { gl_FragColor = vec4(1.0); }"; + const vs = "in vec4 position; void main() { gl_Position = position; }"; + const fs = "void main() { out_FragColor = vec4(1.0); }"; // These functions can be expensive for large shaders, so they should // only be called the first time a shader is created. @@ -121,9 +118,8 @@ describe( }); it("cache handles unordered attributeLocations dictionary", function () { - const vs = - "attribute vec4 position; void main() { gl_Position = position; }"; - const fs = "void main() { gl_FragColor = vec4(1.0); }"; + const vs = "in vec4 position; void main() { gl_Position = position; }"; + const fs = "void main() { out_FragColor = vec4(1.0); }"; // Create a case where JSON.stringify(x) may produce two different results // without sorting the keys @@ -183,10 +179,9 @@ describe( }); it("replaces a shader program", function () { - const vs = - "attribute vec4 position; void main() { gl_Position = position; }"; - const fs = "void main() { gl_FragColor = vec4(1.0); }"; - const fs2 = "void main() { gl_FragColor = vec4(0.5); }"; + const vs = "in vec4 position; void main() { gl_Position = position; }"; + const fs = "void main() { out_FragColor = vec4(1.0); }"; + const fs2 = "void main() { out_FragColor = vec4(0.5); }"; const attributeLocations = { position: 0, }; @@ -212,9 +207,8 @@ describe( }); it("avoids thrashing", function () { - const vs = - "attribute vec4 position; void main() { gl_Position = position; }"; - const fs = "void main() { gl_FragColor = vec4(1.0); }"; + const vs = "in vec4 position; void main() { gl_Position = position; }"; + const fs = "void main() { out_FragColor = vec4(1.0); }"; const cache = new ShaderCache(context); const sp = cache.getShaderProgram({ @@ -247,9 +241,8 @@ describe( }); it("create derived shader program", function () { - const vs = - "attribute vec4 position; void main() { gl_Position = position; }"; - const fs = "void main() { gl_FragColor = vec4(1.0); }"; + const vs = "in vec4 position; void main() { gl_Position = position; }"; + const fs = "void main() { out_FragColor = vec4(1.0); }"; const cache = new ShaderCache(context); const sp = cache.getShaderProgram({ @@ -264,7 +257,7 @@ describe( let spDerived = cache.getDerivedShaderProgram(sp, keyword); expect(spDerived).not.toBeDefined(); - const fsDerived = "void main() { gl_FragColor = vec4(vec3(1.0), 0.5); }"; + const fsDerived = "void main() { out_FragColor = vec4(vec3(1.0), 0.5); }"; spDerived = cache.createDerivedShaderProgram(sp, keyword, { vertexShaderSource: vs, fragmentShaderSource: fsDerived, @@ -278,9 +271,8 @@ describe( }); it("replaces derived shader program", function () { - const vs = - "attribute vec4 position; void main() { gl_Position = position; }"; - const fs = "void main() { gl_FragColor = vec4(1.0); }"; + const vs = "in vec4 position; void main() { gl_Position = position; }"; + const fs = "void main() { out_FragColor = vec4(1.0); }"; const cache = new ShaderCache(context); const sp = cache.getShaderProgram({ @@ -293,7 +285,7 @@ describe( const derivedKeywords = sp._cachedShader.derivedKeywords; const keyword = "derived"; - const fsDerived = "void main() { gl_FragColor = vec4(vec3(1.0), 0.5); }"; + const fsDerived = "void main() { out_FragColor = vec4(vec3(1.0), 0.5); }"; const spDerived = cache.replaceDerivedShaderProgram(sp, keyword, { vertexShaderSource: vs, fragmentShaderSource: fsDerived, @@ -305,7 +297,8 @@ describe( expect(spDerived).toBeDefined(); expect(derivedKeywords.length).toBe(1); - const fsDerived2 = "void main() { gl_FragColor = vec4(vec3(0.5), 0.5); }"; + const fsDerived2 = + "void main() { out_FragColor = vec4(vec3(0.5), 0.5); }"; const spDerived2 = cache.replaceDerivedShaderProgram(sp, keyword, { vertexShaderSource: vs, fragmentShaderSource: fsDerived2, @@ -322,9 +315,8 @@ describe( }); it("destroying a shader program destroys its derived shaders", function () { - const vs = - "attribute vec4 position; void main() { gl_Position = position; }"; - const fs = "void main() { gl_FragColor = vec4(1.0); }"; + const vs = "in vec4 position; void main() { gl_Position = position; }"; + const fs = "void main() { out_FragColor = vec4(1.0); }"; const cache = new ShaderCache(context); const sp = cache.getShaderProgram({ @@ -336,7 +328,7 @@ describe( }); const keyword = "derived"; - const fsDerived = "void main() { gl_FragColor = vec4(vec3(1.0), 0.5); }"; + const fsDerived = "void main() { out_FragColor = vec4(vec3(1.0), 0.5); }"; const spDerived = cache.createDerivedShaderProgram(sp, keyword, { vertexShaderSource: vs, fragmentShaderSource: fsDerived, @@ -356,9 +348,8 @@ describe( }); it("is destroyed", function () { - const vs = - "attribute vec4 position; void main() { gl_Position = position; }"; - const fs = "void main() { gl_FragColor = vec4(1.0); }"; + const vs = "in vec4 position; void main() { gl_Position = position; }"; + const fs = "void main() { out_FragColor = vec4(1.0); }"; const cache = new ShaderCache(context); const sp = cache.getShaderProgram({ diff --git a/packages/engine/Specs/Renderer/ShaderProgramSpec.js b/packages/engine/Specs/Renderer/ShaderProgramSpec.js index e0d20939903f..d40ad7c34a05 100644 --- a/packages/engine/Specs/Renderer/ShaderProgramSpec.js +++ b/packages/engine/Specs/Renderer/ShaderProgramSpec.js @@ -24,7 +24,7 @@ describe( czm_testFunction2: "void czm_testFunction2(vec4 color) { czm_testFunction1(color); }", czm_testFunction1: - "void czm_testFunction1(vec4 color) { gl_FragColor = color; }", + "void czm_testFunction1(vec4 color) { out_FragColor = color; }", czm_testDiamondDependency1: "vec4 czm_testDiamondDependency1(vec4 color) { return czm_testAddAlpha(color); }", czm_testDiamondDependency2: @@ -70,7 +70,7 @@ describe( it("has vertex and fragment shader source", function () { const vs = "void main() { gl_Position = vec4(1.0); }"; - const fs = "void main() { gl_FragColor = vec4(1.0); }"; + const fs = "void main() { out_FragColor = vec4(1.0); }"; sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -91,9 +91,8 @@ describe( }); it("has a position vertex attribute", function () { - const vs = - "attribute vec4 position; void main() { gl_Position = position; }"; - const fs = "void main() { gl_FragColor = vec4(1.0); }"; + const vs = "in vec4 position; void main() { gl_Position = position; }"; + const fs = "void main() { out_FragColor = vec4(1.0); }"; sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -110,11 +109,11 @@ describe( it("sets attribute indices", function () { const vs = - "attribute vec4 position;" + - "attribute vec3 normal;" + - "attribute float heat;" + + "in vec4 position;" + + "in vec3 normal;" + + "in float heat;" + "void main() { gl_Position = position + vec4(normal, 0.0) + vec4(heat); }"; - const fs = "void main() { gl_FragColor = vec4(1.0); }"; + const fs = "void main() { out_FragColor = vec4(1.0); }"; const attributes = { position: 3, @@ -145,7 +144,7 @@ describe( it("has an automatic uniform", function () { const vs = "uniform vec4 u_vec4; void main() { gl_Position = u_vec4; }"; const fs = - "void main() { gl_FragColor = vec4((czm_viewport.x == 0.0) && (czm_viewport.y == 0.0) && (czm_viewport.z == 1.0) && (czm_viewport.w == 1.0)); }"; + "void main() { out_FragColor = vec4((czm_viewport.x == 0.0) && (czm_viewport.y == 0.0) && (czm_viewport.z == 1.0) && (czm_viewport.w == 1.0)); }"; sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -182,7 +181,7 @@ describe( const fs = "uniform sampler2D u_sampler2D;" + "uniform samplerCube u_samplerCube;" + - "void main() { gl_FragColor = texture2D(u_sampler2D, vec2(0.0)) + textureCube(u_samplerCube, vec3(1.0)); }"; + "void main() { out_FragColor = texture(u_sampler2D, vec2(0.0)) + czm_textureCube(u_samplerCube, vec3(1.0)); }"; sp = ShaderProgram.fromCache({ context: d, vertexShaderSource: vs, @@ -215,7 +214,7 @@ describe( it("has a struct uniform", function () { const vs = "uniform struct { float f; vec4 v; } u_struct; void main() { gl_Position = u_struct.f * u_struct.v; }"; - const fs = "void main() { gl_FragColor = vec4(1.0); }"; + const fs = "void main() { out_FragColor = vec4(1.0); }"; sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -252,7 +251,7 @@ describe( const fs = "uniform sampler2D u_sampler2D[2];" + "uniform samplerCube u_samplerCube[2];" + - "void main() { gl_FragColor = texture2D(u_sampler2D[0], vec2(0.0)) + texture2D(u_sampler2D[1], vec2(0.0)) + textureCube(u_samplerCube[0], vec3(1.0)) + textureCube(u_samplerCube[1], vec3(1.0)); }"; + "void main() { out_FragColor = texture(u_sampler2D[0], vec2(0.0)) + texture(u_sampler2D[1], vec2(0.0)) + czm_textureCube(u_samplerCube[0], vec3(1.0)) + czm_textureCube(u_samplerCube[1], vec3(1.0)); }"; sp = ShaderProgram.fromCache({ context: d, vertexShaderSource: vs, @@ -314,7 +313,7 @@ describe( " (czm_oneOverTwoPi > 0.0) && \n" + " (czm_radiansPerDegree > 0.0) && \n" + " (czm_degreesPerRadian > 0.0)) ? 1.0 : 0.0; \n" + - " gl_FragColor = vec4(f); \n" + + " out_FragColor = vec4(f); \n" + "}"; expect({ @@ -331,7 +330,7 @@ describe( " material.diffuse = vec3(1.0, 1.0, 1.0); \n" + " material.alpha = 1.0; \n" + " material.diffuse = czm_hue(material.diffuse, czm_twoPi); \n" + - " gl_FragColor = vec4(material.diffuse, material.alpha); \n" + + " out_FragColor = vec4(material.diffuse, material.alpha); \n" + "}"; expect({ @@ -344,9 +343,9 @@ describe( const highpFloatSupported = ContextLimits.highpFloatSupported; ContextLimits._highpFloatSupported = false; const vs = - "attribute vec4 position; uniform float u_value; varying float v_value; void main() { gl_PointSize = 1.0; v_value = u_value * czm_viewport.z; gl_Position = position; }"; + "in vec4 position; uniform float u_value; out float v_value; void main() { gl_PointSize = 1.0; v_value = u_value * czm_viewport.z; gl_Position = position; }"; const fs = - "uniform float u_value; varying float v_value; void main() { gl_FragColor = vec4(u_value * v_value * czm_viewport.z); }"; + "uniform float u_value; in float v_value; void main() { out_FragColor = vec4(u_value * v_value * czm_viewport.z); }"; const uniformMap = { u_value: function () { return 1.0; @@ -407,11 +406,12 @@ describe( it("diamond dependency", function () { const fs = + "layout (location = 0) out vec4 out_FragColor;\n" + "void main() { \n" + " vec4 color = vec4(1.0, 1.0, 1.0, 0.8); \n" + " color = czm_testDiamondDependency1(color); \n" + " color = czm_testDiamondDependency2(color); \n" + - " gl_FragColor = color; \n" + + " out_FragColor = color; \n" + "}"; expect({ @@ -466,9 +466,11 @@ describe( it("compiles with #version at the top", function () { const vs = "#version 100 \n" + - "attribute vec4 position; void main() { gl_Position = position; }"; + "in vec4 position; void main() { gl_Position = position; }"; const fs = - "#version 100 \n" + "void main() { gl_FragColor = vec4(1.0); }"; + "#version 100 \n" + + "layout (location = 0) out vec4 out_FragColor;\n" + + "void main() { out_FragColor = vec4(1.0); }"; sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -480,9 +482,12 @@ describe( const vs = "// comment before version directive. \n" + "#version 100 \n" + - "attribute vec4 position; void main() { gl_Position = position; }"; + "in vec4 position; void main() { gl_Position = position; }"; const fs = - "\n" + "#version 100 \n" + "void main() { gl_FragColor = vec4(1.0); }"; + "\n" + + "#version 100 \n" + + "layout (location = 0) out vec4 out_FragColor;\n" + + "void main() { out_FragColor = vec4(1.0); }"; sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -496,7 +501,9 @@ describe( } const vs = "does not compile."; - const fs = "void main() { gl_FragColor = vec4(1.0); }"; + const fs = + "layout (location = 0) out vec4 out_FragColor;\n" + + "void main() { out_FragColor = vec4(1.0); }"; sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -547,7 +554,8 @@ describe( it("fails with built-in function circular dependency", function () { const vs = "void main() { gl_Position = vec4(0.0); }"; const fs = - "void main() { czm_circularDependency1(); gl_FragColor = vec4(1.0); }"; + "layout (location = 0) out vec4 out_FragColor;\n" + + "void main() { czm_circularDependency1(); out_FragColor = vec4(1.0); }"; expect(function () { sp = ShaderProgram.fromCache({ context: context, diff --git a/packages/engine/Specs/Renderer/ShaderSourceSpec.js b/packages/engine/Specs/Renderer/ShaderSourceSpec.js index 5f5da7d3c449..8a63340b072e 100644 --- a/packages/engine/Specs/Renderer/ShaderSourceSpec.js +++ b/packages/engine/Specs/Renderer/ShaderSourceSpec.js @@ -2,9 +2,11 @@ import { ShaderSource } from "../../index.js"; describe("Renderer/ShaderSource", function () { const mockContext = { - webgl2: false, + webgl2: true, }; + const fragColorDeclarationRegex = /layout\s*\(location\s*=\s*0\)\s*out\s+vec4\s+out_FragColor;/g; + it("combines #defines", function () { const source = new ShaderSource({ defines: ["A", "B", ""], @@ -40,22 +42,22 @@ describe("Renderer/ShaderSource", function () { it("creates a pick shader with a uniform", function () { const source = new ShaderSource({ - sources: ["void main() { gl_FragColor = vec4(1.0); }"], + sources: ["void main() { out_FragColor = vec4(1.0); }"], pickColorQualifier: "uniform", }); const shaderText = source.createCombinedVertexShader(mockContext); expect(shaderText).toContain("uniform vec4 czm_pickColor;"); - expect(shaderText).toContain("gl_FragColor = czm_pickColor;"); + expect(shaderText).toContain("out_FragColor = czm_pickColor;"); }); it("creates a pick shader with a varying", function () { const source = new ShaderSource({ - sources: ["void main() { gl_FragColor = vec4(1.0); }"], - pickColorQualifier: "varying", + sources: ["void main() { out_FragColor = vec4(1.0); }"], + pickColorQualifier: "in", }); const shaderText = source.createCombinedVertexShader(mockContext); - expect(shaderText).toContain("varying vec4 czm_pickColor;"); - expect(shaderText).toContain("gl_FragColor = czm_pickColor;"); + expect(shaderText).toContain("in vec4 czm_pickColor;"); + expect(shaderText).toContain("out_FragColor = czm_pickColor;"); }); it("throws with invalid qualifier", function () { @@ -68,7 +70,7 @@ describe("Renderer/ShaderSource", function () { it("combines #version to shader", function () { const source = new ShaderSource({ - sources: ["#version 300 es\nvoid main() {gl_FragColor = vec4(1.0); }"], + sources: ["#version 300 es\nvoid main() {out_FragColor = vec4(1.0); }"], }); const shaderText = source.createCombinedVertexShader(mockContext); expect(shaderText).toStartWith("#version 300 es\n"); @@ -77,8 +79,8 @@ describe("Renderer/ShaderSource", function () { it("clones", function () { const source = new ShaderSource({ defines: ["A"], - sources: ["void main() { gl_FragColor = vec4(1.0); }"], - pickColorQualifier: "varying", + sources: ["void main() { out_FragColor = vec4(1.0); }"], + pickColorQualifier: "in", includeBuiltIns: false, }); const clone = source.clone(); @@ -100,13 +102,13 @@ describe("Renderer/ShaderSource", function () { it("creates cache key", function () { const source = new ShaderSource({ defines: ["A", "B", "C"], - sources: ["void main() { gl_FragColor = vec4(1.0); }"], - pickColorQualifier: "varying", + sources: ["void main() { out_FragColor = vec4(1.0); }"], + pickColorQualifier: "in", includeBuiltIns: false, }); expect(source.getCacheKey()).toBe( - "A,B,C:varying:false:void main() { gl_FragColor = vec4(1.0); }" + "A,B,C:in:false:void main() { out_FragColor = vec4(1.0); }" ); }); @@ -125,12 +127,40 @@ describe("Renderer/ShaderSource", function () { const source = new ShaderSource({ sources: [ "vec4 getColor() { return vec4(1.0, 0.0, 0.0, 1.0); }", - "void main() { gl_fragColor = getColor(); }", + "void main() { out_FragColor = getColor(); }", ], }); expect(source.getCacheKey()).toBe( - ":undefined:true:vec4 getColor() { return vec4(1.0, 0.0, 0.0, 1.0); }\nvoid main() { gl_fragColor = getColor(); }" + ":undefined:true:vec4 getColor() { return vec4(1.0, 0.0, 0.0, 1.0); }\nvoid main() { out_FragColor = getColor(); }" ); }); + + it("adds layout declaration for out_FragColor if it does not already exist", function () { + const source = new ShaderSource({ + defines: ["A"], + sources: ["void main() { out_FragColor = vec4(1.0); }"], + pickColorQualifier: "in", + includeBuiltIns: false, + }); + const shaderText = source.createCombinedFragmentShader(mockContext); + const fragColorDeclarations = + shaderText.match(fragColorDeclarationRegex) || []; + expect(fragColorDeclarations.length).toEqual(1); + }); + + it("does not layout declaration for out_FragColor if it already exists", function () { + const source = new ShaderSource({ + defines: ["A"], + sources: [ + "layout (location = 0) out vec4 out_FragColor; void main() { out_FragColor = vec4(1.0); }", + ], + pickColorQualifier: "in", + includeBuiltIns: false, + }); + const shaderText = source.createCombinedFragmentShader(mockContext); + const fragColorDeclarations = + shaderText.match(fragColorDeclarationRegex) || []; + expect(fragColorDeclarations.length).toEqual(1); + }); }); diff --git a/packages/engine/Specs/Renderer/TextureSpec.js b/packages/engine/Specs/Renderer/TextureSpec.js index 29d45d8ff270..1399d971fef2 100644 --- a/packages/engine/Specs/Renderer/TextureSpec.js +++ b/packages/engine/Specs/Renderer/TextureSpec.js @@ -33,10 +33,10 @@ describe( const fs = "uniform sampler2D u_texture;" + - "void main() { gl_FragColor = texture2D(u_texture, vec2(0.0)); }"; + "void main() { out_FragColor = texture(u_texture, vec2(0.0)); }"; const fsLuminanceAlpha = "uniform sampler2D u_texture;" + - "void main() { gl_FragColor = vec4(texture2D(u_texture, vec2(0.0)).ra, 0.0, 1.0); }"; + "void main() { out_FragColor = vec4(texture(u_texture, vec2(0.0)).ra, 0.0, 1.0); }"; let texture; const uniformMap = { u_texture: function () { @@ -333,7 +333,7 @@ describe( const fs = "uniform sampler2D u_texture;" + - "void main() { gl_FragColor = texture2D(u_texture, vec2(0.5, 0.0)); }"; + "void main() { out_FragColor = texture(u_texture, vec2(0.5, 0.0)); }"; if (!context.textureFloatLinear) { expect({ @@ -417,7 +417,7 @@ describe( const fs = "uniform sampler2D u_texture;" + - "void main() { gl_FragColor = texture2D(u_texture, vec2(0.5, 0.0)); }"; + "void main() { out_FragColor = texture(u_texture, vec2(0.5, 0.0)); }"; if (!context.textureHalfFloatLinear) { expect({ @@ -527,7 +527,7 @@ describe( fragmentShaderSource += "uniform sampler2D u_texture;"; fragmentShaderSource += "uniform mediump vec2 u_txCoords;"; fragmentShaderSource += - "void main() { gl_FragColor = texture2D(u_texture, u_txCoords); }"; + "void main() { out_FragColor = texture(u_texture, u_txCoords); }"; let txCoords; const um = { @@ -688,7 +688,7 @@ describe( fragmentShaderSource += "uniform sampler2D u_texture;"; fragmentShaderSource += "uniform mediump vec2 u_txCoords;"; fragmentShaderSource += - "void main() { gl_FragColor = texture2D(u_texture, u_txCoords); }"; + "void main() { out_FragColor = texture(u_texture, u_txCoords); }"; let txCoords; const um = { @@ -1468,28 +1468,42 @@ describe( } }); - it("throws when generating mipmaps with a non-power of two width", function () { - texture = new Texture({ - context: context, - width: 3, - height: 2, + describe("WebGL1", function () { + let webgl1Context; + + beforeAll(() => { + webgl1Context = createContext({ + requestWebgl1: true, + }); }); - expect(function () { - texture.generateMipmap(); - }).toThrowDeveloperError(); - }); + afterAll(() => { + webgl1Context.destroyForSpecs(); + }); - it("throws when generating mipmaps with a non-power of two height", function () { - texture = new Texture({ - context: context, - width: 2, - height: 3, + it("throws when generating mipmaps with a non-power of two width", function () { + texture = new Texture({ + context: webgl1Context, + width: 3, + height: 2, + }); + + expect(function () { + texture.generateMipmap(); + }).toThrowDeveloperError(); }); - expect(function () { - texture.generateMipmap(); - }).toThrowDeveloperError(); + it("throws when generating mipmaps with a non-power of two height", function () { + texture = new Texture({ + context: webgl1Context, + width: 2, + height: 3, + }); + + expect(function () { + texture.generateMipmap(); + }).toThrowDeveloperError(); + }); }); it("throws when generating mipmaps with an invalid hint", function () { diff --git a/packages/engine/Specs/Renderer/UniformSpec.js b/packages/engine/Specs/Renderer/UniformSpec.js index 176793c8b16e..a783e1a0bb38 100644 --- a/packages/engine/Specs/Renderer/UniformSpec.js +++ b/packages/engine/Specs/Renderer/UniformSpec.js @@ -33,7 +33,7 @@ describe( const fs = "uniform float u;" + "void main() { " + - " gl_FragColor = vec4(u == 1.0); " + + " out_FragColor = vec4(u == 1.0); " + "}"; expect({ @@ -53,7 +53,7 @@ describe( const fs = "uniform vec2 u;" + "void main() { " + - " gl_FragColor = vec4(u == vec2(0.25, 0.5)); " + + " out_FragColor = vec4(u == vec2(0.25, 0.5)); " + "}"; expect({ @@ -73,7 +73,7 @@ describe( const fs = "uniform vec3 u;" + "void main() { " + - " gl_FragColor = vec4(u == vec3(0.25, 0.5, 0.75)); " + + " out_FragColor = vec4(u == vec3(0.25, 0.5, 0.75)); " + "}"; expect({ @@ -93,7 +93,7 @@ describe( const fs = "uniform vec3 u;" + "void main() { " + - " gl_FragColor = vec4(u == vec3(0.25, 0.5, 0.75)); " + + " out_FragColor = vec4(u == vec3(0.25, 0.5, 0.75)); " + "}"; expect({ @@ -113,7 +113,7 @@ describe( const fs = "uniform vec4 u;" + "void main() { " + - " gl_FragColor = vec4(u == vec4(0.25, 0.5, 0.75, 1.0)); " + + " out_FragColor = vec4(u == vec4(0.25, 0.5, 0.75, 1.0)); " + "}"; expect({ @@ -133,7 +133,7 @@ describe( const fs = "uniform vec4 u;" + "void main() { " + - " gl_FragColor = vec4(u == vec4(0.25, 0.5, 0.75, 1.0)); " + + " out_FragColor = vec4(u == vec4(0.25, 0.5, 0.75, 1.0)); " + "}"; expect({ @@ -153,7 +153,7 @@ describe( const fs = "uniform int u;" + "void main() { " + - " gl_FragColor = vec4(u == 1); " + + " out_FragColor = vec4(u == 1); " + "}"; expect({ @@ -173,7 +173,7 @@ describe( const fs = "uniform ivec2 u;" + "void main() { " + - " gl_FragColor = vec4(u == ivec2(1, 2)); " + + " out_FragColor = vec4(u == ivec2(1, 2)); " + "}"; expect({ @@ -193,7 +193,7 @@ describe( const fs = "uniform ivec3 u;" + "void main() { " + - " gl_FragColor = vec4(u == ivec3(1, 2, 3)); " + + " out_FragColor = vec4(u == ivec3(1, 2, 3)); " + "}"; expect({ @@ -213,7 +213,7 @@ describe( const fs = "uniform ivec4 u;" + "void main() { " + - " gl_FragColor = vec4(u == ivec4(1, 2, 3, 4)); " + + " out_FragColor = vec4(u == ivec4(1, 2, 3, 4)); " + "}"; expect({ @@ -233,7 +233,7 @@ describe( const fs = "uniform bool u;" + "void main() { " + - " gl_FragColor = vec4(u); " + + " out_FragColor = vec4(u); " + "}"; expect({ @@ -253,7 +253,7 @@ describe( const fs = "uniform bvec2 u;" + "void main() { " + - " gl_FragColor = vec4(u == bvec2(true, false)); " + + " out_FragColor = vec4(u == bvec2(true, false)); " + "}"; expect({ @@ -273,7 +273,7 @@ describe( const fs = "uniform bvec3 u;" + "void main() { " + - " gl_FragColor = vec4(u == bvec3(true, false, true)); " + + " out_FragColor = vec4(u == bvec3(true, false, true)); " + "}"; expect({ @@ -293,7 +293,7 @@ describe( const fs = "uniform bvec4 u;" + "void main() { " + - " gl_FragColor = vec4(u == bvec4(true, false, true, false)); " + + " out_FragColor = vec4(u == bvec4(true, false, true, false)); " + "}"; expect({ @@ -313,7 +313,7 @@ describe( const fs = "uniform mat2 u;" + "void main() { " + - " gl_FragColor = vec4(" + + " out_FragColor = vec4(" + " (u[0].x == 1.0) && (u[1].x == 2.0) &&" + " (u[0].y == 3.0) && (u[1].y == 4.0) " + " ); " + @@ -336,7 +336,7 @@ describe( const fs = "uniform mat3 u;" + "void main() { " + - " gl_FragColor = vec4(" + + " out_FragColor = vec4(" + " (u[0].x == 1.0) && (u[1].x == 2.0) && (u[2].x == 3.0) &&" + " (u[0].y == 4.0) && (u[1].y == 5.0) && (u[2].y == 6.0) &&" + " (u[0].z == 7.0) && (u[1].z == 8.0) && (u[2].z == 9.0)" + @@ -377,7 +377,7 @@ describe( const fs = "uniform mat4 u;" + "void main() { " + - " gl_FragColor = vec4(" + + " out_FragColor = vec4(" + " (u[0].x == 1.0) && (u[1].x == 2.0) && (u[2].x == 3.0) && (u[3].x == 4.0) &&" + " (u[0].y == 5.0) && (u[1].y == 6.0) && (u[2].y == 7.0) && (u[3].y == 8.0) &&" + " (u[0].z == 9.0) && (u[1].z == 10.0) && (u[2].z == 11.0) && (u[3].z == 12.0) &&" + @@ -405,13 +405,13 @@ describe( const fs = "uniform struct { float f; vec4 v; } u;" + "void main() { " + - " gl_FragColor = vec4((u.f == 2.5)); " + + " out_FragColor = vec4((u.f == 2.5)); " + "}"; // There appears to be a bug in Chrome on Windows (not in Firefox or IE, or Chrome on Mac). // The following fails since u.v is still (0.0, 0.0, 0.0, 0.0) even after the call to uniform4f. // - // ' gl_FragColor = vec4((u.f == 2.5) && (u.v == vec4(0.25, 0.5, 0.75, 1.0))); ' + // ' out_FragColor = vec4((u.f == 2.5) && (u.v == vec4(0.25, 0.5, 0.75, 1.0))); ' expect({ context: context, @@ -434,7 +434,7 @@ describe( "uniform float u[2];" + "uniform float u2[2];" + "void main() { " + - " gl_FragColor = vec4(" + + " out_FragColor = vec4(" + " (u[0] == 0.25) && (u[1] == 0.5) &&" + " (u2[0] == 1.25) && (u2[1] == 1.5)" + " ); " + @@ -457,7 +457,7 @@ describe( const fs = "uniform vec2 u[2];" + "void main() { " + - " gl_FragColor = vec4(" + + " out_FragColor = vec4(" + " (u[0] == vec2(0.25, 0.5)) &&" + " (u[1] == vec2(1.25, 1.5))" + " ); " + @@ -483,7 +483,7 @@ describe( const fs = "uniform vec3 u[2];" + "void main() { " + - " gl_FragColor = vec4(" + + " out_FragColor = vec4(" + " (u[0] == vec3(0.25, 0.5, 0.75)) &&" + " (u[1] == vec3(1.25, 1.5, 1.75))" + " ); " + @@ -509,7 +509,7 @@ describe( const fs = "uniform vec4 u[2];" + "void main() { " + - " gl_FragColor = vec4(" + + " out_FragColor = vec4(" + " (u[0] == vec4(0.25, 0.5, 0.75, 1.0)) &&" + " (u[1] == vec4(1.25, 1.5, 1.75, 2.0))" + " ); " + @@ -536,7 +536,7 @@ describe( "uniform int u[2];" + "uniform int u2[2];" + "void main() { " + - " gl_FragColor = vec4(" + + " out_FragColor = vec4(" + " (u[0] == 1) && (u[1] == 2) &&" + " (u2[0] == 3) && (u2[1] == 4)" + " ); " + @@ -559,7 +559,7 @@ describe( const fs = "uniform ivec2 u[2];" + "void main() { " + - " gl_FragColor = vec4(" + + " out_FragColor = vec4(" + " (u[0] == ivec2(1, 2)) &&" + " (u[1] == ivec2(3, 4))" + " ); " + @@ -582,7 +582,7 @@ describe( const fs = "uniform ivec3 u[2];" + "void main() { " + - " gl_FragColor = vec4(" + + " out_FragColor = vec4(" + " (u[0] == ivec3(1, 2, 3)) &&" + " (u[1] == ivec3(4, 5, 6))" + " ); " + @@ -605,7 +605,7 @@ describe( const fs = "uniform ivec4 u[2];" + "void main() { " + - " gl_FragColor = vec4(" + + " out_FragColor = vec4(" + " (u[0] == ivec4(1, 2, 3, 4)) &&" + " (u[1] == ivec4(5, 6, 7, 8))" + " ); " + @@ -632,7 +632,7 @@ describe( "uniform bool u[2];" + "uniform bool u2[2];" + "void main() { " + - " gl_FragColor = vec4(" + + " out_FragColor = vec4(" + " u[0] && !u[1] &&" + " !u2[0] && u2[1]" + " ); " + @@ -655,7 +655,7 @@ describe( const fs = "uniform bvec2 u[2];" + "void main() { " + - " gl_FragColor = vec4(" + + " out_FragColor = vec4(" + " (u[0] == bvec2(true, false)) &&" + " (u[1] == bvec2(false, true))" + " ); " + @@ -681,7 +681,7 @@ describe( const fs = "uniform bvec3 u[2];" + "void main() { " + - " gl_FragColor = vec4(" + + " out_FragColor = vec4(" + " (u[0] == bvec3(true, false, true)) &&" + " (u[1] == bvec3(false, true, false))" + " ); " + @@ -707,7 +707,7 @@ describe( const fs = "uniform bvec4 u[2];" + "void main() { " + - " gl_FragColor = vec4(" + + " out_FragColor = vec4(" + " (u[0] == bvec4(true, false, true, false)) &&" + " (u[1] == bvec4(false, true, false, true))" + " ); " + @@ -733,7 +733,7 @@ describe( const fs = "uniform mat2 u[2];" + "void main() { " + - " gl_FragColor = vec4(" + + " out_FragColor = vec4(" + " ((u[0])[0].x == 1.0) && ((u[0])[1].x == 2.0) &&" + " ((u[0])[0].y == 3.0) && ((u[0])[1].y == 4.0) &&" + " ((u[1])[0].x == 5.0) && ((u[1])[1].x == 6.0) &&" + @@ -761,7 +761,7 @@ describe( const fs = "uniform mat3 u[2];" + "void main() { " + - " gl_FragColor = vec4(" + + " out_FragColor = vec4(" + " ((u[0])[0].x == 1.0) && ((u[0])[1].x == 2.0) && ((u[0])[2].x == 3.0) &&" + " ((u[0])[0].y == 4.0) && ((u[0])[1].y == 5.0) && ((u[0])[2].y == 6.0) &&" + " ((u[0])[0].z == 7.0) && ((u[0])[1].z == 8.0) && ((u[0])[2].z == 9.0) &&" + @@ -825,7 +825,7 @@ describe( const fs = "uniform mat4 u[2];" + "void main() { " + - " gl_FragColor = vec4(" + + " out_FragColor = vec4(" + " ((u[0])[0].x == 1.0) && ((u[0])[1].x == 2.0) && ((u[0])[2].x == 3.0) && ((u[0])[3].x == 4.0) &&" + " ((u[0])[0].y == 5.0) && ((u[0])[1].y == 6.0) && ((u[0])[2].y == 7.0) && ((u[0])[3].y == 8.0) &&" + " ((u[0])[0].z == 9.0) && ((u[0])[1].z == 10.0) && ((u[0])[2].z == 11.0) && ((u[0])[3].z == 12.0) &&" + diff --git a/packages/engine/Specs/Renderer/VertexArrayFactorySpec.js b/packages/engine/Specs/Renderer/VertexArrayFactorySpec.js index e9d3102051b2..d0042e076c39 100644 --- a/packages/engine/Specs/Renderer/VertexArrayFactorySpec.js +++ b/packages/engine/Specs/Renderer/VertexArrayFactorySpec.js @@ -357,19 +357,19 @@ describe( // Validate via rendering const vs = - "attribute float bytes; " + - "attribute float shorts; " + - "attribute float floats; " + - "varying vec4 fsColor; " + + "in float bytes; " + + "in float shorts; " + + "in float floats; " + + "out vec4 fsColor; " + "void main() { " + " gl_PointSize = 1.0; " + " gl_Position = vec4(0.0, 0.0, 0.0, 1.0); " + " fsColor = vec4((bytes == 0.0) && (shorts == 1.0) && (floats == 2.0)); " + "}"; const fs = - "varying vec4 fsColor; " + + "in vec4 fsColor; " + "void main() { " + - " gl_FragColor = fsColor; " + + " out_FragColor = fsColor; " + "}"; sp = ShaderProgram.fromCache({ @@ -423,18 +423,18 @@ describe( // Validate via rendering const vs = - "attribute vec3 position; " + - "attribute vec4 color; " + - "varying vec4 fsColor; " + + "in vec3 position; " + + "in vec4 color; " + + "out vec4 fsColor; " + "void main() { " + " gl_PointSize = 1.0; " + " gl_Position = vec4(position, 1.0); " + " fsColor = color; " + "}"; const fs = - "varying vec4 fsColor; " + + "in vec4 fsColor; " + "void main() { " + - " gl_FragColor = fsColor; " + + " out_FragColor = fsColor; " + "}"; sp = ShaderProgram.fromCache({ context: context, @@ -509,20 +509,20 @@ describe( // Validate via rendering const vs = - "attribute vec2 unsignedByteAttribute; " + - "attribute float unsignedShortAttribute; " + - "attribute float byteAttribute; " + - "attribute float shortAttribute; " + - "varying vec4 fsColor; " + + "in vec2 unsignedByteAttribute; " + + "in float unsignedShortAttribute; " + + "in float byteAttribute; " + + "in float shortAttribute; " + + "out vec4 fsColor; " + "void main() { " + " gl_PointSize = 1.0; " + " gl_Position = vec4(0.0, 0.0, 0.0, 1.0); " + " fsColor = vec4((unsignedByteAttribute.x == 1.0) && (unsignedByteAttribute.y == 2.0) && (unsignedShortAttribute == 3.0) && (byteAttribute == 4.0) && (shortAttribute == 5.0)); " + "}"; const fs = - "varying vec4 fsColor; " + + "in vec4 fsColor; " + "void main() { " + - " gl_FragColor = fsColor; " + + " out_FragColor = fsColor; " + "}"; sp = ShaderProgram.fromCache({ context: context, @@ -585,11 +585,11 @@ describe( // Validate via rendering const vs = - "attribute vec3 position; " + - "attribute vec3 color; " + - "attribute vec3 normal; " + - "attribute float temperature; " + - "varying vec4 fsColor; " + + "in vec3 position; " + + "in vec3 color; " + + "in vec3 normal; " + + "in float temperature; " + + "out vec4 fsColor; " + "void main() { " + " gl_PointSize = 1.0; " + " gl_Position = vec4(position, 1.0); " + @@ -601,9 +601,9 @@ describe( " }" + "}"; const fs = - "varying vec4 fsColor; " + + "in vec4 fsColor; " + "void main() { " + - " gl_FragColor = fsColor; " + + " out_FragColor = fsColor; " + "}"; sp = ShaderProgram.fromCache({ context: context, @@ -626,11 +626,11 @@ describe( expect(context).toReadPixels([255, 0, 0, 255]); const vs2 = - "attribute vec3 position; " + - "attribute vec3 color; " + - "attribute vec3 normal; " + - "attribute float temperature; " + - "varying vec4 fsColor; " + + "in vec3 position; " + + "in vec3 color; " + + "in vec3 normal; " + + "in float temperature; " + + "out vec4 fsColor; " + "void main() { " + " gl_PointSize = 1.0; " + " gl_Position = vec4(position, 1.0); " + diff --git a/packages/engine/Specs/Renderer/VertexArraySpec.js b/packages/engine/Specs/Renderer/VertexArraySpec.js index 9eeb5b69faf7..f9dd7f36f8dc 100644 --- a/packages/engine/Specs/Renderer/VertexArraySpec.js +++ b/packages/engine/Specs/Renderer/VertexArraySpec.js @@ -239,16 +239,16 @@ describe( it("renders with a one-component constant value", function () { const vs = - "attribute float firefoxWorkaround;" + - "attribute float attr;" + - "varying vec4 v_color;" + + "in float firefoxWorkaround;" + + "in float attr;" + + "out vec4 v_color;" + "void main() { " + " v_color = vec4(attr == 0.5) + vec4(firefoxWorkaround);" + " gl_PointSize = 1.0;" + " gl_Position = vec4(0.0, 0.0, 0.0, 1.0);" + "}"; const fs = - "varying vec4 v_color;" + "void main() { gl_FragColor = v_color; }"; + "in vec4 v_color;" + "void main() { out_FragColor = v_color; }"; let sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -292,16 +292,16 @@ describe( it("renders with a two-component constant value", function () { const vs = - "attribute float firefoxWorkaround;" + - "attribute vec2 attr;" + - "varying vec4 v_color;" + + "in float firefoxWorkaround;" + + "in vec2 attr;" + + "out vec4 v_color;" + "void main() { " + " v_color = vec4(attr == vec2(0.25, 0.75)) + vec4(firefoxWorkaround);" + " gl_PointSize = 1.0;" + " gl_Position = vec4(0.0, 0.0, 0.0, 1.0);" + "}"; const fs = - "varying vec4 v_color;" + "void main() { gl_FragColor = v_color; }"; + "in vec4 v_color;" + "void main() { out_FragColor = v_color; }"; let sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -345,16 +345,16 @@ describe( it("renders with a three-component constant value", function () { const vs = - "attribute float firefoxWorkaround;" + - "attribute vec3 attr;" + - "varying vec4 v_color;" + + "in float firefoxWorkaround;" + + "in vec3 attr;" + + "out vec4 v_color;" + "void main() { " + " v_color = vec4(attr == vec3(0.25, 0.5, 0.75)) + vec4(firefoxWorkaround);" + " gl_PointSize = 1.0;" + " gl_Position = vec4(0.0, 0.0, 0.0, 1.0);" + "}"; const fs = - "varying vec4 v_color;" + "void main() { gl_FragColor = v_color; }"; + "in vec4 v_color;" + "void main() { out_FragColor = v_color; }"; let sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -398,16 +398,16 @@ describe( it("renders with a four-component constant value", function () { const vs = - "attribute float firefoxWorkaround;" + - "attribute vec4 attr;" + - "varying vec4 v_color;" + + "in float firefoxWorkaround;" + + "in vec4 attr;" + + "out vec4 v_color;" + "void main() { " + " v_color = vec4(attr == vec4(0.2, 0.4, 0.6, 0.8)) + vec4(firefoxWorkaround);" + " gl_PointSize = 1.0;" + " gl_Position = vec4(0.0, 0.0, 0.0, 1.0);" + "}"; const fs = - "varying vec4 v_color;" + "void main() { gl_FragColor = v_color; }"; + "in vec4 v_color;" + "void main() { out_FragColor = v_color; }"; let sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, @@ -451,9 +451,9 @@ describe( it("renders two vertex arrays with constant values", function () { const vs = - "attribute float firefoxWorkaround;" + - "attribute vec4 attr;" + - "varying vec4 v_color;" + + "in float firefoxWorkaround;" + + "in vec4 attr;" + + "out vec4 v_color;" + "void main() { " + " v_color = attr + vec4(firefoxWorkaround);" + " gl_PointSize = 1.0;" + @@ -461,7 +461,7 @@ describe( "}"; const fs = - "varying vec4 v_color;" + "void main() { gl_FragColor = v_color; }"; + "in vec4 v_color;" + "void main() { out_FragColor = v_color; }"; let sp = ShaderProgram.fromCache({ context: context, @@ -871,12 +871,15 @@ describe( }); it("throws when instanceDivisor is greater than zero and instancing is disabled", function () { + const contextWithoutInstancing = createContext({ + requestWebgl1: true, + }); + // disable extension - const instancedArrays = context._instancedArrays; - context._instancedArrays = undefined; + contextWithoutInstancing._instancedArrays = undefined; const buffer = Buffer.createVertexBuffer({ - context: context, + context: contextWithoutInstancing, sizeInBytes: 3, usage: BufferUsage.STATIC_DRAW, }); @@ -897,11 +900,12 @@ describe( expect(function () { return new VertexArray({ - context: context, + context: contextWithoutInstancing, attributes: attributes, }); }).toThrowDeveloperError(); - context._instancedArrays = instancedArrays; + + contextWithoutInstancing.destroyForSpecs(); }); }, "WebGL" diff --git a/packages/engine/Specs/Renderer/demodernizeShaderSpec.js b/packages/engine/Specs/Renderer/demodernizeShaderSpec.js new file mode 100644 index 000000000000..3eca6c16b14b --- /dev/null +++ b/packages/engine/Specs/Renderer/demodernizeShaderSpec.js @@ -0,0 +1,146 @@ +import { demodernizeShader } from "../../index.js"; + +describe("Renderer/demodernizeShader", () => { + it("replaces version", () => { + const input = `#version 300 es + void main() {} + `; + + const output = demodernizeShader(input, false); + const expectedVersion = "#version 100"; + + expect(output.startsWith(expectedVersion)).toEqual(true); + }); + + it("replaces out_FragData with gl_FragData", () => { + const input = `#version 300 es + layout (location = 0) vec4 out_FragData_0; + layout (location = 1) vec4 out_FragData_1; + layout (location = 10) vec4 out_FragData_10; + layout (location = 11) vec4 out_FragData_11; + + void main() { + out_FragData_0 = vec4(0.0); + out_FragData_1 = vec4(1.0); + out_FragData_10 = vec4(0.0, 0.0, 0.0, 0.0); + out_FragData_11 = vec4(1.0, 2.0, 3.0, 4.0); + } + `; + + const output = demodernizeShader(input, true); + + const expectedVersion = "#version 100"; + expect(output.startsWith(expectedVersion)).toEqual(true); + expect(output).not.toContain("layout (location = 0) vec4 out_FragData_0"); + expect(output).not.toContain("layout (location = 1) vec4 out_FragData_1"); + expect(output).not.toContain("layout (location = 10) vec4 out_FragData_10"); + expect(output).not.toContain("layout (location = 11) vec4 out_FragData_11"); + expect(output).toContain("gl_FragData[0] = vec4(0.0);"); + expect(output).toContain("gl_FragData[1] = vec4(1.0);"); + expect(output).toContain("gl_FragData[10] = vec4(0.0, 0.0, 0.0, 0.0);"); + expect(output).toContain("gl_FragData[11] = vec4(1.0, 2.0, 3.0, 4.0);"); + }); + + it("replaces out_FragColor with gl_FragColor", () => { + const input = `#version 300 es + layout (location = 0) vec4 out_FragColor; + + void main() { + out_FragColor = vec4(1.0); + out_FragColor[0] = 0.0; + out_FragColor[2] = 2.0; + } + `; + const output = demodernizeShader(input, true); + + const expectedVersion = "#version 100"; + + expect(output.startsWith(expectedVersion)).toEqual(true); + expect(output).not.toContain("layout (location = 0) vec4 out_FragColor"); + expect(output).toContain("gl_FragColor = vec4(1.0);"); + expect(output).toContain("gl_FragColor[0] = 0.0;"); + expect(output).toContain("gl_FragColor[2] = 2.0;"); + }); + + it("replaces texture with texture2D", () => { + const input = `#version 300 es + uniform sampler2D u_texture; + void main() { + vec4 tex = texture(u_texture, vec2(0.0)); + } + `; + const output = demodernizeShader(input, false); + + const expectedVersion = "#version 100"; + expect(output.startsWith(expectedVersion)).toEqual(true); + + expect(output).toContain("vec4 tex = texture2D(u_texture, vec2(0.0));"); + }); + + it("replaces in with attribute in vertex shader", () => { + const input = `#version 300 es + in float a_float; + in vec3 a_vec3; + in mat2 a_mat2; + void main() {} + `; + const output = demodernizeShader(input, false); + + const expectedVersion = "#version 100"; + expect(output.startsWith(expectedVersion)).toEqual(true); + + expect(output).toContain("attribute float a_float;"); + expect(output).toContain("attribute vec3 a_vec3;"); + expect(output).toContain("attribute mat2 a_mat2;"); + }); + + it("replaces in with varying in fragment shader", () => { + const input = `#version 300 es + in float a_float; + in vec3 a_vec3; + in mat2 a_mat2; + void main() {} + `; + const output = demodernizeShader(input, true); + + const expectedVersion = "#version 100"; + expect(output.startsWith(expectedVersion)).toEqual(true); + + expect(output).toContain("varying float a_float;"); + expect(output).toContain("varying vec3 a_vec3;"); + expect(output).toContain("varying mat2 a_mat2;"); + }); + + it("replaces out with varying in vertex shader", () => { + const input = `#version 300 es + out float a_float; + out vec3 a_vec3; + out mat2 a_mat2; + void main() {} + `; + const output = demodernizeShader(input, false); + + const expectedVersion = "#version 100"; + expect(output.startsWith(expectedVersion)).toEqual(true); + + expect(output).toContain("varying float a_float;"); + expect(output).toContain("varying vec3 a_vec3;"); + expect(output).toContain("varying mat2 a_mat2;"); + }); + + it("replaces gl_FragDepth with gl_FragDepthEXT", () => { + const input = `#version 300 es + void main() { + gl_FragDepth = vec4(1.0); + gl_FragDepth += vec4(2.0); + } + `; + const output = demodernizeShader(input, true); + + const expectedVersion = "#version 100"; + expect(output.startsWith(expectedVersion)).toEqual(true); + expect(output).toContain("#extension GL_EXT_frag_depth : enable"); + expect(output).toContain("gl_FragDepthEXT = vec4(1.0);"); + expect(output).toContain("gl_FragDepthEXT += vec4(2.0);"); + }); +}); diff --git a/packages/engine/Specs/Renderer/loadCubeMapSpec.js b/packages/engine/Specs/Renderer/loadCubeMapSpec.js index 1c396dd288cb..de41c7154dfa 100644 --- a/packages/engine/Specs/Renderer/loadCubeMapSpec.js +++ b/packages/engine/Specs/Renderer/loadCubeMapSpec.js @@ -37,11 +37,11 @@ describe( expect(cm.height).toEqual(1); const vs = - "attribute vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; + "in vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }"; const fs = "uniform samplerCube u_texture;" + "uniform mediump vec3 u_direction;" + - "void main() { gl_FragColor = textureCube(u_texture, normalize(u_direction)); }"; + "void main() { out_FragColor = czm_textureCube(u_texture, normalize(u_direction)); }"; const sp = ShaderProgram.fromCache({ context: context, vertexShaderSource: vs, diff --git a/packages/engine/Specs/Renderer/modernizeShaderSpec.js b/packages/engine/Specs/Renderer/modernizeShaderSpec.js deleted file mode 100644 index 40a0ca9f55ec..000000000000 --- a/packages/engine/Specs/Renderer/modernizeShaderSpec.js +++ /dev/null @@ -1,353 +0,0 @@ -import { modernizeShader } from "../../index.js"; - -describe("Renderer/modernizeShader", function () { - it("adds version string", function () { - const simple = - "#define OUTPUT_DECLARATION \n" + "void main() \n" + "{ \n" + "} \n"; - const output = modernizeShader(simple, true); - const expected = "#version 300 es\n#define WEBGL_2"; - expect(output.startsWith(expected)).toBe(true); - }); - - it("replace existing version string", function () { - const simple = - "#version 200 es" + - "#define OUTPUT_DECLARATION \n" + - "void main() \n" + - "{ \n" + - "} \n"; - const output = modernizeShader(simple, true); - const expected = "#version 300 es\n#define WEBGL_2"; - expect(output.startsWith(expected)).toBe(true); - }); - - it("removes extensions", function () { - const extensions = - "#define OUTPUT_DECLARATION \n" + - "#extension GL_EXT_draw_buffers : enable \n" + - "void main() \n" + - "{ \n" + - "} \n"; - const output = modernizeShader(extensions, true); - const notExpected = "#extension GL_EXT_draw_buffers : enable \n"; - expect(output).not.toContain(notExpected); - }); - - it("replace extension macro check with WEBGL_2", function () { - const extensions = - "#define OUTPUT_DECLARATION \n" + - "#extension GL_EXT_draw_buffers : enable \n" + - "void main() \n" + - "{ \n" + - " #ifdef GL_EXT_draw_buffers\n" + - " #endif //GL_EXT_draw_buffers\n" + - " #if defined(GL_EXT_draw_buffers)\n" + - " #endif //GL_EXT_draw_buffers\n" + - "} \n"; - const output = modernizeShader(extensions, true); - const notExpected = "#extension GL_EXT_draw_buffers : enable \n"; - const expected = - " #ifdef WEBGL_2\n" + - " #endif //WEBGL_2\n" + - " #if defined(WEBGL_2)\n" + - " #endif //WEBGL_2\n"; - expect(output).not.toContain(notExpected); - expect(output).toContain(expected); - }); - - it("throws exception if no output declaration", function () { - const noOutputDeclaration = "void main() \n" + "{ \n" + "} \n"; - const runFunc = function () { - modernizeShader(noOutputDeclaration, true); - }; - expect(runFunc).toThrowDeveloperError(); - }); - - it("creates layout qualifier for gl_FragColor", function () { - const noQualifiers = - "#define OUTPUT_DECLARATION \n" + - "void main() \n" + - "{ \n" + - " gl_FragColor = vec4(0.0); \n" + - "} \n"; - const output = modernizeShader(noQualifiers, true); - const expected = "layout(location = 0) out vec4 czm_fragColor;"; - expect(output).toContain(expected); - }); - - it("creates layout qualifier for gl_FragData", function () { - const noQualifiers = - "#define OUTPUT_DECLARATION \n" + - "void main() \n" + - "{ \n" + - " gl_FragData[0] = vec4(0.0); \n" + - "} \n"; - const output = modernizeShader(noQualifiers, true); - const expected = "layout(location = 0) out vec4 czm_out0;"; - expect(output).toContain(expected); - }); - - it("creates layout qualifier for MRT", function () { - const noQualifiers = - "#define OUTPUT_DECLARATION \n" + - "#extension GL_EXT_draw_buffers : enable \n" + - "void main() \n" + - "{ \n" + - " gl_FragData[0] = vec4(0.0); \n" + - " gl_FragData[1] = vec4(1.0); \n" + - "} \n"; - const output = modernizeShader(noQualifiers, true); - const expected0 = "layout(location = 0) out vec4 czm_out0;"; - const expected1 = "layout(location = 1) out vec4 czm_out1;"; - expect(output).toContain(expected0); - expect(output).toContain(expected1); - }); - - it("does not create layout qualifier for reserved word lookalike variables", function () { - const noQualifiers = - "#define OUTPUT_DECLARATION \n" + - "uniform sampler2D example; \n" + - "void main() \n" + - "{ \n" + - " vec4 gl_FragData_ = vec4(0.0); \n" + - " vec4 a_gl_FragData = vec4(0.0); \n" + - " vec2 thisIsNotAGoodNameForAtexture2D = vec2(0.0); \n" + - " vec4 gl_FragColor = texture2D(example, thisIsNotAGoodNameForAtexture2D); \n" + - "} \n"; - const output = modernizeShader(noQualifiers, true); - const expectedBadName = "vec2 thisIsNotAGoodNameForAtexture2D"; - const expectedVariable = "vec4 a_gl_FragData = vec4(0.0);"; - const expectedTextureCall = - "texture(example, thisIsNotAGoodNameForAtexture2D)"; - const notExpectedLayout = "layout(location = 0) out czm_out"; - expect(output).toContain(expectedBadName); - expect(output).toContain(expectedVariable); - expect(output).toContain(expectedTextureCall); - expect(output).not.toContain(notExpectedLayout); - }); - - it("creates layout qualifier with swizzle", function () { - const noQualifiers = - "#define OUTPUT_DECLARATION \n" + - "#extension GL_EXT_draw_buffers : enable \n" + - "void main() \n" + - "{ \n" + - " gl_FragData[0] = vec4(0.0); \n" + - " gl_FragData[1].xyz = vec3(1.0); \n" + - "} \n"; - const output = modernizeShader(noQualifiers, true); - const expected0 = "layout(location = 0) out vec4 czm_out0;"; - const expected1 = "layout(location = 1) out vec4 czm_out1;"; - expect(output).toContain(expected0); - expect(output).toContain(expected1); - }); - - it("removes old functions/variables from fragment shader", function () { - const old_fragment = - "#define OUTPUT_DECLARATION \n" + - "#extension GL_EXT_draw_buffers : enable \n" + - "uniform sampler2D example; \n" + - "uniform sampler2D exampleCube; \n" + - "uniform sampler2D example3D; \n" + - "varying vec2 v_textureCoordinates; \n" + - "void main() \n" + - "{ \n" + - " gl_FragData[0] = texture2D(example, v_textureCoordinates); \n" + - " gl_FragData[1] = textureCube(exampleCube, v_textureCoordinates); \n" + - " gl_FragData[2] = texture3D(example3D, v_textureCoordinates); \n" + - " gl_FragDepthEXT = 0.0; \n" + - "} \n"; - - const output = modernizeShader(old_fragment, true); - - const expectedDepth = "gl_FragDepth = 0.0;"; - const expectedTexture2D = "texture(example, v_textureCoordinates);"; - const expectedTextureCube = "texture(exampleCube, v_textureCoordinates);"; - const expectedTexture3D = "texture(example3D, v_textureCoordinates);"; - const expectedIn = "in vec2 v_textureCoordinates;"; - - const notExpectedDepth = "gl_FragDepthEXT = 0.0;"; - const notExpectedTexture2D = "texture2D(example, v_textureCoordinates);"; - const notExpectedTextureCube = - "textureCube(exampleCube, v_textureCoordinates);"; - const notExpectedTexture3D = "texture3D(example3D, v_textureCoordinates);"; - const notExpectedVarying = "varying vec2 v_textureCoordinates;"; - - expect(output).toContain(expectedDepth); - expect(output).toContain(expectedTexture2D); - expect(output).toContain(expectedTextureCube); - expect(output).toContain(expectedTexture3D); - expect(output).toContain(expectedIn); - - expect(output).not.toContain(notExpectedDepth); - expect(output).not.toContain(notExpectedTexture2D); - expect(output).not.toContain(notExpectedTextureCube); - expect(output).not.toContain(notExpectedTexture3D); - expect(output).not.toContain(notExpectedVarying); - }); - - it("removes old functions/variables from vertex shader", function () { - const old_vertex = - "#define OUTPUT_DECLARATION \n" + - "attribute vec4 position; \n" + - "varying vec4 varyingVariable; \n" + - "void main() \n" + - "{ \n" + - " gl_Position = position; \n" + - " varyingVariable = position.wzyx; \n" + - "} \n"; - - const output = modernizeShader(old_vertex, false); - - const expectedOut = "out vec4 varyingVariable;"; - const expectedIn = "in vec4 position;"; - - const notExpectedAttribute = "attribute vec4 varyingVariable;"; - const notExpectedVarying = "varying vec2 varyingVariable;"; - - expect(output).toContain(expectedOut); - expect(output).toContain(expectedIn); - - expect(output).not.toContain(notExpectedAttribute); - expect(output).not.toContain(notExpectedVarying); - }); - - it("creates single layout qualifier under single branch, single condition", function () { - const noQualifiers = - "#define OUTPUT_DECLARATION \n" + - "#define EXAMPLE_BRANCH \n" + - "void main() \n" + - "{ \n" + - " #ifdef EXAMPLE_BRANCH \n" + - " gl_FragData[0] = vec4(0.0); \n" + - " #endif //EXAMPLE_BRANCH \n" + - "} \n"; - const output = modernizeShader(noQualifiers, true); - const expected = - "#ifdef EXAMPLE_BRANCH \nlayout(location = 0) out vec4 czm_out0;\n#endif"; - expect(output).toContain(expected); - }); - - it("creates multiple layout qualifiers under single branch, single condition", function () { - const noQualifiers = - "#define OUTPUT_DECLARATION \n" + - "#define EXAMPLE_BRANCH \n" + - "void main() \n" + - "{ \n" + - " #ifdef EXAMPLE_BRANCH \n" + - " gl_FragData[0] = vec4(0.0); \n" + - " gl_FragData[1] = vec4(1.0); \n" + - " #endif //EXAMPLE_BRANCH \n" + - "} \n"; - const output = modernizeShader(noQualifiers, true); - const expected0 = - "#ifdef EXAMPLE_BRANCH \nlayout(location = 0) out vec4 czm_out0;\n#endif"; - const expected1 = - "#ifdef EXAMPLE_BRANCH \nlayout(location = 1) out vec4 czm_out1;\n#endif"; - expect(output).toContain(expected0); - expect(output).toContain(expected1); - }); - - it("creates multiple layout qualifiers under multiple branches, single condition (cancels)", function () { - const noQualifiers = - "#define OUTPUT_DECLARATION \n" + - "#define EXAMPLE_BRANCH \n" + - "void main() \n" + - "{ \n" + - " #ifdef EXAMPLE_BRANCH \n" + - " gl_FragData[0] = vec4(0.0); \n" + - " gl_FragData[1] = vec4(1.0); \n" + - " #endif //EXAMPLE_BRANCH \n" + - " #ifndef EXAMPLE_BRANCH \n" + - " gl_FragData[0] = vec4(0.0); \n" + - " gl_FragData[1] = vec4(1.0); \n" + - " #endif //!EXAMPLE_BRANCH \n" + - "} \n"; - const output = modernizeShader(noQualifiers, true); - const notExpected = - "#ifdef EXAMPLE_BRANCH \nlayout(location = 0) out vec4 czm_out0;\n#endif"; - expect(output).not.toContain(notExpected); - }); - - it("creates single layout qualifier under multiple branches, multiple conditions (cancels)", function () { - const noQualifiers = - "#define OUTPUT_DECLARATION \n" + - "#define EXAMPLE_BRANCH \n" + - "#define EXAMPLE_BRANCH1 \n" + - "void main() \n" + - "{ \n" + - " #ifdef EXAMPLE_BRANCH \n" + - " gl_FragData[0] = vec4(0.0); \n" + - " #endif //EXAMPLE_BRANCH \n" + - " #ifdef EXAMPLE_BRANCH1 \n" + - " gl_FragData[0] = vec4(0.0); \n" + - " #endif //EXAMPLE_BRANCH1 \n" + - "} \n"; - const output = modernizeShader(noQualifiers, true); - const notExpected = - "#ifdef EXAMPLE_BRANCH \nlayout(location = 0) out vec4 czm_out0;\n#endif"; - expect(output).not.toContain(notExpected); - }); - - it("creates multiple layout qualifiers under multiple branches, multiple conditions (cascades)", function () { - const noQualifiers = - "#define OUTPUT_DECLARATION \n" + - "#define EXAMPLE_BRANCH \n" + - "#define EXAMPLE_BRANCH1 \n" + - "void main() \n" + - "{ \n" + - " #ifdef EXAMPLE_BRANCH \n" + - " gl_FragData[0] = vec4(0.0); \n" + - " #ifdef EXAMPLE_BRANCH1 \n" + - " gl_FragData[1] = vec4(1.0); \n" + - " #endif //EXAMPLE_BRANCH1 \n" + - " #endif //EXAMPLE_BRANCH \n" + - "} \n"; - const output = modernizeShader(noQualifiers, true); - const expected0 = - "#ifdef EXAMPLE_BRANCH \nlayout(location = 0) out vec4 czm_out0;\n#endif"; - const expected1 = /#ifdef (EXAMPLE_BRANCH|EXAMPLE_BRANCH1)\s*\n\s*#ifdef (EXAMPLE_BRANCH1|EXAMPLE_BRANCH)\s*\n\s*layout\(location = 1\) out vec4 czm_out1;/g; - const containsExpected0 = expected1.test(output); - expect(output).toContain(expected0); - expect(containsExpected0).toBe(true); - }); - - it("creates single layout qualifier under multiple branches, single condition (else)", function () { - const noQualifiers = - "#define OUTPUT_DECLARATION \n" + - "#define EXAMPLE_BRANCH \n" + - "void main() \n" + - "{ \n" + - " #ifdef EXAMPLE_BRANCH \n" + - " gl_FragData[0] = vec4(0.0); \n" + - " #else \n" + - " gl_FragData[0] = vec4(1.0); \n" + - " #endif //EXAMPLE_BRANCH \n" + - "} \n"; - const output = modernizeShader(noQualifiers, true); - const notExpected = - "#ifdef EXAMPLE_BRANCH \nlayout(location = 0) out vec4 czm_out0;\n#endif"; - expect(output).not.toContain(notExpected); - }); - - it("creates branched layout qualifiers for gl_FragColor and gl_FragData", function () { - const noQualifiers = - "#define OUTPUT_DECLARATION \n" + - "#define EXAMPLE_BRANCH \n" + - "void main() \n" + - "{ \n" + - " #ifdef EXAMPLE_BRANCH \n" + - " gl_FragData[0] = vec4(0.0); \n" + - " #else \n" + - " gl_FragColor = vec4(1.0); \n" + - " #endif //EXAMPLE_BRANCH \n" + - "} \n"; - const output = modernizeShader(noQualifiers, true); - const expected0 = - "#ifdef EXAMPLE_BRANCH \nlayout(location = 0) out vec4 czm_out0;\n#endif"; - const expected1 = - "#ifndef EXAMPLE_BRANCH \nlayout(location = 0) out vec4 czm_fragColor;\n#endif"; - expect(output).toContain(expected0); - expect(output).toContain(expected1); - }); -}); diff --git a/packages/engine/Specs/Scene/AppearanceSpec.js b/packages/engine/Specs/Scene/AppearanceSpec.js index df8624c874ba..05cd5876c728 100644 --- a/packages/engine/Specs/Scene/AppearanceSpec.js +++ b/packages/engine/Specs/Scene/AppearanceSpec.js @@ -9,18 +9,18 @@ describe("Scene/Appearance", function () { it("constructor", function () { const material = Material.fromType("Color"); const vs = - "attribute vec3 position3DHigh;\n" + - "attribute vec3 position3DLow;\n" + - "attribute vec4 color;\n" + - "varying vec4 v_color;\n" + + "in vec3 position3DHigh;\n" + + "in vec3 position3DLow;\n" + + "in vec4 color;\n" + + "out vec4 v_color;\n" + "void main() {\n" + " gl_Position = czm_modelViewProjectionRelativeToEye * czm_computePosition();\n" + " v_color = color;\n" + "}\n"; const fs = - "varying vec4 v_color;\n" + + "in vec4 v_color;\n" + "void main() {\n" + - " gl_FragColor = v_color;\n" + + " out_FragColor = v_color;\n" + "}\n"; const renderState = { depthTest: { @@ -46,9 +46,9 @@ describe("Scene/Appearance", function () { it("getFragmentShaderSource", function () { const fs = - "varying vec4 v_color;\n" + + "out vec4 v_color;\n" + "void main() {\n" + - " gl_FragColor = v_color;\n" + + " out_FragColor = v_color;\n" + "}\n"; const appearance = new Appearance({ fragmentShaderSource: fs, @@ -62,9 +62,9 @@ describe("Scene/Appearance", function () { it("getFragmentShaderSource with material", function () { const material = Material.fromType("Color"); const fs = - "varying vec4 v_color;\n" + + "in vec4 v_color;\n" + "void main() {\n" + - " gl_FragColor = v_color;\n" + + " out_FragColor = v_color;\n" + "}\n"; const appearance = new Appearance({ material: material, diff --git a/packages/engine/Specs/Scene/GlobeTranslucencyStateSpec.js b/packages/engine/Specs/Scene/GlobeTranslucencyStateSpec.js index 2c1421a1b8b7..61a65cd7420f 100644 --- a/packages/engine/Specs/Scene/GlobeTranslucencyStateSpec.js +++ b/packages/engine/Specs/Scene/GlobeTranslucencyStateSpec.js @@ -44,7 +44,7 @@ function reset() { function createShaderProgram(colorString) { const vs = "void main() { gl_Position = vec4(0.0, 0.0, 0.0, 1.0); }"; - const fs = `void main() { gl_FragColor = vec4(${colorString}); }`; + const fs = `void main() { out_FragColor = vec4(${colorString}); }`; const vertexShaderSource = new ShaderSource({ sources: [vs], diff --git a/packages/engine/Specs/Scene/GltfLoaderSpec.js b/packages/engine/Specs/Scene/GltfLoaderSpec.js index 4ab49554fd17..c71546619a55 100644 --- a/packages/engine/Specs/Scene/GltfLoaderSpec.js +++ b/packages/engine/Specs/Scene/GltfLoaderSpec.js @@ -2175,7 +2175,11 @@ describe( beforeAll(function () { // Disable instancing extension. - sceneWithNoInstancing = createScene(); + sceneWithNoInstancing = createScene({ + contextOptions: { + requestWebgl1: true, + }, + }); sceneWithNoInstancing.context._instancedArrays = undefined; }); @@ -2495,7 +2499,7 @@ describe( }); }); - it("loads BoxInstanced when WebGL instancing is disabled", function () { + it("loads BoxInstanced when WebGL instancing is disabled on WebGL 1", function () { const options = { scene: sceneWithNoInstancing, }; @@ -3426,20 +3430,24 @@ describe( }); describe("loadIndicesForWireframe", function () { - let sceneWithWebgl2; + let sceneWithWebgl1; beforeAll(function () { - sceneWithWebgl2 = createScene(); - sceneWithWebgl2.context._webgl2 = true; + sceneWithWebgl1 = createScene({ + contextOptions: { + requestWebgl1: true, + }, + }); }); afterAll(function () { - sceneWithWebgl2.destroyForSpecs(); + sceneWithWebgl1.destroyForSpecs(); }); it("loads indices in buffer and typed array for wireframes in WebGL1", function () { return loadGltf(triangle, { loadIndicesForWireframe: true, + scene: sceneWithWebgl1, }).then(function (gltfLoader) { const components = gltfLoader.components; const scene = components.scene; @@ -3463,9 +3471,12 @@ describe( }); it("loads indices in buffer only for wireframes in WebGL2", function () { + const customScene = createScene(); + customScene.context._webgl2 = true; + return loadGltf(triangle, { loadIndicesForWireframe: true, - scene: sceneWithWebgl2, + scene: customScene, }).then(function (gltfLoader) { const components = gltfLoader.components; const scene = components.scene; @@ -3485,6 +3496,8 @@ describe( expect(primitive.indices.count).toBe(3); expect(primitive.indices.typedArray).not.toBeDefined(); expect(primitive.indices.buffer).toBeDefined(); + + customScene.destroyForSpecs(); }); }); }); diff --git a/packages/engine/Specs/Scene/MaterialSpec.js b/packages/engine/Specs/Scene/MaterialSpec.js index f473da322542..53b0148ca38a 100644 --- a/packages/engine/Specs/Scene/MaterialSpec.js +++ b/packages/engine/Specs/Scene/MaterialSpec.js @@ -410,7 +410,7 @@ describe( "czm_material czm_getMaterial(czm_materialInput materialInput)\n" + "{\n" + " czm_material material = czm_getDefaultMaterial(materialInput);\n" + - " material.diffuse = textureCube(cubeMap, vec3(1.0)).xyz;\n" + + " material.diffuse = czm_textureCube(cubeMap, vec3(1.0)).xyz;\n" + " return material;\n" + "}\n", }, @@ -437,7 +437,7 @@ describe( "czm_material czm_getMaterial(czm_materialInput materialInput)\r\n" + "{\r\n" + " czm_material material = czm_getDefaultMaterial(materialInput);\r\n" + - " material.diffuse = textureCube(cubeMap, vec3(1.0)).xyz;\r\n" + + " material.diffuse = czm_textureCube(cubeMap, vec3(1.0)).xyz;\r\n" + " return material;\r\n" + "}", }, diff --git a/packages/engine/Specs/Scene/Model/CustomShaderPipelineStageSpec.js b/packages/engine/Specs/Scene/Model/CustomShaderPipelineStageSpec.js index 1eb461cdc999..cf674eee8c16 100644 --- a/packages/engine/Specs/Scene/Model/CustomShaderPipelineStageSpec.js +++ b/packages/engine/Specs/Scene/Model/CustomShaderPipelineStageSpec.js @@ -152,8 +152,8 @@ describe("Scene/Model/CustomShaderPipelineStage", function () { CustomShaderPipelineStage.process(renderResources, primitive); ShaderBuilderTester.expectHasVaryings(shaderBuilder, [ - "varying float v_distanceFromCenter;", - "varying mat2 v_computedMatrix;", + "float v_distanceFromCenter;", + "mat2 v_computedMatrix;", ]); }); diff --git a/packages/engine/Specs/Scene/Model/FeatureIdPipelineStageSpec.js b/packages/engine/Specs/Scene/Model/FeatureIdPipelineStageSpec.js index f8285e6715c3..e73c69036a81 100644 --- a/packages/engine/Specs/Scene/Model/FeatureIdPipelineStageSpec.js +++ b/packages/engine/Specs/Scene/Model/FeatureIdPipelineStageSpec.js @@ -243,12 +243,12 @@ describe( ShaderBuilderTester.expectHasVertexDefines(shaderBuilder, []); ShaderBuilderTester.expectHasFragmentDefines(shaderBuilder, []); ShaderBuilderTester.expectHasAttributes(shaderBuilder, undefined, [ - "attribute float a_implicit_featureId_0;", + "in float a_implicit_featureId_0;", ]); ShaderBuilderTester.expectHasVertexUniforms(shaderBuilder, []); ShaderBuilderTester.expectHasFragmentUniforms(shaderBuilder, []); ShaderBuilderTester.expectHasVaryings(shaderBuilder, [ - "varying float v_implicit_featureId_0;", + "float v_implicit_featureId_0;", ]); ShaderBuilderTester.expectVertexLinesEqual(shaderBuilder, [ _shadersFeatureIdStageVS, @@ -365,12 +365,12 @@ describe( ShaderBuilderTester.expectHasVertexDefines(shaderBuilder, []); ShaderBuilderTester.expectHasFragmentDefines(shaderBuilder, []); ShaderBuilderTester.expectHasAttributes(shaderBuilder, undefined, [ - "attribute float a_implicit_featureId_1;", + "in float a_implicit_featureId_1;", ]); ShaderBuilderTester.expectHasVertexUniforms(shaderBuilder, []); ShaderBuilderTester.expectHasFragmentUniforms(shaderBuilder, []); ShaderBuilderTester.expectHasVaryings(shaderBuilder, [ - "varying float v_implicit_featureId_1;", + "float v_implicit_featureId_1;", ]); ShaderBuilderTester.expectVertexLinesEqual(shaderBuilder, [ _shadersFeatureIdStageVS, @@ -443,7 +443,7 @@ describe( FeatureIdPipelineStage.FUNCTION_ID_INITIALIZE_FEATURE_IDS_FS, FeatureIdPipelineStage.FUNCTION_SIGNATURE_INITIALIZE_FEATURE_IDS, [ - " featureIds.featureId_0 = czm_unpackUint(texture2D(u_featureIdTexture_0, v_texCoord_0).r);", + " featureIds.featureId_0 = czm_unpackUint(texture(u_featureIdTexture_0, v_texCoord_0).r);", ] ); ShaderBuilderTester.expectHasVertexFunctionUnordered( @@ -540,13 +540,13 @@ describe( FeatureIdPipelineStage.FUNCTION_ID_INITIALIZE_FEATURE_IDS_FS, FeatureIdPipelineStage.FUNCTION_SIGNATURE_INITIALIZE_FEATURE_IDS, [ - " featureIds.featureId_0 = czm_unpackUint(texture2D(u_featureIdTexture_0, v_texCoord_0).rgba);", - " featureIds.featureId_1 = czm_unpackUint(texture2D(u_featureIdTexture_1, v_texCoord_0).rgb);", - " featureIds.featureId_2 = czm_unpackUint(texture2D(u_featureIdTexture_2, v_texCoord_0).g);", - " featureIds.featureId_3 = czm_unpackUint(texture2D(u_featureIdTexture_3, v_texCoord_0).ba);", - " featureIds.featureId_4 = czm_unpackUint(texture2D(u_featureIdTexture_4, v_texCoord_0).gr);", - " featureIds.featureId_5 = czm_unpackUint(texture2D(u_featureIdTexture_5, v_texCoord_0).agbb);", - " featureIds.featureId_6 = czm_unpackUint(texture2D(u_featureIdTexture_6, v_texCoord_0).g);", + " featureIds.featureId_0 = czm_unpackUint(texture(u_featureIdTexture_0, v_texCoord_0).rgba);", + " featureIds.featureId_1 = czm_unpackUint(texture(u_featureIdTexture_1, v_texCoord_0).rgb);", + " featureIds.featureId_2 = czm_unpackUint(texture(u_featureIdTexture_2, v_texCoord_0).g);", + " featureIds.featureId_3 = czm_unpackUint(texture(u_featureIdTexture_3, v_texCoord_0).ba);", + " featureIds.featureId_4 = czm_unpackUint(texture(u_featureIdTexture_4, v_texCoord_0).gr);", + " featureIds.featureId_5 = czm_unpackUint(texture(u_featureIdTexture_5, v_texCoord_0).agbb);", + " featureIds.featureId_6 = czm_unpackUint(texture(u_featureIdTexture_6, v_texCoord_0).g);", ] ); ShaderBuilderTester.expectHasVertexFunctionUnordered( @@ -694,13 +694,13 @@ describe( ShaderBuilderTester.expectHasVertexDefines(shaderBuilder, []); ShaderBuilderTester.expectHasFragmentDefines(shaderBuilder, []); ShaderBuilderTester.expectHasAttributes(shaderBuilder, undefined, [ - "attribute float a_implicit_instanceFeatureId_0;", + "in float a_implicit_instanceFeatureId_0;", ]); ShaderBuilderTester.expectHasVertexUniforms(shaderBuilder, []); ShaderBuilderTester.expectHasFragmentUniforms(shaderBuilder, []); ShaderBuilderTester.expectHasVaryings(shaderBuilder, [ - "varying float v_instanceFeatureId_0;", - "varying float v_implicit_instanceFeatureId_0;", + "float v_instanceFeatureId_0;", + "float v_implicit_instanceFeatureId_0;", ]); ShaderBuilderTester.expectVertexLinesEqual(shaderBuilder, [ _shadersFeatureIdStageVS, diff --git a/packages/engine/Specs/Scene/Model/GeometryPipelineStageSpec.js b/packages/engine/Specs/Scene/Model/GeometryPipelineStageSpec.js index 3bb6e7953c3f..1fea0d0f0600 100644 --- a/packages/engine/Specs/Scene/Model/GeometryPipelineStageSpec.js +++ b/packages/engine/Specs/Scene/Model/GeometryPipelineStageSpec.js @@ -215,15 +215,15 @@ describe( [] ); ShaderBuilderTester.expectHasVaryings(shaderBuilder, [ - "varying vec3 v_positionEC;", - "varying vec3 v_positionMC;", - "varying vec3 v_positionWC;", + "vec3 v_positionEC;", + "vec3 v_positionMC;", + "vec3 v_positionWC;", ]); ShaderBuilderTester.expectHasVertexDefines(shaderBuilder, []); ShaderBuilderTester.expectHasFragmentDefines(shaderBuilder, []); ShaderBuilderTester.expectHasAttributes( shaderBuilder, - "attribute vec3 a_positionMC;", + "in vec3 a_positionMC;", [] ); verifyFeatureStruct(shaderBuilder); @@ -317,11 +317,11 @@ describe( [" attributes.texCoord_0 = v_texCoord_0;"] ); ShaderBuilderTester.expectHasVaryings(shaderBuilder, [ - "varying vec3 v_normalEC;", - "varying vec2 v_texCoord_0;", - "varying vec3 v_positionEC;", - "varying vec3 v_positionMC;", - "varying vec3 v_positionWC;", + "vec3 v_normalEC;", + "vec2 v_texCoord_0;", + "vec3 v_positionEC;", + "vec3 v_positionMC;", + "vec3 v_positionWC;", ]); ShaderBuilderTester.expectHasVertexDefines(shaderBuilder, [ "HAS_NORMALS", @@ -333,8 +333,8 @@ describe( ]); ShaderBuilderTester.expectHasAttributes( shaderBuilder, - "attribute vec3 a_positionMC;", - ["attribute vec3 a_normalMC;", "attribute vec2 a_texCoord_0;"] + "in vec3 a_positionMC;", + ["in vec3 a_normalMC;", "in vec2 a_texCoord_0;"] ); verifyFeatureStruct(shaderBuilder); }); @@ -417,11 +417,11 @@ describe( ]); ShaderBuilderTester.expectHasAttributes( shaderBuilder, - "attribute vec3 a_positionMC;", + "in vec3 a_positionMC;", [ - "attribute vec3 a_position2D;", - "attribute vec3 a_normalMC;", - "attribute vec2 a_texCoord_0;", + "in vec3 a_position2D;", + "in vec3 a_normalMC;", + "in vec2 a_texCoord_0;", ] ); verifyFeatureStruct(shaderBuilder); @@ -537,13 +537,13 @@ describe( [" attributes.texCoord_0 = v_texCoord_0;"] ); ShaderBuilderTester.expectHasVaryings(shaderBuilder, [ - "varying vec3 v_normalEC;", - "varying vec3 v_tangentEC;", - "varying vec3 v_bitangentEC;", - "varying vec2 v_texCoord_0;", - "varying vec3 v_positionEC;", - "varying vec3 v_positionMC;", - "varying vec3 v_positionWC;", + "vec3 v_normalEC;", + "vec3 v_tangentEC;", + "vec3 v_bitangentEC;", + "vec2 v_texCoord_0;", + "vec3 v_positionEC;", + "vec3 v_positionMC;", + "vec3 v_positionWC;", ]); ShaderBuilderTester.expectHasVertexDefines(shaderBuilder, [ "HAS_BITANGENTS", @@ -559,11 +559,11 @@ describe( ]); ShaderBuilderTester.expectHasAttributes( shaderBuilder, - "attribute vec3 a_positionMC;", + "in vec3 a_positionMC;", [ - "attribute vec3 a_normalMC;", - "attribute vec4 a_tangentMC;", - "attribute vec2 a_texCoord_0;", + "in vec3 a_normalMC;", + "in vec4 a_tangentMC;", + "in vec2 a_texCoord_0;", ] ); verifyFeatureStruct(shaderBuilder); @@ -666,11 +666,11 @@ describe( ] ); ShaderBuilderTester.expectHasVaryings(shaderBuilder, [ - "varying vec2 v_texCoord_0;", - "varying vec2 v_texCoord_1;", - "varying vec3 v_positionEC;", - "varying vec3 v_positionMC;", - "varying vec3 v_positionWC;", + "vec2 v_texCoord_0;", + "vec2 v_texCoord_1;", + "vec3 v_positionEC;", + "vec3 v_positionMC;", + "vec3 v_positionWC;", ]); ShaderBuilderTester.expectHasVertexDefines(shaderBuilder, [ "HAS_TEXCOORD_0", @@ -682,8 +682,8 @@ describe( ]); ShaderBuilderTester.expectHasAttributes( shaderBuilder, - "attribute vec3 a_positionMC;", - ["attribute vec2 a_texCoord_0;", "attribute vec2 a_texCoord_1;"] + "in vec3 a_positionMC;", + ["in vec2 a_texCoord_0;", "in vec2 a_texCoord_1;"] ); verifyFeatureStruct(shaderBuilder); }); @@ -800,12 +800,12 @@ describe( ] ); ShaderBuilderTester.expectHasVaryings(shaderBuilder, [ - "varying vec3 v_normalEC;", - "varying vec4 v_color_0;", - "varying vec2 v_texCoord_0;", - "varying vec3 v_positionEC;", - "varying vec3 v_positionMC;", - "varying vec3 v_positionWC;", + "vec3 v_normalEC;", + "vec4 v_color_0;", + "vec2 v_texCoord_0;", + "vec3 v_positionEC;", + "vec3 v_positionMC;", + "vec3 v_positionWC;", ]); ShaderBuilderTester.expectHasVertexDefines(shaderBuilder, [ "HAS_NORMALS", @@ -819,12 +819,8 @@ describe( ]); ShaderBuilderTester.expectHasAttributes( shaderBuilder, - "attribute vec3 a_positionMC;", - [ - "attribute vec3 a_normalMC;", - "attribute vec4 a_color_0;", - "attribute vec2 a_texCoord_0;", - ] + "in vec3 a_positionMC;", + ["in vec3 a_normalMC;", "in vec4 a_color_0;", "in vec2 a_texCoord_0;"] ); verifyFeatureStruct(shaderBuilder); }); @@ -906,10 +902,10 @@ describe( [" attributes.color_0 = v_color_0;"] ); ShaderBuilderTester.expectHasVaryings(shaderBuilder, [ - "varying vec4 v_color_0;", - "varying vec3 v_positionEC;", - "varying vec3 v_positionMC;", - "varying vec3 v_positionWC;", + "vec4 v_color_0;", + "vec3 v_positionEC;", + "vec3 v_positionMC;", + "vec3 v_positionWC;", ]); ShaderBuilderTester.expectHasVertexDefines(shaderBuilder, [ "HAS_COLOR_0", @@ -921,8 +917,8 @@ describe( ]); ShaderBuilderTester.expectHasAttributes( shaderBuilder, - "attribute vec3 a_positionMC;", - ["attribute vec4 a_color_0;"] + "in vec3 a_positionMC;", + ["in vec4 a_color_0;"] ); verifyFeatureStruct(shaderBuilder); }); @@ -1001,15 +997,15 @@ describe( [" attributes.temperature = v_temperature;"] ); ShaderBuilderTester.expectHasVaryings(shaderBuilder, [ - "varying vec2 v_temperature;", - "varying vec3 v_positionEC;", - "varying vec3 v_positionMC;", - "varying vec3 v_positionWC;", + "vec2 v_temperature;", + "vec3 v_positionEC;", + "vec3 v_positionMC;", + "vec3 v_positionWC;", ]); ShaderBuilderTester.expectHasAttributes( shaderBuilder, - "attribute vec3 a_positionMC;", - ["attribute vec2 a_temperature;"] + "in vec3 a_positionMC;", + ["in vec2 a_temperature;"] ); verifyFeatureStruct(shaderBuilder); }); @@ -1095,8 +1091,8 @@ describe( ); ShaderBuilderTester.expectHasAttributes( shaderBuilder, - "attribute vec3 a_positionMC;", - ["attribute float a_featureId_0;", "attribute vec3 a_normalMC;"] + "in vec3 a_positionMC;", + ["in float a_featureId_0;", "in vec3 a_normalMC;"] ); ShaderBuilderTester.expectHasVertexDefines(shaderBuilder, [ "HAS_FEATURE_ID_0", @@ -1175,8 +1171,8 @@ describe( ); ShaderBuilderTester.expectHasAttributes( shaderBuilder, - "attribute vec3 a_positionMC;", - ["attribute float a_featureId_0;"] + "in vec3 a_positionMC;", + ["in float a_featureId_0;"] ); ShaderBuilderTester.expectHasVertexDefines(shaderBuilder, [ "HAS_FEATURE_ID_0", @@ -1264,11 +1260,8 @@ describe( ); ShaderBuilderTester.expectHasAttributes( shaderBuilder, - "attribute vec3 a_quantized_positionMC;", - [ - "attribute vec2 a_quantized_normalMC;", - "attribute vec2 a_quantized_texCoord_0;", - ] + "in vec3 a_quantized_positionMC;", + ["in vec2 a_quantized_normalMC;", "in vec2 a_quantized_texCoord_0;"] ); ShaderBuilderTester.expectHasVertexDefines(shaderBuilder, [ "HAS_NORMALS", @@ -1379,11 +1372,11 @@ describe( ); ShaderBuilderTester.expectHasAttributes( shaderBuilder, - "attribute vec3 a_quantized_positionMC;", + "in vec3 a_quantized_positionMC;", [ - "attribute vec2 a_quantized_normalMC;", - "attribute vec2 a_quantized_texCoord_0;", - "attribute vec4 a_tangentMC;", + "in vec2 a_quantized_normalMC;", + "in vec2 a_quantized_texCoord_0;", + "in vec4 a_tangentMC;", ] ); ShaderBuilderTester.expectHasVertexDefines(shaderBuilder, [ @@ -1495,11 +1488,11 @@ describe( ); ShaderBuilderTester.expectHasAttributes( shaderBuilder, - "attribute vec3 a_quantized_positionMC;", + "in vec3 a_quantized_positionMC;", [ - "attribute vec3 a_position2D;", - "attribute vec2 a_quantized_normalMC;", - "attribute vec2 a_quantized_texCoord_0;", + "in vec3 a_position2D;", + "in vec2 a_quantized_normalMC;", + "in vec2 a_quantized_texCoord_0;", ] ); ShaderBuilderTester.expectHasVertexDefines(shaderBuilder, [ @@ -1651,13 +1644,13 @@ describe( ] ); ShaderBuilderTester.expectHasVaryings(shaderBuilder, [ - "varying vec3 v_normalEC;", - "varying vec2 v_texCoord_0;", - "varying vec3 v_positionEC;", - "varying vec3 v_positionMC;", - "varying vec3 v_positionWC;", - "varying mat2 v_warp_matrix;", - "varying vec2 v_temperatures;", + "vec3 v_normalEC;", + "vec2 v_texCoord_0;", + "vec3 v_positionEC;", + "vec3 v_positionMC;", + "vec3 v_positionWC;", + "mat2 v_warp_matrix;", + "vec2 v_temperatures;", ]); ShaderBuilderTester.expectHasVertexDefines(shaderBuilder, [ "HAS_NORMALS", @@ -1669,12 +1662,12 @@ describe( ]); ShaderBuilderTester.expectHasAttributes( shaderBuilder, - "attribute vec3 a_positionMC;", + "in vec3 a_positionMC;", [ - "attribute vec3 a_normalMC;", - "attribute vec2 a_texCoord_0;", - "attribute mat2 a_warp_matrix;", - "attribute vec2 a_temperatures;", + "in vec3 a_normalMC;", + "in vec2 a_texCoord_0;", + "in mat2 a_warp_matrix;", + "in vec2 a_temperatures;", ] ); verifyFeatureStruct(shaderBuilder); @@ -1737,8 +1730,8 @@ describe( ]); ShaderBuilderTester.expectHasAttributes( shaderBuilder, - "attribute vec3 a_positionMC;", - ["attribute vec3 a_normalMC;"] + "in vec3 a_positionMC;", + ["in vec3 a_normalMC;"] ); verifyFeatureStruct(shaderBuilder); }); diff --git a/packages/engine/Specs/Scene/Model/InstancingPipelineStageSpec.js b/packages/engine/Specs/Scene/Model/InstancingPipelineStageSpec.js index a3186d6dae8d..6c77534d7d22 100644 --- a/packages/engine/Specs/Scene/Model/InstancingPipelineStageSpec.js +++ b/packages/engine/Specs/Scene/Model/InstancingPipelineStageSpec.js @@ -269,10 +269,10 @@ describe( "HAS_INSTANCE_MATRICES", ]); ShaderBuilderTester.expectHasAttributes(shaderBuilder, undefined, [ - "attribute vec4 a_instancingTransformRow0;", - "attribute vec4 a_instancingTransformRow1;", - "attribute vec4 a_instancingTransformRow2;", - "attribute float a_instanceFeatureId_0;", + "in vec4 a_instancingTransformRow0;", + "in vec4 a_instancingTransformRow1;", + "in vec4 a_instancingTransformRow2;", + "in float a_instanceFeatureId_0;", ]); expect(runtimeNode.instancingTransformsBuffer).toBeDefined(); @@ -314,13 +314,13 @@ describe( ]); ShaderBuilderTester.expectHasAttributes(shaderBuilder, undefined, [ - "attribute vec4 a_instancingTransformRow0;", - "attribute vec4 a_instancingTransformRow1;", - "attribute vec4 a_instancingTransformRow2;", - "attribute vec4 a_instancingTransform2DRow0;", - "attribute vec4 a_instancingTransform2DRow1;", - "attribute vec4 a_instancingTransform2DRow2;", - "attribute float a_instanceFeatureId_0;", + "in vec4 a_instancingTransformRow0;", + "in vec4 a_instancingTransformRow1;", + "in vec4 a_instancingTransformRow2;", + "in vec4 a_instancingTransform2DRow0;", + "in vec4 a_instancingTransform2DRow1;", + "in vec4 a_instancingTransform2DRow2;", + "in float a_instanceFeatureId_0;", ]); ShaderBuilderTester.expectHasVertexUniforms(shaderBuilder, [ @@ -514,7 +514,7 @@ describe( ]); ShaderBuilderTester.expectHasAttributes(shaderBuilder, undefined, [ - "attribute vec3 a_instanceTranslation;", + "in vec3 a_instanceTranslation;", ]); // No additional buffer was created. @@ -561,7 +561,7 @@ describe( ]); ShaderBuilderTester.expectHasAttributes(shaderBuilder, undefined, [ - "attribute vec3 a_instanceTranslation;", + "in vec3 a_instanceTranslation;", ]); // No additional buffer was created. @@ -617,8 +617,8 @@ describe( ]); ShaderBuilderTester.expectHasAttributes(shaderBuilder, undefined, [ - "attribute vec3 a_instanceTranslation;", - "attribute vec3 a_instanceTranslation2D;", + "in vec3 a_instanceTranslation;", + "in vec3 a_instanceTranslation2D;", ]); ShaderBuilderTester.expectHasVertexUniforms(shaderBuilder, [ diff --git a/packages/engine/Specs/Scene/Model/MetadataPipelineStageSpec.js b/packages/engine/Specs/Scene/Model/MetadataPipelineStageSpec.js index 79efc8b07323..42cd1bbc4c71 100644 --- a/packages/engine/Specs/Scene/Model/MetadataPipelineStageSpec.js +++ b/packages/engine/Specs/Scene/Model/MetadataPipelineStageSpec.js @@ -311,9 +311,9 @@ describe( MetadataPipelineStage.FUNCTION_ID_INITIALIZE_METADATA_FS, MetadataPipelineStage.FUNCTION_SIGNATURE_INITIALIZE_METADATA, [ - " metadata.insulation = texture2D(u_propertyTexture_1, attributes.texCoord_0).b;", - " metadata.insideTemperature = int(255.0 * texture2D(u_propertyTexture_1, attributes.texCoord_0).r);", - " metadata.outsideTemperature = int(255.0 * texture2D(u_propertyTexture_1, attributes.texCoord_0).g);", + " metadata.insulation = texture(u_propertyTexture_1, attributes.texCoord_0).b;", + " metadata.insideTemperature = int(255.0 * texture(u_propertyTexture_1, attributes.texCoord_0).r);", + " metadata.outsideTemperature = int(255.0 * texture(u_propertyTexture_1, attributes.texCoord_0).g);", " metadataClass.insulation.defaultValue = float(1);", ] ); @@ -404,11 +404,11 @@ describe( MetadataPipelineStage.FUNCTION_ID_INITIALIZE_METADATA_FS, MetadataPipelineStage.FUNCTION_SIGNATURE_INITIALIZE_METADATA, [ - " metadata.vec2Property = texture2D(u_propertyTexture_1, attributes.texCoord_0).gb;", - " metadata.uint8Property = int(255.0 * texture2D(u_propertyTexture_1, attributes.texCoord_0).r);", - " metadata.uint8vec3Property = ivec3(255.0 * texture2D(u_propertyTexture_1, attributes.texCoord_0).rgb);", - " metadata.arrayProperty = texture2D(u_propertyTexture_1, attributes.texCoord_0).rgb;", - " metadata.valueTransformProperty = czm_valueTransform(u_valueTransformProperty_offset, u_valueTransformProperty_scale, texture2D(u_propertyTexture_1, attributes.texCoord_0).rg);", + " metadata.vec2Property = texture(u_propertyTexture_1, attributes.texCoord_0).gb;", + " metadata.uint8Property = int(255.0 * texture(u_propertyTexture_1, attributes.texCoord_0).r);", + " metadata.uint8vec3Property = ivec3(255.0 * texture(u_propertyTexture_1, attributes.texCoord_0).rgb);", + " metadata.arrayProperty = texture(u_propertyTexture_1, attributes.texCoord_0).rgb;", + " metadata.valueTransformProperty = czm_valueTransform(u_valueTransformProperty_offset, u_valueTransformProperty_scale, texture(u_propertyTexture_1, attributes.texCoord_0).rg);", " metadataClass.uint8vec3Property.defaultValue = ivec3(255,0,0);", " metadataClass.uint8vec3Property.maxValue = ivec3(30,17,50);", " metadataClass.uint8vec3Property.minValue = ivec3(10,10,10);", diff --git a/packages/engine/Specs/Scene/Model/ModelSpec.js b/packages/engine/Specs/Scene/Model/ModelSpec.js index 94e878fcb725..180ab45ec0ec 100644 --- a/packages/engine/Specs/Scene/Model/ModelSpec.js +++ b/packages/engine/Specs/Scene/Model/ModelSpec.js @@ -1314,22 +1314,22 @@ describe( const triangleFanUrl = "./Data/Models/glTF-2.0/TriangleFan/glTF/TriangleFan.gltf"; - let sceneWithWebgl2; + let sceneWithWebgl1; beforeAll(function () { - sceneWithWebgl2 = createScene({ + sceneWithWebgl1 = createScene({ contextOptions: { - requestWebgl1: false, + requestWebgl1: true, }, }); }); afterEach(function () { - sceneWithWebgl2.primitives.removeAll(); + sceneWithWebgl1.primitives.removeAll(); }); afterAll(function () { - sceneWithWebgl2.destroyForSpecs(); + sceneWithWebgl1.destroyForSpecs(); }); it("debugWireframe works for WebGL1 if enableDebugWireframe is true", function () { @@ -1338,7 +1338,7 @@ describe( return loadPromise.then(function (buffer) { return loadAndZoomToModel( { gltf: new Uint8Array(buffer), enableDebugWireframe: true }, - scene + sceneWithWebgl1 ).then(function (model) { verifyDebugWireframe(model, PrimitiveType.TRIANGLES); }); @@ -1351,12 +1351,12 @@ describe( return loadPromise.then(function (buffer) { return loadAndZoomToModel( { gltf: new Uint8Array(buffer), enableDebugWireframe: false }, - scene + sceneWithWebgl1 ).then(function (model) { const commandList = scene.frameState.commandList; const commandCounts = []; let i, command; - scene.renderForSpecs(); + sceneWithWebgl1.renderForSpecs(); for (i = 0; i < commandList.length; i++) { command = commandList[i]; expect(command.primitiveType).toBe(PrimitiveType.TRIANGLES); @@ -1366,7 +1366,7 @@ describe( model.debugWireframe = true; expect(model._drawCommandsBuilt).toBe(false); - scene.renderForSpecs(); + sceneWithWebgl1.renderForSpecs(); for (i = 0; i < commandList.length; i++) { command = commandList[i]; expect(command.primitiveType).toBe(PrimitiveType.TRIANGLES); @@ -1377,7 +1377,7 @@ describe( }); it("debugWireframe works for WebGL2", function () { - if (!sceneWithWebgl2.context.webgl2) { + if (!scene.context.webgl2) { return; } const resource = Resource.createIfNeeded(boxTexturedGlbUrl); @@ -1388,7 +1388,7 @@ describe( scene ).then(function (model) { verifyDebugWireframe(model, PrimitiveType.TRIANGLES, { - scene: sceneWithWebgl2, + scene: scene, }); }); }); diff --git a/packages/engine/Specs/Scene/Model/MorphTargetsPipelineStageSpec.js b/packages/engine/Specs/Scene/Model/MorphTargetsPipelineStageSpec.js index b9b7e174dcd5..3bf6dea562e0 100644 --- a/packages/engine/Specs/Scene/Model/MorphTargetsPipelineStageSpec.js +++ b/packages/engine/Specs/Scene/Model/MorphTargetsPipelineStageSpec.js @@ -132,7 +132,7 @@ describe( ]); ShaderBuilderTester.expectHasAttributes(shaderBuilder, undefined, [ - "attribute vec3 a_targetPosition_0;", + "in vec3 a_targetPosition_0;", ]); ShaderBuilderTester.expectVertexLinesEqual(shaderBuilder, [ @@ -231,12 +231,12 @@ describe( ]); ShaderBuilderTester.expectHasAttributes(shaderBuilder, undefined, [ - "attribute vec3 a_targetPosition_0;", - "attribute vec3 a_targetPosition_1;", - "attribute vec3 a_targetNormal_0;", - "attribute vec3 a_targetNormal_1;", - "attribute vec3 a_targetTangent_0;", - "attribute vec3 a_targetTangent_1;", + "in vec3 a_targetPosition_0;", + "in vec3 a_targetPosition_1;", + "in vec3 a_targetNormal_0;", + "in vec3 a_targetNormal_1;", + "in vec3 a_targetTangent_0;", + "in vec3 a_targetTangent_1;", ]); ShaderBuilderTester.expectVertexLinesEqual(shaderBuilder, [ diff --git a/packages/engine/Specs/Scene/Model/PickingPipelineStageSpec.js b/packages/engine/Specs/Scene/Model/PickingPipelineStageSpec.js index 95c8410ee479..180ffe197d30 100644 --- a/packages/engine/Specs/Scene/Model/PickingPipelineStageSpec.js +++ b/packages/engine/Specs/Scene/Model/PickingPipelineStageSpec.js @@ -297,10 +297,10 @@ describe( const shaderBuilder = renderResources.shaderBuilder; ShaderBuilderTester.expectHasAttributes(shaderBuilder, undefined, [ - "attribute vec4 a_pickColor;", + "in vec4 a_pickColor;", ]); ShaderBuilderTester.expectHasVaryings(shaderBuilder, [ - "varying vec4 v_pickColor;", + "vec4 v_pickColor;", ]); let i = 0; @@ -368,7 +368,7 @@ describe( ]); expect(renderResources.pickId).toEqual( - "((selectedFeature.id < int(model_featuresLength)) ? texture2D(model_pickTexture, selectedFeature.st) : vec4(0.0))" + "((selectedFeature.id < int(model_featuresLength)) ? texture(model_pickTexture, selectedFeature.st) : vec4(0.0))" ); }); }); diff --git a/packages/engine/Specs/Scene/Model/PointCloudStylingPipelineStageSpec.js b/packages/engine/Specs/Scene/Model/PointCloudStylingPipelineStageSpec.js index 7b0f3df12cf4..38639d9da85e 100644 --- a/packages/engine/Specs/Scene/Model/PointCloudStylingPipelineStageSpec.js +++ b/packages/engine/Specs/Scene/Model/PointCloudStylingPipelineStageSpec.js @@ -174,7 +174,7 @@ describe( ); ShaderBuilderTester.expectHasVaryings(shaderBuilder, [ - "varying vec4 v_pointCloudColor;", + "vec4 v_pointCloudColor;", ]); ShaderBuilderTester.expectHasVertexDefines(shaderBuilder, [ @@ -221,7 +221,7 @@ describe( ); ShaderBuilderTester.expectHasVaryings(shaderBuilder, [ - "varying vec4 v_pointCloudColor;", + "vec4 v_pointCloudColor;", ]); ShaderBuilderTester.expectHasVertexDefines(shaderBuilder, [ diff --git a/packages/engine/Specs/Scene/Model/PrimitiveOutlinePipelineStageSpec.js b/packages/engine/Specs/Scene/Model/PrimitiveOutlinePipelineStageSpec.js index c7ce0679a476..4a124406ce7d 100644 --- a/packages/engine/Specs/Scene/Model/PrimitiveOutlinePipelineStageSpec.js +++ b/packages/engine/Specs/Scene/Model/PrimitiveOutlinePipelineStageSpec.js @@ -111,10 +111,10 @@ describe( "HAS_PRIMITIVE_OUTLINE", ]); ShaderBuilderTester.expectHasAttributes(shaderBuilder, undefined, [ - "attribute vec3 a_outlineCoordinates;", + "in vec3 a_outlineCoordinates;", ]); ShaderBuilderTester.expectHasVaryings(shaderBuilder, [ - "varying vec3 v_outlineCoordinates;", + "vec3 v_outlineCoordinates;", ]); ShaderBuilderTester.expectHasVertexUniforms(shaderBuilder, []); ShaderBuilderTester.expectHasFragmentUniforms(shaderBuilder, [ diff --git a/packages/engine/Specs/Scene/Model/PrimitiveStatisticsPipelineStageSpec.js b/packages/engine/Specs/Scene/Model/PrimitiveStatisticsPipelineStageSpec.js index b64e82089fa2..d7e9cc580219 100644 --- a/packages/engine/Specs/Scene/Model/PrimitiveStatisticsPipelineStageSpec.js +++ b/packages/engine/Specs/Scene/Model/PrimitiveStatisticsPipelineStageSpec.js @@ -44,7 +44,11 @@ describe( const gltfLoaders = []; beforeAll(function () { - scene = createScene(); + scene = createScene({ + contextOptions: { + requestWebgl1: true, + }, + }); }); afterAll(function () { diff --git a/packages/engine/Specs/Scene/Model/TextureManagerSpec.js b/packages/engine/Specs/Scene/Model/TextureManagerSpec.js index 6f6bc647ec87..2bd470f93417 100644 --- a/packages/engine/Specs/Scene/Model/TextureManagerSpec.js +++ b/packages/engine/Specs/Scene/Model/TextureManagerSpec.js @@ -10,10 +10,12 @@ describe( let sceneWithWebgl2; beforeAll(function () { - sceneWithWebgl1 = createScene(); - sceneWithWebgl2 = createScene({ - contextOptions: { requestWebgl1: false }, + sceneWithWebgl1 = createScene({ + contextOptions: { + requestWebgl1: true, + }, }); + sceneWithWebgl2 = createScene(); }); afterAll(function () { @@ -111,7 +113,9 @@ describe( }) ); - return waitForTextureLoad(textureManager, id).then(function (texture) { + return waitForTextureLoad(textureManager, id, false).then(function ( + texture + ) { expect(texture._hasMipmap).toBe(true); }); }); @@ -129,7 +133,9 @@ describe( }) ); - return waitForTextureLoad(textureManager, id).then(function (texture) { + return waitForTextureLoad(textureManager, id, false).then(function ( + texture + ) { expect(texture.width).toBe(16); expect(texture.height).toBe(16); expect(texture._hasMipmap).toBe(true); diff --git a/packages/engine/Specs/Scene/Model/WireframePipelineStageSpec.js b/packages/engine/Specs/Scene/Model/WireframePipelineStageSpec.js index 8e452e837040..f7e93c7892cf 100644 --- a/packages/engine/Specs/Scene/Model/WireframePipelineStageSpec.js +++ b/packages/engine/Specs/Scene/Model/WireframePipelineStageSpec.js @@ -24,12 +24,12 @@ describe( let scene; let sceneWithWebgl2; beforeAll(function () { - scene = createScene(); - sceneWithWebgl2 = createScene({ + scene = createScene({ contextOptions: { - requestWebgl1: false, + sceneWithWebgl1: true, }, }); + sceneWithWebgl2 = createScene(); }); afterAll(function () { diff --git a/packages/engine/Specs/Scene/MultifrustumSpec.js b/packages/engine/Specs/Scene/MultifrustumSpec.js index 98e7710d61e7..7a83a658b4e4 100644 --- a/packages/engine/Specs/Scene/MultifrustumSpec.js +++ b/packages/engine/Specs/Scene/MultifrustumSpec.js @@ -235,7 +235,7 @@ describe( Primitive.prototype.update = function (frameState) { if (!defined(this._sp)) { let vs = ""; - vs += "attribute vec4 position;"; + vs += "in vec4 position;"; vs += "void main()"; vs += "{"; vs += " gl_Position = czm_modelViewProjection * position;"; @@ -247,7 +247,7 @@ describe( fs += "uniform vec4 u_color;"; fs += "void main()"; fs += "{"; - fs += " gl_FragColor = u_color;"; + fs += " out_FragColor = u_color;"; fs += "}"; const dimensions = new Cartesian3(500000.0, 500000.0, 500000.0); diff --git a/packages/engine/Specs/Scene/OctahedralProjectedCubeMapSpec.js b/packages/engine/Specs/Scene/OctahedralProjectedCubeMapSpec.js index f8d2933c86a0..c8cda34593e9 100644 --- a/packages/engine/Specs/Scene/OctahedralProjectedCubeMapSpec.js +++ b/packages/engine/Specs/Scene/OctahedralProjectedCubeMapSpec.js @@ -26,15 +26,15 @@ describe( "uniform float maxLod;" + "void main() {" + " vec3 color = czm_sampleOctahedralProjection(projectedMap, textureSize, direction, lod, maxLod);" + - " gl_FragColor = vec4(color, 1.0);" + + " out_FragColor = vec4(color, 1.0);" + "}"; const fsCubeMap = "uniform samplerCube cubeMap;" + "uniform vec3 direction;" + "void main() {" + - " vec4 rgba = textureCube(cubeMap, direction);" + - " gl_FragColor = vec4(rgba.rgb, 1.0);" + + " vec4 rgba = czm_textureCube(cubeMap, direction);" + + " out_FragColor = vec4(rgba.rgb, 1.0);" + "}"; beforeAll(function () { diff --git a/packages/engine/Specs/Scene/PickingSpec.js b/packages/engine/Specs/Scene/PickingSpec.js index 3b4c5c0f57d7..4474051a0adc 100644 --- a/packages/engine/Specs/Scene/PickingSpec.js +++ b/packages/engine/Specs/Scene/PickingSpec.js @@ -62,6 +62,9 @@ describe( beforeAll(function () { scene = createScene({ canvas: createCanvas(10, 10), + contextOptions: { + requestWebgl1: true, + }, }); primitives = scene.primitives; camera = scene.camera; diff --git a/packages/engine/Specs/Scene/PostProcessStageCollectionSpec.js b/packages/engine/Specs/Scene/PostProcessStageCollectionSpec.js index 85538e48ef9c..85bca942fbfb 100644 --- a/packages/engine/Specs/Scene/PostProcessStageCollectionSpec.js +++ b/packages/engine/Specs/Scene/PostProcessStageCollectionSpec.js @@ -46,7 +46,7 @@ describe( scene.postProcessStages.add( new PostProcessStage({ fragmentShader: - "void main() { gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0); }", + "void main() { out_FragColor = vec4(1.0, 1.0, 0.0, 1.0); }", }) ); expect(scene.postProcessStages.length).toEqual(1); @@ -58,10 +58,10 @@ describe( new PostProcessStage({ fragmentShader: "uniform sampler2D colorTexture;\n" + - "varying vec2 v_textureCoordinates;\n" + + "in vec2 v_textureCoordinates;\n" + "void main() {\n" + - " vec4 color = texture2D(colorTexture, v_textureCoordinates);\n" + - " gl_FragColor = vec4(color.r, 0.0, 1.0, 1.0);\n" + + " vec4 color = texture(colorTexture, v_textureCoordinates);\n" + + " out_FragColor = vec4(color.r, 0.0, 1.0, 1.0);\n" + "}", }) ); @@ -74,7 +74,7 @@ describe( it("throws when adding the same stage", function () { const stage = new PostProcessStage({ fragmentShader: - "void main() { gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0); }", + "void main() { out_FragColor = vec4(1.0, 1.0, 0.0, 1.0); }", }); expect(function () { scene.postProcessStages.add(stage); @@ -86,7 +86,7 @@ describe( const stage1 = scene.postProcessStages.add( new PostProcessStage({ fragmentShader: - "void main() { gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0); }", + "void main() { out_FragColor = vec4(1.0, 1.0, 0.0, 1.0); }", }) ); scene.renderForSpecs(); @@ -103,17 +103,17 @@ describe( const stage1 = scene.postProcessStages.add( new PostProcessStage({ fragmentShader: - "void main() { gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0); }", + "void main() { out_FragColor = vec4(1.0, 1.0, 0.0, 1.0); }", }) ); const stage2 = scene.postProcessStages.add( new PostProcessStage({ fragmentShader: "uniform sampler2D colorTexture;\n" + - "varying vec2 v_textureCoordinates;\n" + + "in vec2 v_textureCoordinates;\n" + "void main() {\n" + - " vec4 color = texture2D(colorTexture, v_textureCoordinates);\n" + - " gl_FragColor = vec4(color.r, 0.0, 1.0, 1.0);\n" + + " vec4 color = texture(colorTexture, v_textureCoordinates);\n" + + " out_FragColor = vec4(color.r, 0.0, 1.0, 1.0);\n" + "}", }) ); @@ -146,17 +146,17 @@ describe( const stage1 = scene.postProcessStages.add( new PostProcessStage({ fragmentShader: - "void main() { gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0); }", + "void main() { out_FragColor = vec4(1.0, 1.0, 0.0, 1.0); }", }) ); const stage2 = scene.postProcessStages.add( new PostProcessStage({ fragmentShader: "uniform sampler2D colorTexture;\n" + - "varying vec2 v_textureCoordinates;\n" + + "in vec2 v_textureCoordinates;\n" + "void main() {\n" + - " vec4 color = texture2D(colorTexture, v_textureCoordinates);\n" + - " gl_FragColor = vec4(color.r, 0.0, 1.0, 1.0);\n" + + " vec4 color = texture(colorTexture, v_textureCoordinates);\n" + + " out_FragColor = vec4(color.r, 0.0, 1.0, 1.0);\n" + "}", }) ); @@ -176,7 +176,7 @@ describe( scene.postProcessStages.add( new PostProcessStage({ fragmentShader: - "void main() { gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0); }", + "void main() { out_FragColor = vec4(1.0, 1.0, 0.0, 1.0); }", }) ); expect(function () { @@ -193,17 +193,17 @@ describe( const stage1 = scene.postProcessStages.add( new PostProcessStage({ fragmentShader: - "void main() { gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0); }", + "void main() { out_FragColor = vec4(1.0, 1.0, 0.0, 1.0); }", }) ); const stage2 = scene.postProcessStages.add( new PostProcessStage({ fragmentShader: "uniform sampler2D colorTexture;\n" + - "varying vec2 v_textureCoordinates;\n" + + "in vec2 v_textureCoordinates;\n" + "void main() {\n" + - " vec4 color = texture2D(colorTexture, v_textureCoordinates);\n" + - " gl_FragColor = vec4(color.r, 0.0, 1.0, 1.0);\n" + + " vec4 color = texture(colorTexture, v_textureCoordinates);\n" + + " out_FragColor = vec4(color.r, 0.0, 1.0, 1.0);\n" + "}", }) ); @@ -229,17 +229,17 @@ describe( const stage1 = scene.postProcessStages.add( new PostProcessStage({ fragmentShader: - "void main() { gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0); }", + "void main() { out_FragColor = vec4(1.0, 1.0, 0.0, 1.0); }", }) ); const stage2 = scene.postProcessStages.add( new PostProcessStage({ fragmentShader: "uniform sampler2D colorTexture;\n" + - "varying vec2 v_textureCoordinates;\n" + + "in vec2 v_textureCoordinates;\n" + "void main() {\n" + - " vec4 color = texture2D(colorTexture, v_textureCoordinates);\n" + - " gl_FragColor = vec4(color.r, 0.0, 1.0, 1.0);\n" + + " vec4 color = texture(colorTexture, v_textureCoordinates);\n" + + " out_FragColor = vec4(color.r, 0.0, 1.0, 1.0);\n" + "}", }) ); @@ -259,17 +259,17 @@ describe( const stage1 = scene.postProcessStages.add( new PostProcessStage({ fragmentShader: - "void main() { gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0); }", + "void main() { out_FragColor = vec4(1.0, 1.0, 0.0, 1.0); }", }) ); const stage2 = scene.postProcessStages.add( new PostProcessStage({ fragmentShader: "uniform sampler2D colorTexture;\n" + - "varying vec2 v_textureCoordinates;\n" + + "in vec2 v_textureCoordinates;\n" + "void main() {\n" + - " vec4 color = texture2D(colorTexture, v_textureCoordinates);\n" + - " gl_FragColor = vec4(color.r, 0.0, 1.0, 1.0);\n" + + " vec4 color = texture(colorTexture, v_textureCoordinates);\n" + + " out_FragColor = vec4(color.r, 0.0, 1.0, 1.0);\n" + "}", }) ); @@ -304,7 +304,7 @@ describe( const stage = scene.postProcessStages.add( new PostProcessStage({ fragmentShader: - "void main() { gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0); }", + "void main() { out_FragColor = vec4(1.0, 0.0, 1.0, 1.0); }", }) ); scene.renderForSpecs(); @@ -320,7 +320,7 @@ describe( const stage = scene.postProcessStages.add( new PostProcessStage({ fragmentShader: - "void main() { gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0); }", + "void main() { out_FragColor = vec4(1.0, 0.0, 1.0, 1.0); }", }) ); stage.enabled = false; @@ -338,13 +338,13 @@ describe( scene.postProcessStages.add( new PostProcessStage({ fragmentShader: - "void main() { gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0); }", + "void main() { out_FragColor = vec4(1.0, 0.0, 1.0, 1.0); }", }) ); const stage = scene.postProcessStages.add( new PostProcessStage({ fragmentShader: - "void main() { gl_FragColor = vec4(0.0, 1.0, 1.0, 1.0); }", + "void main() { out_FragColor = vec4(0.0, 1.0, 1.0, 1.0); }", }) ); @@ -361,13 +361,13 @@ describe( scene.postProcessStages.add( new PostProcessStage({ fragmentShader: - "void main() { gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0); }", + "void main() { out_FragColor = vec4(1.0, 0.0, 1.0, 1.0); }", }) ); const stage = scene.postProcessStages.add( new PostProcessStage({ fragmentShader: - "void main() { gl_FragColor = vec4(0.0, 1.0, 1.0, 1.0); }", + "void main() { out_FragColor = vec4(0.0, 1.0, 1.0, 1.0); }", }) ); stage.enabled = false; @@ -388,7 +388,7 @@ describe( const fs = "void main() { \n" + - " gl_FragColor = vec4(4.0, 0.0, 0.0, 1.0); \n" + + " out_FragColor = vec4(4.0, 0.0, 0.0, 1.0); \n" + "} \n"; scene.primitives.add(new ViewportPrimitive(fs)); @@ -414,7 +414,7 @@ describe( const fs = "void main() { \n" + - " gl_FragColor = vec4(0.5, 0.0, 0.0, 1.0); \n" + + " out_FragColor = vec4(0.5, 0.0, 0.0, 1.0); \n" + "} \n"; scene.primitives.add(new ViewportPrimitive(fs)); @@ -442,7 +442,7 @@ describe( const fs = "void main() { \n" + - " gl_FragColor = vec4(4.0, 0.0, 0.0, 1.0); \n" + + " out_FragColor = vec4(4.0, 0.0, 0.0, 1.0); \n" + "} \n"; scene.primitives.add(new ViewportPrimitive(fs)); @@ -468,7 +468,7 @@ describe( const fs = "void main() { \n" + - " gl_FragColor = vec4(4.0, 0.0, 0.0, 1.0); \n" + + " out_FragColor = vec4(4.0, 0.0, 0.0, 1.0); \n" + "} \n"; scene.primitives.add(new ViewportPrimitive(fs)); @@ -491,7 +491,7 @@ describe( const stages = new PostProcessStageCollection(); const stage = stages.add( new PostProcessStage({ - fragmentShader: "void main() { gl_FragColor = vec4(1.0); }", + fragmentShader: "void main() { out_FragColor = vec4(1.0); }", }) ); expect(stages.isDestroyed()).toEqual(false); diff --git a/packages/engine/Specs/Scene/PostProcessStageCompositeSpec.js b/packages/engine/Specs/Scene/PostProcessStageCompositeSpec.js index 2102eebe299a..442373b1e412 100644 --- a/packages/engine/Specs/Scene/PostProcessStageCompositeSpec.js +++ b/packages/engine/Specs/Scene/PostProcessStageCompositeSpec.js @@ -29,7 +29,7 @@ describe( it("constructs", function () { const stage = new PostProcessStage({ fragmentShader: - "uniform vec4 color; void main() { gl_FragColor = color; }", + "uniform vec4 color; void main() { out_FragColor = color; }", uniforms: { color: Color.clone(Color.RED) }, }); const uniforms = { @@ -63,11 +63,11 @@ describe( it("default constructs", function () { const stage1 = new PostProcessStage({ - fragmentShader: "void main() { gl_FragColor = vec4(1.0); }", + fragmentShader: "void main() { out_FragColor = vec4(1.0); }", }); const stage2 = new PostProcessStage({ fragmentShader: - "void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }", + "void main() { out_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }", }); const composite = new PostProcessStageComposite({ stages: [stage1, stage2], @@ -91,11 +91,11 @@ describe( it("gets stages", function () { const stage1 = new PostProcessStage({ - fragmentShader: "void main() { gl_FragColor = vec4(1.0); }", + fragmentShader: "void main() { out_FragColor = vec4(1.0); }", }); const stage2 = new PostProcessStage({ fragmentShader: - "void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }", + "void main() { out_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }", }); const composite = new PostProcessStageComposite({ stages: [stage1, stage2], @@ -106,11 +106,11 @@ describe( it("throws when get index is invalid", function () { const stage1 = new PostProcessStage({ - fragmentShader: "void main() { gl_FragColor = vec4(1.0); }", + fragmentShader: "void main() { out_FragColor = vec4(1.0); }", }); const stage2 = new PostProcessStage({ fragmentShader: - "void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }", + "void main() { out_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }", }); const composite = new PostProcessStageComposite({ stages: [stage1, stage2], @@ -125,15 +125,15 @@ describe( it("renders with inputPreviousStageTexture is true", function () { const stage1 = new PostProcessStage({ - fragmentShader: "void main() { gl_FragColor = vec4(1.0); }", + fragmentShader: "void main() { out_FragColor = vec4(1.0); }", }); const stage2 = new PostProcessStage({ fragmentShader: "uniform sampler2D colorTexture;\n" + - "varying vec2 v_textureCoordinates;\n" + + "in vec2 v_textureCoordinates;\n" + "void main() {\n" + - " vec4 color = texture2D(colorTexture, v_textureCoordinates);\n" + - " gl_FragColor = vec4(color.r, 0.0, 1.0, 1.0);\n" + + " vec4 color = texture(colorTexture, v_textureCoordinates);\n" + + " out_FragColor = vec4(color.r, 0.0, 1.0, 1.0);\n" + "}", }); const composite = new PostProcessStageComposite({ @@ -148,15 +148,15 @@ describe( it("renders with inputPreviousStageTexture is false", function () { const stage1 = new PostProcessStage({ - fragmentShader: "void main() { gl_FragColor = vec4(1.0); }", + fragmentShader: "void main() { out_FragColor = vec4(1.0); }", }); const stage2 = new PostProcessStage({ fragmentShader: "uniform sampler2D colorTexture;\n" + - "varying vec2 v_textureCoordinates;\n" + + "in vec2 v_textureCoordinates;\n" + "void main() {\n" + - " vec4 color = texture2D(colorTexture, v_textureCoordinates);\n" + - " gl_FragColor = vec4(color.r, 0.0, 1.0, 1.0);\n" + + " vec4 color = texture(colorTexture, v_textureCoordinates);\n" + + " out_FragColor = vec4(color.r, 0.0, 1.0, 1.0);\n" + "}", }); const composite = new PostProcessStageComposite({ @@ -171,7 +171,11 @@ describe( }); it("does not run a stage that requires depth textures when depth textures are not supported", function () { - const s = createScene(); + const s = createScene({ + contextOptions: { + requestWebgl1: true, + }, + }); s.context._depthTexture = false; if (defined(s._view.globeDepth)) { @@ -188,7 +192,7 @@ describe( const bgColor = 51; // Choose a factor of 255 to make sure there aren't rounding issues s.postProcessStages.add( new PostProcessStage({ - fragmentShader: `void main() { gl_FragColor = vec4(vec3(${ + fragmentShader: `void main() { out_FragColor = vec4(vec3(${ bgColor / 255 }), 1.0); }`, }) @@ -200,7 +204,7 @@ describe( stages: [ new PostProcessStage({ fragmentShader: - "uniform sampler2D depthTexture; void main() { gl_FragColor = vec4(1.0); }", + "uniform sampler2D depthTexture; void main() { out_FragColor = vec4(1.0); }", }), ], }) @@ -222,11 +226,11 @@ describe( it("destroys", function () { const stage1 = new PostProcessStage({ - fragmentShader: "void main() { gl_FragColor = vec4(1.0); }", + fragmentShader: "void main() { out_FragColor = vec4(1.0); }", }); const stage2 = new PostProcessStage({ fragmentShader: - "void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }", + "void main() { out_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }", }); const composite = new PostProcessStageComposite({ stages: [stage1, stage2], diff --git a/packages/engine/Specs/Scene/PostProcessStageLibrarySpec.js b/packages/engine/Specs/Scene/PostProcessStageLibrarySpec.js index 886e90aa927f..90dd4726dbf3 100644 --- a/packages/engine/Specs/Scene/PostProcessStageLibrarySpec.js +++ b/packages/engine/Specs/Scene/PostProcessStageLibrarySpec.js @@ -48,7 +48,7 @@ describe( it("black and white", function () { const fs = "void main() { \n" + - " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); \n" + + " out_FragColor = vec4(1.0, 0.0, 0.0, 1.0); \n" + "} \n"; scene.primitives.add(new ViewportPrimitive(fs)); @@ -121,7 +121,7 @@ describe( it("brightness", function () { const fs = "void main() { \n" + - " gl_FragColor = vec4(vec3(0.25), 1.0); \n" + + " out_FragColor = vec4(vec3(0.25), 1.0); \n" + "} \n"; scene.primitives.add(new ViewportPrimitive(fs)); @@ -169,7 +169,7 @@ describe( it("night vision", function () { const fs = "void main() { \n" + - " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); \n" + + " out_FragColor = vec4(1.0, 0.0, 0.0, 1.0); \n" + "} \n"; scene.primitives.add(new ViewportPrimitive(fs)); @@ -209,7 +209,7 @@ describe( const fs = "void main() { \n" + - " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); \n" + + " out_FragColor = vec4(1.0, 0.0, 0.0, 1.0); \n" + "} \n"; scene.primitives.add(new ViewportPrimitive(fs)); @@ -245,7 +245,7 @@ describe( it("blur", function () { const fs = "void main() { \n" + - " gl_FragColor = all(equal(floor(gl_FragCoord.xy), vec2(1.0, 1.0))) ? vec4(1.0, 0.0, 0.0, 1.0) : vec4(0.0, 0.0, 1.0, 1.0); \n" + + " out_FragColor = all(equal(floor(gl_FragCoord.xy), vec2(1.0, 1.0))) ? vec4(1.0, 0.0, 0.0, 1.0) : vec4(0.0, 0.0, 1.0, 1.0); \n" + "} \n"; scene.primitives.add(new ViewportPrimitive(fs)); diff --git a/packages/engine/Specs/Scene/PostProcessStageSpec.js b/packages/engine/Specs/Scene/PostProcessStageSpec.js index 1dd5b786a7cc..844741a42dc4 100644 --- a/packages/engine/Specs/Scene/PostProcessStageSpec.js +++ b/packages/engine/Specs/Scene/PostProcessStageSpec.js @@ -35,7 +35,7 @@ describe( it("constructs", function () { const fragmentShader = - "uniform vec4 color; void main() { gl_FragColor = color; }"; + "uniform vec4 color; void main() { out_FragColor = color; }"; const uniforms = { color: Color.clone(Color.RED) }; const textureScale = 0.5; const forcePowerOfTwo = true; @@ -72,7 +72,7 @@ describe( }); it("default constructs", function () { - const fragmentShader = "void main() { gl_FragColor = vec4(1.0); }"; + const fragmentShader = "void main() { out_FragColor = vec4(1.0); }"; const stage = new PostProcessStage({ fragmentShader: fragmentShader, @@ -97,7 +97,7 @@ describe( }); it("throws with invalid texture scale", function () { - const fs = "void main() { gl_FragColor = vec4(1.0); }"; + const fs = "void main() { out_FragColor = vec4(1.0); }"; expect(function () { return new PostProcessStage({ fragmentShader: fs, @@ -115,7 +115,7 @@ describe( it("throws if pixel format is not a color format", function () { expect(function () { return new PostProcessStage({ - fragmentShader: "void main() { gl_FragColor = vec4(1.0); }", + fragmentShader: "void main() { out_FragColor = vec4(1.0); }", pixelFormat: PixelFormat.DEPTH_STENCIL, }); }).toThrowDeveloperError(); @@ -126,7 +126,7 @@ describe( scene.postProcessStages.add( new PostProcessStage({ fragmentShader: - "void main() { gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0); }", + "void main() { out_FragColor = vec4(1.0, 1.0, 0.0, 1.0); }", }) ); scene.renderForSpecs(); // render one frame so the stage is ready @@ -138,9 +138,9 @@ describe( const stage = scene.postProcessStages.add( new PostProcessStage({ fragmentShader: - "uniform sampler2D texture; varying vec2 v_textureCoordinates; void main() { gl_FragColor = texture2D(texture, v_textureCoordinates); }", + "uniform sampler2D inputTexture; in vec2 v_textureCoordinates; void main() { out_FragColor = texture(inputTexture, v_textureCoordinates); }", uniforms: { - texture: "./Data/Images/Green2x2.png", + inputTexture: "./Data/Images/Green2x2.png", }, }) ); @@ -149,7 +149,7 @@ describe( return stage.ready; }).then(function () { expect(scene).toRender([0, 255, 0, 255]); - stage.uniforms.texture = "./Data/Images/Blue2x2.png"; + stage.uniforms.inputTexture = "./Data/Images/Blue2x2.png"; return pollToPromise(function () { scene.renderForSpecs(); return stage.ready; @@ -174,9 +174,9 @@ describe( const stage = scene.postProcessStages.add( new PostProcessStage({ fragmentShader: - "uniform sampler2D texture; void main() { gl_FragColor = texture2D(texture, vec2(0.5)); }", + "uniform sampler2D inputTexture; void main() { out_FragColor = texture(inputTexture, vec2(0.5)); }", uniforms: { - texture: image, + inputTexture: image, }, }) ); @@ -190,7 +190,11 @@ describe( }); it("does not run a stage that requires depth textures when depth textures are not supported", function () { - const s = createScene(); + const s = createScene({ + contextOptions: { + requestWebgl1: true, + }, + }); s.context._depthTexture = false; if (defined(s._view.globeDepth)) { @@ -207,7 +211,7 @@ describe( const bgColor = 51; // Choose a factor of 255 to make sure there aren't rounding issues s.postProcessStages.add( new PostProcessStage({ - fragmentShader: `void main() { gl_FragColor = vec4(vec3(${ + fragmentShader: `void main() { out_FragColor = vec4(vec3(${ bgColor / 255 }), 1.0); }`, }) @@ -216,7 +220,7 @@ describe( const stage = s.postProcessStages.add( new PostProcessStage({ fragmentShader: - "uniform sampler2D depthTexture; void main() { gl_FragColor = vec4(1.0); }", + "uniform sampler2D depthTexture; void main() { out_FragColor = vec4(1.0); }", }) ); return pollToPromise(function () { @@ -249,12 +253,12 @@ describe( ).then(function (model) { const fs = "uniform sampler2D colorTexture; \n" + - "varying vec2 v_textureCoordinates; \n" + + "in vec2 v_textureCoordinates; \n" + "void main() { \n" + " if (czm_selected(v_textureCoordinates)) { \n" + - " gl_FragColor = texture2D(colorTexture, v_textureCoordinates); \n" + + " out_FragColor = texture(colorTexture, v_textureCoordinates); \n" + " } else { \n" + - " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); \n" + + " out_FragColor = vec4(1.0, 0.0, 0.0, 1.0); \n" + " } \n" + "} \n"; const stage = scene.postProcessStages.add( @@ -278,7 +282,7 @@ describe( it("destroys", function () { const stage = new PostProcessStage({ - fragmentShader: "void main() { gl_FragColor = vec4(1.0); }", + fragmentShader: "void main() { out_FragColor = vec4(1.0); }", }); expect(stage.isDestroyed()).toEqual(false); stage.destroy(); diff --git a/packages/engine/Specs/Scene/SceneSpec.js b/packages/engine/Specs/Scene/SceneSpec.js index ac03d760e8a8..d747408416ce 100644 --- a/packages/engine/Specs/Scene/SceneSpec.js +++ b/packages/engine/Specs/Scene/SceneSpec.js @@ -69,7 +69,7 @@ describe( sources: ["void main() { gl_Position = vec4(1.0); }"], }), fragmentShaderSource: new ShaderSource({ - sources: ["void main() { gl_FragColor = vec4(1.0); }"], + sources: ["void main() { out_FragColor = vec4(1.0); }"], }), }); simpleRenderState = new RenderState(); diff --git a/packages/engine/Specs/Scene/ShadowMapSpec.js b/packages/engine/Specs/Scene/ShadowMapSpec.js index cc1d93085a04..90b1e99c1eca 100644 --- a/packages/engine/Specs/Scene/ShadowMapSpec.js +++ b/packages/engine/Specs/Scene/ShadowMapSpec.js @@ -448,9 +448,9 @@ describe( return color; } - function renderAndCall(expectationCallback, time) { + function renderAndCall(expectationCallback, time, customScene) { expect({ - scene: scene, + scene: defined(customScene) ? customScene : scene, time: time, primeShadowMap: true, }).toRenderAndCall(function (rgba) { @@ -1060,7 +1060,7 @@ describe( }); }); - function depthFramebufferSupported() { + function depthFramebufferSupported(scene) { const framebuffer = new Framebuffer({ context: scene.context, depthStencilTexture: new Texture({ @@ -1079,41 +1079,62 @@ describe( box.show = true; floor.show = true; - createCascadedShadowMap(); + // Create a WebGL 1 scene + const sceneWithWebgl1 = createScene({ + contextOptions: { + requestWebgl1: true, + }, + }); + const lightCamera = new Camera(scene); + sceneWithWebgl1.shadowMap = new ShadowMap({ + context: sceneWithWebgl1.context, + lightCamera: lightCamera, + }); - renderAndCall(function (rgba) { - if (scene.context.depthTexture) { - if (depthFramebufferSupported()) { - expect(scene.shadowMap._usesDepthTexture).toBe(true); - expect(scene.shadowMap._shadowMapTexture.pixelFormat).toEqual( - PixelFormat.DEPTH_STENCIL - ); - } else { - // Depth texture extension is supported, but it fails to create create a depth-only FBO - expect(scene.shadowMap._usesDepthTexture).toBe(false); - expect(scene.shadowMap._shadowMapTexture.pixelFormat).toEqual( - PixelFormat.RGBA - ); + renderAndCall( + function (rgba) { + if (sceneWithWebgl1.context.depthTexture) { + if (depthFramebufferSupported(sceneWithWebgl1)) { + expect(sceneWithWebgl1.shadowMap._usesDepthTexture).toBe(true); + expect( + sceneWithWebgl1.shadowMap._shadowMapTexture.pixelFormat + ).toEqual(PixelFormat.DEPTH_STENCIL); + } else { + // Depth texture extension is supported, but it fails to create create a depth-only FBO + expect(sceneWithWebgl1.shadowMap._usesDepthTexture).toBe(false); + expect( + sceneWithWebgl1.shadowMap._shadowMapTexture.pixelFormat + ).toEqual(PixelFormat.RGBA); + } } - } - }); + }, + undefined, + sceneWithWebgl1 + ); - scene.shadowMap = scene.shadowMap && scene.shadowMap.destroy(); + sceneWithWebgl1.shadowMap = + sceneWithWebgl1.shadowMap && sceneWithWebgl1.shadowMap.destroy(); // Disable extension - const depthTexture = scene.context._depthTexture; - scene.context._depthTexture = false; - createCascadedShadowMap(); + sceneWithWebgl1.context._depthTexture = false; - renderAndCall(function (rgba) { - expect(scene.shadowMap._usesDepthTexture).toBe(false); - expect(scene.shadowMap._shadowMapTexture.pixelFormat).toEqual( - PixelFormat.RGBA - ); + sceneWithWebgl1.shadowMap = new ShadowMap({ + context: sceneWithWebgl1.context, + lightCamera: lightCamera, }); - // Re-enable extension - scene.context._depthTexture = depthTexture; + renderAndCall( + function (rgba) { + expect(sceneWithWebgl1.shadowMap._usesDepthTexture).toBe(false); + expect( + sceneWithWebgl1.shadowMap._shadowMapTexture.pixelFormat + ).toEqual(PixelFormat.RGBA); + }, + undefined, + sceneWithWebgl1 + ); + + sceneWithWebgl1.destroyForSpecs(); }); it("does not render shadows when the camera is far away from any shadow receivers", function () { diff --git a/packages/engine/Specs/Scene/ShadowVolumeAppearanceSpec.js b/packages/engine/Specs/Scene/ShadowVolumeAppearanceSpec.js index ba1f723db019..0b053191682d 100644 --- a/packages/engine/Specs/Scene/ShadowVolumeAppearanceSpec.js +++ b/packages/engine/Specs/Scene/ShadowVolumeAppearanceSpec.js @@ -19,9 +19,9 @@ import { Math as CesiumMath } from "../../index.js"; describe("Scene/ShadowVolumeAppearance", function () { // using ShadowVolumeAppearanceVS directly fails on Travis with the --release test const testVs = - "attribute vec3 position3DHigh;\n" + - "attribute vec3 position3DLow;\n" + - "attribute float batchId;\n" + + "in vec3 position3DHigh;\n" + + "in vec3 position3DLow;\n" + + "in float batchId;\n" + "void main() {\n" + " vec4 position = czm_computePosition();\n" + " gl_Position = czm_depthClamp(czm_modelViewProjectionRelativeToEye * position);\n" + diff --git a/packages/engine/Specs/Scene/TextureAtlasSpec.js b/packages/engine/Specs/Scene/TextureAtlasSpec.js index 3886c22bf907..b7acb31debd6 100644 --- a/packages/engine/Specs/Scene/TextureAtlasSpec.js +++ b/packages/engine/Specs/Scene/TextureAtlasSpec.js @@ -84,7 +84,7 @@ describe( `${ "uniform sampler2D u_texture;" + "void main() {" + - " gl_FragColor = texture2D(u_texture, vec2(" + " out_FragColor = texture(u_texture, vec2(" }${x}, ${y}));` + `}`; const uniformMap = { u_texture: function () { diff --git a/packages/engine/Specs/Scene/Vector3DTileGeometrySpec.js b/packages/engine/Specs/Scene/Vector3DTileGeometrySpec.js index e69049a32045..8a91e0fff2eb 100644 --- a/packages/engine/Specs/Scene/Vector3DTileGeometrySpec.js +++ b/packages/engine/Specs/Scene/Vector3DTileGeometrySpec.js @@ -30,15 +30,15 @@ describe( "Scene/Vector3DTileGeometry", function () { createGeometrySpecs({}); - const c = createContext({ requestWebgl1: false }); + const c = createContext({}); // Don't repeat WebGL 1 tests when WebGL 2 is not supported if (c.webgl2) { - createGeometrySpecs({ requestWebgl1: false }); + createGeometrySpecs({}); } c.destroyForSpecs(); function createGeometrySpecs(contextOptions) { - const webglMessage = contextOptions.requestWebgl1 ? "" : ": WebGL 2"; + const webglMessage = contextOptions.requestWebgl1 ? "" : "WebGL 2"; let scene; let rectangle; diff --git a/packages/engine/Specs/Scene/Vector3DTilePolygonsSpec.js b/packages/engine/Specs/Scene/Vector3DTilePolygonsSpec.js index 126679f32d13..9f2e022b9bf8 100644 --- a/packages/engine/Specs/Scene/Vector3DTilePolygonsSpec.js +++ b/packages/engine/Specs/Scene/Vector3DTilePolygonsSpec.js @@ -37,16 +37,16 @@ describe( createPolygonSpecs({}); if (testInWebGL2) { - const c = createContext({ requestWebgl1: false }); + const c = createContext({}); // Don't repeat WebGL 1 tests when WebGL 2 is not supported if (c.webgl2) { - createPolygonSpecs({ requestWebgl1: false }); + createPolygonSpecs({}); } c.destroyForSpecs(); } function createPolygonSpecs(contextOptions) { - const webglMessage = contextOptions.requestWebgl1 ? "" : ": WebGL 2"; + const webglMessage = contextOptions.requestWebgl1 ? "" : "WebGL 2"; let scene; let rectangle;