glviewvol

diff src/rend_fast.cc @ 5:5417c25cb238

moving to a simpler transfer function
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 29 Dec 2014 15:59:55 +0200
parents 04330eb80b36
children f22be47a3572
line diff
     1.1 --- a/src/rend_fast.cc	Mon Dec 29 05:41:36 2014 +0200
     1.2 +++ b/src/rend_fast.cc	Mon Dec 29 15:59:55 2014 +0200
     1.3 @@ -3,6 +3,8 @@
     1.4  #include "rend_fast.h"
     1.5  #include "sdr.h"
     1.6  
     1.7 +static inline float smoothstep(float a, float b, float x);
     1.8 +
     1.9  #define XFER_MAP_SZ		1024
    1.10  
    1.11  static unsigned int sdr;
    1.12 @@ -55,6 +57,12 @@
    1.13  	return Renderer::transfer_curve(color);
    1.14  }
    1.15  
    1.16 +void RendererFast::set_simple_transfer(float low, float high)
    1.17 +{
    1.18 +	xfer_tex_valid = false;
    1.19 +	Renderer::set_simple_transfer(low, high);
    1.20 +}
    1.21 +
    1.22  void RendererFast::update(unsigned int msec)
    1.23  {
    1.24  	if(!vol) return;
    1.25 @@ -118,9 +126,18 @@
    1.26  
    1.27  		for(int i=0; i<XFER_MAP_SZ; i++) {
    1.28  			float x = (float)i / (float)(XFER_MAP_SZ - 1);
    1.29 +
    1.30 +			// TODO make 0.1 a tweakable parameter
    1.31 +			float val = smoothstep(xfer_low - 0.1, xfer_low + 0.1, x);
    1.32 +			val *= 1.0 - smoothstep(xfer_high - 0.1, xfer_high + 0.1, x);
    1.33 +			*pptr++ = val;
    1.34 +			*pptr++ = val;
    1.35 +			*pptr++ = val;
    1.36 +			/*
    1.37  			*pptr++ = xfer[0].value(x);
    1.38  			*pptr++ = xfer[1].value(x);
    1.39  			*pptr++ = xfer[2].value(x);
    1.40 +			*/
    1.41  		}
    1.42  
    1.43  		glBindTexture(GL_TEXTURE_1D, xfer_tex);
    1.44 @@ -168,3 +185,12 @@
    1.45  	glMatrixMode(GL_MODELVIEW);
    1.46  	glPopMatrix();
    1.47  }
    1.48 +
    1.49 +static inline float smoothstep(float a, float b, float x)
    1.50 +{
    1.51 +	if(x < a) return 0.0;
    1.52 +	if(x >= b) return 1.0;
    1.53 +
    1.54 +	x = (x - a) / (b - a);
    1.55 +	return x * x * (3.0 - 2.0 * x);
    1.56 +}