Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enabling an extension on a Three.js shader

How can I enable an extension on a Three.js shader?

My code so far:

getting extension:

var domElement = document.createElement( 'canvas' );
var gl = domElement.getContext('webgl') || domElement.getContext('experimental-webgl');
gl.getExtension('OES_standard_derivatives');

on my shader:

fragmentShader: [
    "#extension GL_OES_standard_derivatives : enable",
    "code..."
]...

The console output:
WARNING: 0:26: extension 'GL_OES_standard_derivatives' is not supported
ERROR: 0:32: 'dFdx' : no matching overloaded function found
ERROR: 0:32: '=' : cannot convert from 'const mediump float' to '2-component vector of float'
ERROR: 0:33: 'dFdy' : no matching overloaded function found
ERROR: 0:33: '=' : cannot convert from 'const mediump float' to '2-component vector of float'

After reading this issue on github, I tried this example: From http://jsfiddle.net/VJca4/ I get these errors

WARNING: 0:27: extension 'GL_OES_standard_derivatives' is not supported
ERROR: 0:30: '=' : cannot convert from 'const mediump float' to '2-component vector of float'
ERROR: 0:31: 'dFdx' : no matching overloaded function found
ERROR: 0:31: '=' : cannot convert from 'const mediump float' to '2-component vector of float'

like image 956
frank Avatar asked Jun 17 '12 13:06

frank


2 Answers

You should also be able to do this:

renderer.context.getExtension('OES_standard_derivatives');
like image 200
mrdoob Avatar answered Oct 20 '22 14:10

mrdoob


Found the error. You have to use the renderer's dom element:

var gl = renderer.domElement.getContext('webgl') ||
            renderer.domElement.getContext('experimental-webgl');
gl.getExtension('OES_standard_derivatives');
like image 25
frank Avatar answered Oct 20 '22 15:10

frank