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 8817949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:58:38+00:00 2026-06-14T04:58:38+00:00

I try to render lights on some models. All models have some uniques options

  • 0

I try to render lights on some models.
All models have some uniques options (scale, position, rotation). I create a matrix with all this options and change all model’s vertices from this matrix.

I have a big problem when the model has a negative scale, the normal is reversed and don’t looks like it should.

enter image description here

Here the code I use:

vec3.calcNormal = function( a, b, c, dest ) {
    var v1 = dest || vec3.create(), v2 = vec3.create();
    vec3.subtract( c, b, v1 );
    vec3.subtract( a, b, v2 );
    vec3.cross( v1, v2 );
    return vec3.normalize(v1);
};

// Apply matrix on vertices
size  = vertices.length;
vert  = new Array(size);
for( i=0; i<size; ++i ) {
    vert[i] = vec3.create();
    mat4.multiplyVec3(  matrix, vertices[i],  vert[i] );
}


// Generate face normals
face_normal    = new Array(faces.length);
for ( i=0, count=faces.length; i<count; ++i ) {
    face           = faces[i];
    face_normal[i] = vec3.create();

    vec3.calcNormal(
        vert[ face.vertidx[0] ],
        vert[ face.vertidx[1] ],
        vert[ face.vertidx[2] ],
        face_normal[i]
    );
}

Does someone know how to fix this problem ?
I tried to scale back the normal or don’t scale it at all, but It didn’t work.

Fixed with:

// Get normal matrix
mat3.transpose( mat4.toInverseMat3(matrix), normalMat );

// Apply matrix on vertices
size  = vertices.length;
vert  = new Array(size);
for( i=0; i<size; ++i ) {
    vert[i] = vec3.create();
    mat4.multiplyVec3(  matrix, vertices[i],  vert[i] );
}


// Generate face normals
face_normal    = new Array(faces.length);
for ( i=0, count=faces.length; i<count; ++i ) {
    face           = faces[i];
    face_normal[i] = vec3.create();

    vec3.calcNormal(
        vertices[ face.vertidx[0] ],
        vertices[ face.vertidx[1] ],
        vertices[ face.vertidx[2] ],
        face_normal[i]
    );

    mat3.multiplyVec3( normalMat, face_normal[i] );
}
  • 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-14T04:58:40+00:00Added an answer on June 14, 2026 at 4:58 am

    Negative scale value will flip your geometry: demo From here. If you need to shrink it you should use fraction value.

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

Sidebar

Related Questions

So I have this div <div id=result_text></div> And I try doing render :update do
I have a mvc web project where I try to render a list of
Can anyone give some clues as to why when I try to render the
When i try to render this svg sample, the line is bluring automatically and
I'm try to render a gradient background on some form elements. While it works
when I try to render the view, browser show this error 01:46:11,371 GRAVE [javax.enterprise.resource.webcontainer.jsf.application]
For some reason my textures look strange when I try to render them. XNA
I try create ruby class with included Enumarable So insode view I try render
I load obj models and try to render them with OpenGL ES using Android
I have some xml that looks like this: <rootElement attribute=' > '/> This is

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.