flat assembler
Message board for the users of flat assembler.

Index > Windows > CPU raytracing draw triangle.

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1840
Roman 13 Jan 2019, 13:40
I found c++ example draw sphere.
RayIntersectSphere. Work fine. I not use camera. Very simple raytracing.

But i try use RayIntersectTriangle and not see triangle.
Code:
rayTriangleIntersect (Ray * r, Vec3 * v0, Vec3 * v1, Vec3 * v2){
  Vec3 v0v1 = sub (*v1, *v0);
  Vec3 v0v2 = sub (*v2, *v0);

  Vec3 pvec = cross (r->dir, v0v2);

  float det = dot (v0v1, pvec);
  if (det < 0.000001)
    return -INFINITY;

  float invDet = 1.0 / det;

  Vec3 tvec = sub (r->orig, *v0);

  float u = dot (tvec, pvec) * invDet;

  if (u < -0.0001 || u > 1.0001)
    return -INFINITY;

  Vec3 qvec = cross (tvec, v0v1);

  float v = dot (r->dir, qvec) * invDet;

  if (v < -0.0001 || u + v > 1.0001)
    return -INFINITY;

  return dot (v0v2, qvec) * invDet;   }
    

I check this code and my both work equally.
My RayOrigin.xyz = 0
My RayDir.xyz=(float 2DX,float 2DY ,-1.0);
I draw in BMP image size 500x500 and save to disk and look result.
Draw simple.
Code:
v0 = (0.0,0.0,0.1);
v1 = (0.01,0.0,0.1);
v2 = (0.002,0.01,0.1);
for int 2DY = 0 to 500; ++2DY {
for int 2DX = 0 to 500; ++2DX {
RayDir.xyz=(float 2DX,float 2DY ,-1.0); 
float r = rayTriangleIntersect(Ray,v0,v1,v2);
if (r != -INFINITY) drawone_pixel(2DX,2DY) }
}

    


Last edited by Roman on 14 Jan 2019, 07:10; edited 1 time in total
Post 13 Jan 2019, 13:40
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4061
Location: vpcmpistri
bitRAKE 13 Jan 2019, 22:01
Relative to your screen projection that is a very small triangle?
Post 13 Jan 2019, 22:01
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1840
Roman 14 Jan 2019, 07:04
In code need:
Code:
vec2 f = float(2DX,2DY);
f = (2.0 * f / 500.0 - 1.0);
RayDir.xyz=(f.x,f.y ,-1.0);
    

And i get small triangle in BMP file. On center of screen.
Post 14 Jan 2019, 07:04
View user's profile Send private message Reply with quote
macgub



Joined: 11 Jan 2006
Posts: 350
Location: Poland
macgub 27 May 2019, 17:48
Post 27 May 2019, 17:48
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.