Jump to content


Photo

Lighting looks pixelated (3D)


  • Please log in to reply
2 replies to this topic

#1 loverock125

loverock125

    GMC Member

  • GMC Member
  • 1830 posts
  • Version:GM8.1

Posted 25 April 2012 - 01:37 AM

Hey everyone,

I'm not sure why, but I've just created a simple 3D model and normalised it but lighting looks very pixelated; as seen in the picture below (inside the spoiler).

Spoiler


This is the code I used to normalise it:

for (i=0; i<global.gridParts;i+=1) {
d3d_model_primitive_begin(terModel,pr_trianglelist);

    for (j=0; j<global.gridParts; j+=1) {
    x1 = i*global.gridSize;
    y1 = j*global.gridSize;
    z1 = ds_grid_get(heightGrid,i,j);
    x2 = (i+1)*global.gridSize;
    y2 = j*global.gridSize;
    z2 = ds_grid_get(heightGrid,i+1,j);
    x3 = (i+1)*global.gridSize;
    y3 = (j+1)*global.gridSize;
    z3 = ds_grid_get(heightGrid,i+1,j+1);
    nX = (y2-y1)*(z3-z1)-(y3-y1)*(z2-z1);
    nY = (z2-z1)*(x3-x1)-(z3-z1)*(x2-x1);
    nZ = (x2-x1)*(y3-y1)-(x3-x1)*(y2-y1);
    m = sqrt(nX*nX + nY*nY + nZ*nZ);
    nX /= m;
    nY /= m;
    nZ /= m;
  
    d3d_model_vertex_normal(terModel,x1,y1,z1,nX,nY,nZ);
    d3d_model_vertex_normal(terModel,x2,y2,z2,nX,nY,nZ);
    d3d_model_vertex_normal(terModel,x3,y3,z3,nX,nY,nZ);
    
    x1 = (i+1)*global.gridSize;
    y1 = (j+1)*global.gridSize;
    z1 = ds_grid_get(heightGrid,i+1,j+1);
    x2 = i*global.gridSize;
    y2 = (j+1)*global.gridSize;
    z2 = ds_grid_get(heightGrid,i,j+1);
    x3 = i*global.gridSize;
    y3 = j*global.gridSize;
    z3 = ds_grid_get(heightGrid,i,j);
    nX = (y2-y1)*(z3-z1)-(y3-y1)*(z2-z1);
    nY = (z2-z1)*(x3-x1)-(z3-z1)*(x2-x1);
    nZ = (x2-x1)*(y3-y1)-(x3-x1)*(y2-y1);
    m = sqrt(nX*nX + nY*nY + nZ*nZ);
    nX /= m;
    nY /= m;
    nZ /= m;

    d3d_model_vertex_normal(terModel,x1,y1,z1,nX,nY,nZ);
    d3d_model_vertex_normal(terModel,x2,y2,z2,nX,nY,nZ);
    d3d_model_vertex_normal(terModel,x3,y3,z3,nX,nY,nZ);
    }

d3d_model_primitive_end(terModel)
}


If this is normal, is there a way to achieve something smoother? Perhaps another method of normalising possible in GM?

Thank you very much,
I appreciate your help

Edited by loverock125, 25 April 2012 - 01:38 AM.

  • 0

#2 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 15937 posts
  • Version:GM:Studio

Posted 25 April 2012 - 01:55 AM

you have to set the vertex normal of each vertex to the average of all the facet normal of all the facets it is a member of. this will smooth the edges.
  • 1

#3 slayer 64

slayer 64

    Slayer of gingers

  • GMC Member
  • 3864 posts
  • Version:GM8.1

Posted 25 April 2012 - 02:38 AM

you are calculating the normal for each triangle. the normal is completely different for each triangle making each one a differnet color causing the "pixelation" calculate the normal for the points instead of the triangle.

these scripts will help
http://gmc.yoyogames...1
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users