Back to Parent

AFRAME.registerShader('depth-shader', {
  schema: {
    color: {type: 'vec3', is: 'uniform'},
  },

  vertexShader: [
    'varying vec3 viewPos;',
    'void main(void) {',
    '  viewPos = (modelViewMatrix * vec4(position, 1.0)).xyz;',
    '  gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);',
    '}'
  ].join('\n'),

  fragmentShader: [
    'varying vec3 viewPos;',
    'uniform vec3 color;',
    'void main() {',
    '  float depth = -viewPos.z - 18.0;',
    '  gl_FragColor.rgb = vec3(depth, depth, depth);',
    '  gl_FragColor.a = 1.0;',
    '}'
  ].join('\n')
});
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0