Git Product home page Git Product logo

pex-renderer's Introduction

pex-gl

npm version stability-stable npm minzipped size dependencies types Conventional Commits styled with prettier linted with eslint license

Create a RenderingContext (2d, webgl, webgl2, bitmaprenderer, webgpu) for use in PEX.

Installation

npm install pex-gl

Usage

import createRenderingContext, { FALLBACKS } from "pex-gl";

// Creates a webgl context filling the window
const context = createRenderingContext();

// Creates a webgl context from an existing canvas and keeps its size
const context = createRenderingContext({ canvas });

// Creates a webgl context on a new canvas with given width and height
const context = createRenderingContext({ width, height });

// Creates a new canvas of type "webgpu"
const context = createRenderingContext({ type: "webgpu" });

// Creates a new canvas of type "webgl" or fallback to experimental-webgl in case it fails
const context = createRenderingContext({ type: "webgl" });

// Disable fallbacks for "webgl2"
FALLBACKS.webgl2 = [];
// Creates a new canvas of type "webgl2" and return null in case it fails
const context = createRenderingContext({ type: "webgl2" });

API

Constants

FALLBACKS

Context fallbacks map

Functions

createRenderingContext([opts])RenderingContext

Creates a rendering context.

Typedefs

Options : object

Options for context creation. All optional.

FALLBACKS

Context fallbacks map

Kind: global constant

createRenderingContext([opts]) ⇒ RenderingContext

Creates a rendering context.

Kind: global function

Param Type Default
[opts] Options {}

Options : object

Options for context creation. All optional.

Kind: global typedef Properties

Name Type Default Description
[width] number window.innerWidth Request an initial canvas width.
[height] number window.innerHeight Request an initial canvas height.
[pixelRatio] boolean 1 Multiply canvas dimensions with a given ratio.
[fullscreen] boolean !opts.width && !opts.height Make the canvas fullscreen.
[type] "2d" | "bitmaprenderer" | "webgl" | "webgl2" | "webgpu" "webgl" A "contextType" for getContext.
[element] HTMLElement document.body Element to append the canvas to.
[...contextAttributes] CanvasRenderingContext2DSettings | WebGLContextAttributes {} Attributes to be passed to getContext.

License

MIT. See license file.

pex-renderer's People

Contributors

dependabot[bot] avatar dmnsgn avatar simonharrisco avatar vorg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pex-renderer's Issues

Transparent postprocessing

Currently with post-processing on the resulting scene has black background.

screen shot 2018-07-19 at 23 13 20

So no point doing postprocessing. How can i pack HDR in RGBA and transparency? Probably not possible and have to stick to forward rendering on top of the map.

Octahedral maps for PREM

There are problems with using CubeMaps for Prefiltered Mipmaped Radiance Environment Maps

  • textureCubeLod is still not supported in Firefox on OSX
  • seamless cubemap filtering is not available in WebGL 1
  • most importantly we can't render to HDR CubeMap mipmap levels > 0 on iOS

Use Octahedral maps as described in WebGL Insights: HDR Rendering could solve all that issues.

screen shot 2016-05-04 at 10 45 43

Remove unused dependencies

Running

depcheck --ignore-dirs=examples,experiments

returns quite a lot of old unused stuff still being installed

Unused dependencies
* async
* gl-constants
* glsl-atmosphere
* glsl-fxaa
* glsl-gamma
* glsl-inverse
* glsl-perturb-normal
* glsl-random
* glsl-transpose
* is-mobile
* pex-cam
* pex-context
* pex-draw
* pex-gl
* pex-gui
* pex-io
* primitive-cube
* primitive-sphere
* scene-tree
Missing dependencies
* plask
* glslify-sync

Broken shadows on Radeon Pro 460 and Intel HD Graphics 630

dcylobuwsaefqb8 jpg-large

Works on my old GeForce and Intel GPU

The problem seems to be with addressing array of depth maps for directional lights

#define NUM_LIGHTS 1

// gl.DEPTH_COMPONENT, NEAREST, NEAREST
uniform sampler2D uDirectionalLightShadowMap;
uniform sampler2D uDirectionalLightShadowMaps[NUM_LIGHTS];

// not working
// get 0 or 1 on Radeon Pro 460
// get 0 on Intel HD Graphics 630
for (int i = 0; i < NUM_LIGHTS; i++) {
 float depth = texture2D(uDirectionalLightShadowMaps[i], uv).r;
}

// working, I get depth gradient
float depth = texture2D(uDirectionalLightShadowMap, lightUV).r;
float depth = texture2D(uDirectionalLightShadowMaps[0], lightUV).r;

Although separated use case (bunny with shadows in raw pex-context) can't recreate the issue.

Handle window resize

With the latest code (pex-renderer and pex-context) the following is now possible:

window.addEventListener('resize', () => {
  const W = window.innerWidth
  const H = window.innerHeight
  ctx.gl.canvas.width = W // ctx will pickup that change and update default viewport
  ctx.gl.canvas.height = H
  cameraEnt.getComponent('Camera').set({
    viewport: [0, 0, W, H]
  })
})

You need to update only Camera as all width/height code has been removed from the Renderer itself.

This ctx.gl.canvas.width is a bit ugly so alternatively we could do

window.addEventListener('resize', () => {
  ctx.resize(window.innerWidth, window.innerHeight)
  cameraEnt.getComponent('Camera').set({
    viewport: [0, 0, window.innerWidth, window.innerHeight]
  })
})

There is a question about "retina resolution" that requires the following code.

window.addEventListener('resize2', () => {
  const W = window.innerWidth
  const H = window.innerHeight
  ctx.gl.canvas.width = W * 2
  ctx.gl.canvas.height = H * 2
  ctx.gl.canvas.style.width = W + 'px'
  ctx.gl.canvas.style.height = H + 'px'

  cameraEnt.getComponent('Camera').set({
    viewport: [0, 0, W * 2, H * 2]
  })
})

Changing it to the ctx.resize version is ambiguous...

ctx.resize(W * 2, H * 2) // who sets canvas.style.width = W ?
ctx.resize(W, H, 2) //?
ctx.resize(W, H, { pixelRatio: 2 }) //?
ctx.resize(H, H, { scale: 2 }) //?

// and additionally
var ctx = createContext({ width: W, height: H, pixelRatio: 2 })
//ctx.defaultState.viewport[2] is now W * 2...

Z-Prepass

Render z-buffer first to avoid duplicated pixel shader work.

This would also allow to compute SSAO in advance and use when shading.

Fallback for max num supported textures

Adding more lights with shadows maps can bump number of textures higher than max supported (e.g. 16). Additional lights should have shadows disabled or a warning issued.

DOF

Could be done using depth aware bilateral box blur like SSAO

DOF bug

Macbook Pro (Retina, 13-inch, Mid 2014)
Intel Iris 1536 MB

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.