Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8541541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:51:23+00:00 2026-06-11T11:51:23+00:00

I have a Three.js scene containing objects which have an immediateRenderCallback method. I have

  • 0

I have a Three.js scene containing objects which have an immediateRenderCallback method. I have also created a custom shader and I am trying to use MeshShaderMaterial(myShader).

The shader material works without warnings on basic Three.js objects.
Regular materials work fine on my custom immediateRenderCallback objects.

The shader material throws warnings when I use it on my custom immediateRenderCallback objects. These are the warnings:

    WebGL: INVALID_VALUE: enableVertexAttribArray: index out of range
    WebGL: INVALID_VALUE: vertexAttribPointer: index out of range

Now, despite these warnings, everything seems to be working fine. The objects appear, the shader works correctly, but I do not understand why these warnings appear and whether they can be safely ignored.

Here is my immediateRenderCallback function:

THREE.Segment.prototype.immediateRenderCallback = function ( program, _gl, _frustum )
{
    if ( ! this.__webglPositionNormalBuffer ) this.__webglPositionNormalBuffer = _gl.createBuffer();
    if ( ! this.__webglStripBuffer ) this.__webglStripBuffer = _gl.createBuffer();

    _gl.bindBuffer( _gl.ARRAY_BUFFER, this.__webglPositionNormalBuffer );
    _gl.bufferData( _gl.ARRAY_BUFFER, this.interleavedData, _gl.STATIC_DRAW );
    _gl.enableVertexAttribArray( program.attributes.position );
    _gl.enableVertexAttribArray( program.attributes.normal );
    _gl.vertexAttribPointer( program.attributes.position, 3, _gl.FLOAT, false, 24, 0 );
    _gl.vertexAttribPointer( program.attributes.normal, 3, _gl.FLOAT, false, 24, 12 );

    _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, this.__webglStripBuffer );
    _gl.bufferData( _gl.ELEMENT_ARRAY_BUFFER, this.stripData, _gl.STATIC_DRAW );

    for(var i=0; i<this.stripOffsets.length; i+=2)
    {
        var size = this.stripOffsets[i+1];
        var offset = this.stripOffsets[i]*2;
        _gl.drawElements( _gl.TRIANGLE_STRIP, size, _gl.UNSIGNED_SHORT, offset);
    }
}

Here is my shader:

'depthPacked': {
    uniforms: {},

    vertexShader: [
        "void main() {",
            "vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
            "gl_Position = projectionMatrix * mvPosition;",
        "}"
    ].join("\n"),

    fragmentShader: [
        "vec4 pack_depth( const in highp float depth ) {",
            "const highp vec4 bit_shift = vec4( 256.0, 256.0*256.0, 256.0*256.0*256.0, 0.0 );",
            "float power = floor(log2(depth));",
            "float mantissa = (power + 127.0) / 256.0;",
            "vec4 res = (depth/exp2(power)) * bit_shift;",
            "res = fract(floor(res) / 256.0);",
            "res.w = mantissa;",
            "return res;",
        "}",
        "void main() {",
            "gl_FragData[0] = pack_depth( gl_FragCoord.z );",
        "}"
    ].join("\n")
}

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:51:24+00:00Added an answer on June 11, 2026 at 11:51 am

    I’ve figured this out from a related problem here: WebGL: glsl attributes issue, getProgramParameter returns wrong number of attributes

    My custom immediateRenderCallback assigns values to the attributes position and normal, which are default attributes within Three.js. However, because my vertex shader does not utilize the normal attribute, the GLSL compiler optimizes out the normal attribute declaration, causing the immediateRenderCallback to complain because there is no normal attribute for it to assign data to!

    Because I’m using two different shaders (in two passes) on the same geometry and the other (phong) shader requires normal information, in the depth shader I simply assigned the normal attribute value to a varying in the vertex shader to prevent it from being optimized out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a scene in andEngine. The scene has basically three animated objects. I
I've created a scene which has many cubes, spheres, etc, in it, and have
I have a simple Three.js scene around which I want to move the camera.
I have three tables (individuals, groups & recordlabels) and want use the information between
I am trying to use Three.js to render a cube with 6 different images
I have created a scene in 3DS Max with a stock engine model and
I have an article container which has three aside tags inside it. The third
In THREE.js, if I have multiple calls to the JSONLoader to load multiple objects
I'm trying to create a simple Skybox using Three.js but have run into an
I have created a really simple model in Maya 8.5 to test in THREE.JS,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.