We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProcessing DevelopmentLibraries,  Tool Development › Defining a new renderer
Pages: 1 2 3 4 
Defining a new renderer (Read 7028 times)
Re: Defining a new renderer
Reply #15 - Apr 7th, 2006, 4:33pm
 
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.1) Gecko/20060324 Ubuntu/dapper Firefox/1.5.0.1

These are my system details.
Re: Defining a new renderer
Reply #16 - Apr 7th, 2006, 5:24pm
 
Ah right, on linux then.. no idea then I'm afraid. The dump file wont help, since I've no idea how those sorts of things work, this GL stuff is probably the deepest Java I've done, and even then it's not that complex...
Re: Defining a new renderer
Reply #17 - Apr 7th, 2006, 6:09pm
 
Ok, no worries.

Some friends of mine had the same problem with the older Jogl and JoglLauncher on Windows, but maybe now it has been fixed.  I'll check with them.

cheers
Re: Defining a new renderer
Reply #18 - Apr 8th, 2006, 7:55pm
 
More eye-candy.

I've finally managed to get the specular lighting sorted. Took ages to get anything to happen though.

Again this uses a GLSL shader to make the lighting per-pixel instead of per-vertex.

http://www.hardcorepawn.com/Specular/

(also during uploading this one, I worked out how to only need one copy of the jogl/jogl-native files on a website, and use them from each page individually)
Re: Defining a new renderer
Reply #19 - Apr 8th, 2006, 8:11pm
 
Hrm, I'm still seeing the polys quite a bit.  Is this normal?

...

Marcello
Re: Defining a new renderer
Reply #20 - Apr 8th, 2006, 8:53pm
 
Unfortunately yes, because of the triangulation, you get edges , but it's only a quick test sketch really.
Re: Defining a new renderer
Reply #21 - Apr 9th, 2006, 2:44am
 
No, I think there is something wrong with your normals.  It would look very smooth if the normals were correct.

Marcello
Re: Defining a new renderer
Reply #22 - Apr 9th, 2006, 12:14pm
 
The normals are right, I've checked, the problems is how the fragment shader interpolates the normals between the verticies to try to smooth it that's the problem, and there's not much I can do about it.

If you rotate the thing by 90' it's right, when the triangulation puts the divide horizontal, but when it's vertical (with respect to the viewer) you get the problem.
Re: Defining a new renderer
Reply #23 - Apr 9th, 2006, 2:38pm
 
that looks to me like quads drawn in the wrong order, i.e. instead of vertices a,b,c,d defining the shape it's a,c,b,d or something like that. any chance that's what's going on?
Re: Defining a new renderer
Reply #24 - Apr 9th, 2006, 2:46pm
 
No, since I'm drawing TRIANGLES, if it was a quad order problem there'd be holes, since every quad ends up looking like
Code:
|\  /|
| \/ |
| /\ |
|/ \|


I tried changing it to QUADS, and doing it as a TRIANGLE_STRIP and it looks the same. it's GL trying to be clever, and causing problems. removing the pixel-shader, and just letting GL od it per-vertex removes some of the artifacts, but it doesn't look as smooth.
Re: Defining a new renderer
Reply #25 - Apr 9th, 2006, 6:05pm
 
Can you post the source?
Re: Defining a new renderer
Reply #26 - Apr 9th, 2006, 6:59pm
 
Not so easy, since it relies on the new renderer I'm writing to make it work properly, so it'll be hard to test, but the basic part is:

Code:
void setup()
{
// size(800,600,"hardcorepawn.opengl.PGraphicsGL");
size(800,600,P3D);
camera(0,0,0,0,0,-1,0,-1,0);
perspective(PI/3.0,4.0/3.0,0.001,1000);
noStroke();
var=0;
verticies=new float[484][3];
}

void draw()
{
float mx=((mouseX-(width/2))/(float)width)*TWO_PI;
float my=((mouseY)/(float)height);

var-=0.04;
background(40);
camera(200*sin(mx),100*my,200*cos(mx),0,0,0,0,-1,0);
lightSpecular(255,200,100);
directionalLight(255,255,255,0,1,0);

fill(30,60,120);
ambient(30,30,30);
specular(200,180,100);
shininess(128.0);

for(int i=0;i<22;i++)
for(int j=0;j<22;j++)
verticies[j+i*22]=new float[]{(i-10)*10,10*sin(var+(sqrt(pow(i-10,2)+pow(j-10,2)))),(j-10)*10};

for(int i=1;i<20;i++)
{
beginShape(QUAD_STRIP);
for(int j=1;j<20;j++)
{
Vector norm=getNormal(i,j);
normal(norm.nx,norm.ny,norm.nz);
float[] f=verticies[(i)*22+j];
vertex(f[0],f[1],f[2]);
norm=getNormal(i+1,j);
normal(norm.nx,norm.ny,norm.nz);
f=verticies[(i+1)*22+j];
vertex(f[0],f[1],f[2]);
}
endShape();
}
if(frameCount%90==89)
println(framerate);
}


Vector getNormal(int x, int y)
{
Vector v1=new Vector(verticies[(x-1)*22+y][0],verticies[(x-1)*22+y][1],verticies[(x-1)*22+y][2]);
Vector v2=new Vector(verticies[(x+1)*22+y][0],verticies[(x+1)*22+y][1],verticies[(x+1)*22+y][2]);
Vector v3=new Vector(verticies[x*22+y-1][0],verticies[x*22+y-1][1],verticies[x*22+y-1][2]);
Vector v4=new Vector(verticies[x*22+y+1][0],verticies[x*22+y+1][1],verticies[x*22+y+1][2]);

return cross(dir(v3,v4),dir(v1,v2));
}

class Vector
{
float x,y,z;
float nx,ny,nz;
float mag;
Vector(float _x, float _y, float _z)
{
x=_x;
y=_y;
z=_z;

//calculate the normalised vector (vector of length 1) .. doesn't make sense for using vector for co-ords, but useful when an actual vector
mag=sqrt(x*x+y*y+z*z);
nx=x/mag;
ny=y/mag;
nz=z/mag;
}
}

Vector cross(Vector a, Vector b)
{
return new Vector(a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y-a.y*b.x);
}

Vector dir(Vector a, Vector b)
{
return new Vector(a.x-b.x,a.y-b.y,a.z-b.z);
}
Re: Defining a new renderer
Reply #27 - Apr 9th, 2006, 8:23pm
 
please don't use the name PGraphicsGL for your renderer, that's gonna cause serious problems should you ever release it.
Re: Defining a new renderer
Reply #28 - Apr 9th, 2006, 9:14pm
 
Oh I know, it's just there since I'm just editing a copy of the real PGraphicsGL and haven't got round to changing the name.
Re: Defining a new renderer
Reply #29 - Apr 9th, 2006, 9:14pm
 
That getNormal function doesn't look right to me, but I could be wrong (I don't have a great understanding of the vector math involved)...  It looks like you're doing a soft shading normal by using the 4 adjacent vertices.  But don't you also need to take into account the location of the current point in question?

Marcello
Pages: 1 2 3 4