Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove final references to WebGL1 from the examples #6313

Merged
merged 2 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ PlayCanvas 是一款使用 HTML5 和 WebGL 技术运行游戏以及其他 3D 内

PlayCanvas 是一款优秀的全功能游戏引擎。

- 🧊 **图形** - 基于 WebGL1&2 的超前 2D + 3D 图形引擎
- 🧊 **图形** - 基于 WebGL2 的超前 2D + 3D 图形引擎
- 🏃 **动画** - 基于状态的强大动画功能,有效展现动画角色和随机场景属性
- ⚛️ **物理** - 一体化的 3D 刚体物理引擎 [ammo.js](https://github.com/kripken/ammo.js)
- 🎮 **输入** - 支持鼠标,键盘,触控,游戏控制器以及众多 VR 控制器 API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,6 @@ assetListLoader.load(() => {
spotlight.rotateLocal(90, 0, 0);
});

// display shadow texture (debug feature, only works when depth is stored as color, which is webgl1)
// app.drawTexture(-0.7, 0.7, 0.4, 0.4, app.renderer.lightTextureAtlas.shadowAtlas.texture);

// display cookie texture (debug feature)
if (debugAtlas) {
// @ts-ignore engine-tsd
Expand Down
2 changes: 1 addition & 1 deletion examples/src/examples/graphics/grab-pass/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default {
// get background pixel color with distorted offset
vec3 grabColor = texture2DLodEXT(uSceneColorMap, grabUv + offset, mipmap).rgb;

// tint the material based on mipmap, on WebGL2 only, as WebGL1 does not support non-constant array indexing
// tint the material based on mipmap
// (note - this could be worked around by using a series of if statements in this case)
#ifdef GL2
float tintIndex = clamp(mipmap, 0.0, 3.0);
Expand Down
10 changes: 1 addition & 9 deletions examples/src/examples/graphics/integer-textures/controls.mjs
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
import * as pc from 'playcanvas';

/**
* @param {import('../../../app/components/Example.mjs').ControlOptions} options - The options.
* @returns {JSX.Element} The returned JSX Element.
*/
export function controls({ observer, ReactPCUI, jsx, fragment }) {
const { BindingTwoWay, Container, Button, InfoBox, LabelGroup, Panel, SliderInput, SelectInput } = ReactPCUI;
const { BindingTwoWay, Container, Button, LabelGroup, Panel, SliderInput, SelectInput } = ReactPCUI;

return fragment(
jsx(InfoBox, {
icon: 'E218',
title: 'WebGL 1.0',
text: 'Integer textures are not supported on WebGL 1.0 devices',
hidden: !(pc.app?.graphicsDevice.isWebGL1 ?? false)
}),
jsx(
Panel,
{ headerText: 'Sand simulation' },
Expand Down
13 changes: 3 additions & 10 deletions examples/src/examples/graphics/integer-textures/example.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,9 @@ const createPixelRenderTarget = (i, colorBuffer) => {
// Create our integer pixel buffers and render targets
const pixelColorBuffers = [];
const pixelRenderTargets = [];
if (!device.isWebGL1) {
pixelColorBuffers.push(createPixelColorBuffer(0), createPixelColorBuffer(1));
pixelRenderTargets.push(createPixelRenderTarget(0, pixelColorBuffers[0]));
pixelRenderTargets.push(createPixelRenderTarget(1, pixelColorBuffers[1]));
}
pixelColorBuffers.push(createPixelColorBuffer(0), createPixelColorBuffer(1));
pixelRenderTargets.push(createPixelRenderTarget(0, pixelColorBuffers[0]));
pixelRenderTargets.push(createPixelRenderTarget(1, pixelColorBuffers[1]));

const sourceTexture = pixelColorBuffers[0];
const sourceRenderTarget = pixelRenderTargets[0];
Expand Down Expand Up @@ -153,7 +151,6 @@ const outputShader = pc.createShaderFromCode(

// Write the initial simulation state to the integer texture
const resetData = () => {
if (device.isWebGL1) return;
// Loop through the pixels in the texture
// and initialize them to either AIR, SAND or WALL
const sourceTextureData = sourceTexture.lock();
Expand Down Expand Up @@ -312,10 +309,6 @@ assetListLoader.load(() => {

let passNum = 0;
app.on('update', function (/** @type {number} */) {
if (device.isWebGL1) {
// WebGL1 does not support integer textures
return;
}

mouseUniform[0] = mousePos.x;
mouseUniform[1] = mousePos.y;
Expand Down
10 changes: 1 addition & 9 deletions examples/src/examples/graphics/texture-array/controls.mjs
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
import * as pc from 'playcanvas';

/**
* @param {import('../../../app/components/Example.mjs').ControlOptions} options - The options.
* @returns {JSX.Element} The returned JSX Element.
*/
export function controls({ observer, ReactPCUI, React, jsx, fragment }) {
const { InfoBox, BindingTwoWay, LabelGroup, Panel, BooleanInput } = ReactPCUI;
const { BindingTwoWay, LabelGroup, Panel, BooleanInput } = ReactPCUI;
return fragment(
jsx(InfoBox, {
icon: 'E218',
title: 'WebGL 1.0',
text: 'Texture Arrays are not supported on WebGL 1.0 devices',
hidden: !(pc.app?.graphicsDevice.isWebGL1 ?? false)
}),
jsx(
Panel,
{ headerText: 'Texture Arrays' },
Expand Down
5 changes: 0 additions & 5 deletions examples/src/examples/graphics/texture-array/example.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,6 @@ app.on('destroy', () => {
const assetListLoader = new pc.AssetListLoader(Object.values(assets), app.assets);
assetListLoader.load(() => {
app.start();

if (app.graphicsDevice.isWebGL1) {
return app;
}

app.scene.ambientLight = new pc.Color(0.2, 0.2, 0.2);

// Create directional light
Expand Down
23 changes: 3 additions & 20 deletions scripts/posteffects/posteffect-ssao.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,7 @@ function SSAOEffect(graphicsDevice, ssaoScript) {
" float ssDiskRadius = -(uProjectionScaleRadius / origin.z);",
"",
" float occlusion = 0.0;",

// webgl1 does not handle non-constant loop, work around it
graphicsDevice.isWebGL2 ? (
" for (float i = 0.0; i < uSampleCount.x; i += 1.0) {"
) : (
" const float maxSampleCount = 256.0;" +
" for (float i = 0.0; i < maxSampleCount; i += 1.0) {" +
" if (i >= uSampleCount.x) break;"
),

" for (float i = 0.0; i < uSampleCount.x; i += 1.0) {",
" computeAmbientOcclusionSAO(occlusion, i, ssDiskRadius, uv, origin, normal, tapPosition, noise);",
" tapPosition = angleStep * tapPosition;",
" }",
Expand Down Expand Up @@ -288,16 +279,8 @@ function SSAOEffect(graphicsDevice, ssaoScript) {
" float ssao = texture2D( uSSAOBuffer, vUv0 ).r;",
" float sum = ssao * totalWeight;",
"",

// webgl1 does not handle non-constant loop, work around it
graphicsDevice.isWebGL2 ? (
" for (int x = -uBilatSampleCount; x <= uBilatSampleCount; x++) {" +
" for (int y = -uBilatSampleCount; y < uBilatSampleCount; y++) {"
) : (
" for (int x = -4; x <= 4; x++) {" +
" for (int y = -4; y < 4; y++) {"
),

" for (int x = -uBilatSampleCount; x <= uBilatSampleCount; x++) {",
" for (int y = -uBilatSampleCount; y < uBilatSampleCount; y++) {",
" float weight = 1.0;",
" vec2 offset = vec2(x,y)*uResolution.zw;",
" tap(sum, totalWeight, weight, depth, uv + offset);",
Expand Down