erebus

changeset 5:9621beb22694

huh?
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 24 May 2014 02:20:44 +0300
parents 93894c232d65
children bb006fb96f1b
files liberebus/src/camera.cc liberebus/src/camera.h liberebus/src/color.h liberebus/src/erebus.cc src/main.cc
diffstat 5 files changed, 26 insertions(+), 9 deletions(-) [+]
line diff
     1.1 --- a/liberebus/src/camera.cc	Tue Apr 29 07:38:40 2014 +0300
     1.2 +++ b/liberebus/src/camera.cc	Sat May 24 02:20:44 2014 +0300
     1.3 @@ -10,6 +10,7 @@
     1.4  	cached_matrix_valid = false;
     1.5  
     1.6  	rdir_cache_width = rdir_cache_height = 0;
     1.7 +	rdir_cache_fov = 0;
     1.8  	rdir_cache = 0;
     1.9  }
    1.10  
    1.11 @@ -20,6 +21,7 @@
    1.12  	cached_matrix_valid = false;
    1.13  
    1.14  	rdir_cache_width = rdir_cache_height = 0;
    1.15 +	rdir_cache_fov = 0;
    1.16  	rdir_cache = 0;
    1.17  }
    1.18  
    1.19 @@ -31,9 +33,6 @@
    1.20  void Camera::set_fov(float vfov)
    1.21  {
    1.22  	this->vfov = vfov;
    1.23 -
    1.24 -	// invalidate the dir cache
    1.25 -	delete [] rdir_cache;
    1.26  }
    1.27  
    1.28  float Camera::get_fov() const
    1.29 @@ -80,8 +79,9 @@
    1.30  {
    1.31  #pragma omp single
    1.32  	{
    1.33 -		if(!rdir_cache || rdir_cache_width != xsz || rdir_cache_height != ysz) {
    1.34 -			printf("calculating primary ray direction cache\n");
    1.35 +		if(!rdir_cache || rdir_cache_width != xsz || rdir_cache_height != ysz ||
    1.36 +				fabs(rdir_cache_fov - vfov) > 1e-4) {
    1.37 +			printf("calculating primary ray direction cache (%dx%d)\n", xsz, ysz);
    1.38  
    1.39  			delete [] rdir_cache;
    1.40  			rdir_cache = new Vector3[xsz * ysz];
    1.41 @@ -102,6 +102,7 @@
    1.42  			}
    1.43  			rdir_cache_width = xsz;
    1.44  			rdir_cache_height = ysz;
    1.45 +			rdir_cache_fov = vfov;
    1.46  		}
    1.47  	}
    1.48  
     2.1 --- a/liberebus/src/camera.h	Tue Apr 29 07:38:40 2014 +0300
     2.2 +++ b/liberebus/src/camera.h	Sat May 24 02:20:44 2014 +0300
     2.3 @@ -13,6 +13,7 @@
     2.4  
     2.5  	mutable Vector3 *rdir_cache;
     2.6  	mutable int rdir_cache_width, rdir_cache_height;
     2.7 +	mutable float rdir_cache_fov;
     2.8  
     2.9  	virtual void calc_matrix(Matrix4x4 *mat) const = 0;
    2.10  
     3.1 --- a/liberebus/src/color.h	Tue Apr 29 07:38:40 2014 +0300
     3.2 +++ b/liberebus/src/color.h	Sat May 24 02:20:44 2014 +0300
     3.3 @@ -3,7 +3,7 @@
     3.4  
     3.5  #include "vmath/vector.h"
     3.6  
     3.7 -typedef Vector3 Color;
     3.8 +typedef Vector4 Color;
     3.9  
    3.10  inline float color_luminance(const Color &c) { return c[0] * 0.2126 + c[1] * 0.7152 + c[2] * 0.0722; }
    3.11  
     4.1 --- a/liberebus/src/erebus.cc	Tue Apr 29 07:38:40 2014 +0300
     4.2 +++ b/liberebus/src/erebus.cc	Sat May 24 02:20:44 2014 +0300
     4.3 @@ -7,6 +7,7 @@
     4.4  #include "image.h"
     4.5  #include "scene.h"
     4.6  #include "geomobj.h"
     4.7 +#include "rt.h"
     4.8  
     4.9  using namespace std::chrono;
    4.10  
    4.11 @@ -175,7 +176,18 @@
    4.12  
    4.13  static void render_pixel(struct erebus *ctx, int x, int y)
    4.14  {
    4.15 -	float *pix = ctx->fbimg.get_pixels() + (y * ctx->fbimg.get_width() + x) * 4;
    4.16 -	pix[0] = pix[1] = pix[2] = 0.0f;
    4.17 -	pix[3] = 1.0f;
    4.18 +	Camera *cam = ctx->scn->get_active_camera();
    4.19 +	if(!cam) return;
    4.20 +
    4.21 +	int xsz = ctx->fbimg.get_width();
    4.22 +	int ysz = ctx->fbimg.get_height();
    4.23 +	float *pix = ctx->fbimg.get_pixels() + (y * xsz + x) * 4;
    4.24 +
    4.25 +	Ray ray = cam->get_primary_ray(x, y, xsz, ysz, 0);
    4.26 +	//Color c = ray_trace(ray, ctx->scn, 0);
    4.27 +	Color c = ray.dir.normalized() * 0.5 + Vector3(0.5, 0.5, 0.5);
    4.28 +	pix[0] = 1.0;//c.x;
    4.29 +	pix[1] = c.y;
    4.30 +	pix[2] = c.z;
    4.31 +	pix[3] = c.w;
    4.32  }
     5.1 --- a/src/main.cc	Tue Apr 29 07:38:40 2014 +0300
     5.2 +++ b/src/main.cc	Sat May 24 02:20:44 2014 +0300
     5.3 @@ -44,6 +44,9 @@
     5.4  
     5.5  static bool init()
     5.6  {
     5.7 +	width = glutGet(GLUT_WINDOW_WIDTH);
     5.8 +	height = glutGet(GLUT_WINDOW_HEIGHT);
     5.9 +
    5.10  	if(!(erb = erb_init())) {
    5.11  		return false;
    5.12  	}