Skip to content

Commit 3f6fd06

Browse files
mvaligurskyMartin Valigursky
andauthored
Improved point rendering on WebGL2 (#7706)
Co-authored-by: Martin Valigursky <[email protected]>
1 parent e9a8b53 commit 3f6fd06

File tree

5 files changed

+99
-0
lines changed

5 files changed

+99
-0
lines changed
8.07 MB
Binary file not shown.
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// @config DESCRIPTION This example demonstrates the clear coat material. Visually, the Coated column should contain highlights from both the Base and Boating layers.
2+
import { deviceType, rootPath } from 'examples/utils';
3+
import * as pc from 'playcanvas';
4+
5+
const canvas = /** @type {HTMLCanvasElement} */ (document.getElementById('application-canvas'));
6+
window.focus();
7+
8+
const assets = {
9+
orbitCamera: new pc.Asset('script', 'script', { url: `${rootPath}/static/scripts/camera/orbit-camera.js` }),
10+
helipad: new pc.Asset(
11+
'helipad-env-atlas',
12+
'texture',
13+
{ url: `${rootPath}/static/assets/cubemaps/morning-env-atlas.png` },
14+
{ type: pc.TEXTURETYPE_RGBP, mipmaps: false }
15+
),
16+
model: new pc.Asset('model', 'container', { url: `${rootPath}/static/assets/models/PrimitiveModeNormalsTest.glb` })
17+
};
18+
19+
const gfxOptions = {
20+
deviceTypes: [deviceType],
21+
glslangUrl: `${rootPath}/static/lib/glslang/glslang.js`,
22+
twgslUrl: `${rootPath}/static/lib/twgsl/twgsl.js`
23+
};
24+
25+
const device = await pc.createGraphicsDevice(canvas, gfxOptions);
26+
device.maxPixelRatio = Math.min(window.devicePixelRatio, 2);
27+
28+
const createOptions = new pc.AppOptions();
29+
createOptions.graphicsDevice = device;
30+
createOptions.mouse = new pc.Mouse(document.body);
31+
createOptions.touch = new pc.TouchDevice(document.body);
32+
createOptions.keyboard = new pc.Keyboard(document.body);
33+
34+
createOptions.componentSystems = [
35+
pc.RenderComponentSystem,
36+
pc.CameraComponentSystem,
37+
pc.LightComponentSystem,
38+
pc.ScriptComponentSystem
39+
];
40+
createOptions.resourceHandlers = [pc.TextureHandler, pc.ContainerHandler, pc.ScriptHandler];
41+
42+
const app = new pc.AppBase(canvas);
43+
app.init(createOptions);
44+
45+
// Set the canvas to fill the window and automatically change resolution to be the same as the canvas size
46+
app.setCanvasFillMode(pc.FILLMODE_FILL_WINDOW);
47+
app.setCanvasResolution(pc.RESOLUTION_AUTO);
48+
49+
// Ensure canvas is resized when window changes size
50+
const resize = () => app.resizeCanvas();
51+
window.addEventListener('resize', resize);
52+
app.on('destroy', () => {
53+
window.removeEventListener('resize', resize);
54+
});
55+
56+
const assetListLoader = new pc.AssetListLoader(Object.values(assets), app.assets);
57+
assetListLoader.load(() => {
58+
app.start();
59+
60+
// Setup skydome
61+
app.scene.envAtlas = assets.helipad.resource;
62+
app.scene.skyboxIntensity = 1;
63+
64+
const testEntity = assets.model.resource.instantiateRenderEntity();
65+
testEntity.setLocalEulerAngles(0, 90, 0);
66+
app.root.addChild(testEntity);
67+
68+
// Create a camera with an orbit camera script
69+
const camera = new pc.Entity();
70+
camera.addComponent('camera', {
71+
toneMapping: pc.TONEMAP_ACES
72+
});
73+
camera.addComponent('script');
74+
camera.script.create('orbitCamera', {
75+
attributes: {
76+
inertiaFactor: 0.2
77+
}
78+
});
79+
camera.script.create('orbitCameraInputMouse');
80+
camera.script.create('orbitCameraInputTouch');
81+
app.root.addChild(camera);
82+
camera.script.orbitCamera.yaw = 90;
83+
camera.script.orbitCamera.distance = 25;
84+
85+
const directionalLight = new pc.Entity();
86+
directionalLight.addComponent('light', {
87+
type: 'directional',
88+
color: pc.Color.YELLOW,
89+
castShadows: false,
90+
intensity: 1
91+
});
92+
directionalLight.setEulerAngles(45, 180, 0);
93+
app.root.addChild(directionalLight);
94+
});
95+
96+
export { app };
3.88 KB
Loading
668 Bytes
Loading

src/scene/shader-lib/glsl/chunks/lit/vert/litMain.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ void main(void) {
6767
6868
#include "litUserMainStartVS"
6969
70+
// default point size to 1 in case the shader is used with points
71+
gl_PointSize = 1.0;
72+
7073
gl_Position = getPosition();
7174
vPositionW = getWorldPosition();
7275

0 commit comments

Comments
 (0)