Exemplo n.º 1
0
CBData *colorband_element_add(struct ColorBand *coba, float position)
{
	if (coba->tot == MAXCOLORBAND) {
		return NULL;
	}
	else if (coba->tot > 0) {
		CBData *xnew;
		float col[4];

		do_colorband(coba, position, col);

		xnew = &coba->data[coba->tot];
		xnew->pos = position;

		xnew->r = col[0];
		xnew->g = col[1];
		xnew->b = col[2];
		xnew->a = col[3];
	}

	coba->tot++;
	coba->cur = coba->tot - 1;

	colorband_update_sort(coba);

	return coba->data + coba->cur;
}
Exemplo n.º 2
0
static void node_composit_exec_valtorgb(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
	/* stack order in: fac */
	/* stack order out: col, alpha */
	
	if(out[0]->hasoutput==0 && out[1]->hasoutput==0) 
		return;
	
	if(node->storage) {
		/* input no image? then only color operation */
		if(in[0]->data==NULL) {
			do_colorband(node->storage, in[0]->vec[0], out[0]->vec);
		}
		else {
			/* make output size of input image */
			CompBuf *cbuf= in[0]->data;
			CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */
			
			composit1_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, do_colorband_composit, CB_VAL);
			
			out[0]->data= stackbuf;
			
			if(out[1]->hasoutput)
				out[1]->data= valbuf_from_rgbabuf(stackbuf, CHAN_A);

		}
	}
}
void ColorRampOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
{
	float values[4];

	this->m_inputProgram->readSampled(values, x, y, sampler);
	do_colorband(this->m_colorBand, values[0], output);
}
Exemplo n.º 4
0
static void valtorgb_colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
{
	if(node->storage) {
		float fac = tex_input_value(in[0], p, thread);

		do_colorband(node->storage, fac, out);
	}
}
Exemplo n.º 5
0
static int pointdensity_color(PointDensity *pd, TexResult *texres, float age, const float vec[3])
{
	int retval = 0;
	float col[4];

	retval |= TEX_RGB;

	switch (pd->color_source) {
		case TEX_PD_COLOR_PARTAGE:
			if (pd->coba) {
				if (do_colorband(pd->coba, age, col)) {
					texres->talpha = true;
					copy_v3_v3(&texres->tr, col);
					texres->tin *= col[3];
					texres->ta = texres->tin;
				}
			}
			break;
		case TEX_PD_COLOR_PARTSPEED:
		{
			float speed = len_v3(vec) * pd->speed_scale;

			if (pd->coba) {
				if (do_colorband(pd->coba, speed, col)) {
					texres->talpha = true;
					copy_v3_v3(&texres->tr, col);
					texres->tin *= col[3];
					texres->ta = texres->tin;
				}
			}
			break;
		}
		case TEX_PD_COLOR_PARTVEL:
			texres->talpha = true;
			mul_v3_v3fl(&texres->tr, vec, pd->speed_scale);
			texres->ta = texres->tin;
			break;
		case TEX_PD_COLOR_CONSTANT:
		default:
			texres->tr = texres->tg = texres->tb = texres->ta = 1.0f;
			break;
	}
	
	return retval;
}
Exemplo n.º 6
0
void colorband_table_RGBA(ColorBand *coba, float **array, int *size)
{
	int a;
	
	*size = CM_TABLE + 1;
	*array = MEM_callocN(sizeof(float) * (*size) * 4, "ColorBand");

	for (a = 0; a < *size; a++)
		do_colorband(coba, (float)a / (float)CM_TABLE, &(*array)[a * 4]);
}
Exemplo n.º 7
0
static void node_shader_exec_valtorgb(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
	/* stack order in: fac */
	/* stack order out: col, alpha */
	
	if(node->storage) {
		float fac;
		nodestack_get_vec(&fac, SOCK_VALUE, in[0]);

		do_colorband(node->storage, fac, out[0]->vec);
		out[1]->vec[0]= out[0]->vec[3];
	}
}
Exemplo n.º 8
0
static PyObject *Freestyle_evaluateColorRamp(PyObject *self, PyObject *args)
{
	BPy_StructRNA *py_srna;
	ColorBand *coba;
	float in, out[4];

	if (!(PyArg_ParseTuple(args, "O!f", &pyrna_struct_Type, &py_srna, &in)))
		return NULL;
	if (!RNA_struct_is_a(py_srna->ptr.type, &RNA_ColorRamp)) {
		PyErr_SetString(PyExc_TypeError, "1st argument is not a ColorRamp object");
		return NULL;
	}
	coba = (ColorBand *)py_srna->ptr.data;
	if (!do_colorband(coba, in, out)) {
		PyErr_SetString(PyExc_ValueError, "failed to evaluate the color ramp");
		return NULL;
	}
	return Vector_CreatePyObject(out, 4, Py_NEW, NULL);
}
Exemplo n.º 9
0
CBData *colorband_element_add(struct ColorBand *coba, float position)
{
	int a;

	if(coba->tot==MAXCOLORBAND) {
		return NULL;
	}
	else if(coba->tot > 0) {
		CBData *xnew;
		float col[4];

		do_colorband(coba, position, col);

		xnew = &coba->data[coba->tot];
		xnew->pos = position;

		xnew->r = col[0];
		xnew->g = col[1];
		xnew->b = col[2];
		xnew->a = col[3];
	}

	coba->tot++;
	coba->cur = coba->tot-1;

	for(a = 0; a < coba->tot; a++)
		coba->data[a].cur = a;

	qsort(coba->data, coba->tot, sizeof(CBData), vergcband);

	for(a = 0; a < coba->tot; a++) {
		if(coba->data[a].cur == coba->cur) {
			coba->cur = a;
			break;
		}
	}

	return coba->data + coba->cur;
}
Exemplo n.º 10
0
static void rna_ColorRamp_eval(struct ColorBand *coba, float position, float color[4])
{
	do_colorband(coba, position, color);
}
Exemplo n.º 11
0
int pointdensitytex(Tex *tex, float *texvec, TexResult *texres)
{
	int retval = TEX_INT;
	PointDensity *pd = tex->pd;
	PointDensityRangeData pdr;
	float density=0.0f, age=0.0f, time=0.0f;
	float vec[3] = {0.0f, 0.0f, 0.0f}, co[3];
	float col[4];
	float turb, noise_fac;
	int num=0;
	
	texres->tin = 0.0f;
	
	if ((!pd) || (!pd->point_tree))		
		return 0;
		
	init_pointdensityrangedata(pd, &pdr, &density, vec, &age, 
		(pd->flag&TEX_PD_FALLOFF_CURVE ? pd->falloff_curve : NULL), pd->falloff_speed_scale*0.001f);
	noise_fac = pd->noise_fac * 0.5f;	/* better default */
	
	VECCOPY(co, texvec);
	
	if (point_data_used(pd)) {
		/* does a BVH lookup to find accumulated density and additional point data *
		 * stores particle velocity vector in 'vec', and particle lifetime in 'time' */
		num = BLI_bvhtree_range_query(pd->point_tree, co, pd->radius, accum_density, &pdr);
		if (num > 0) {
			age /= num;
			mul_v3_fl(vec, 1.0f/num);
		}
		
		/* reset */
		density = vec[0] = vec[1] = vec[2] = 0.0f;
	}
	
	if (pd->flag & TEX_PD_TURBULENCE) {
	
		if (pd->noise_influence == TEX_PD_NOISE_AGE) {
			turb = BLI_gTurbulence(pd->noise_size, texvec[0]+age, texvec[1]+age, texvec[2]+age, pd->noise_depth, 0, pd->noise_basis);
		}
		else if (pd->noise_influence == TEX_PD_NOISE_TIME) {
			time = R.cfra / (float)R.r.efra;
			turb = BLI_gTurbulence(pd->noise_size, texvec[0]+time, texvec[1]+time, texvec[2]+time, pd->noise_depth, 0, pd->noise_basis);
			//turb = BLI_turbulence(pd->noise_size, texvec[0]+time, texvec[1]+time, texvec[2]+time, pd->noise_depth);
		}
		else {
			turb = BLI_gTurbulence(pd->noise_size, texvec[0]+vec[0], texvec[1]+vec[1], texvec[2]+vec[2], pd->noise_depth, 0, pd->noise_basis);
		}

		turb -= 0.5f;	/* re-center 0.0-1.0 range around 0 to prevent offsetting result */
		
		/* now we have an offset coordinate to use for the density lookup */
		co[0] = texvec[0] + noise_fac * turb;
		co[1] = texvec[1] + noise_fac * turb;
		co[2] = texvec[2] + noise_fac * turb;
	}

	/* BVH query with the potentially perturbed coordinates */
	num = BLI_bvhtree_range_query(pd->point_tree, co, pd->radius, accum_density, &pdr);
	if (num > 0) {
		age /= num;
		mul_v3_fl(vec, 1.0f/num);
	}
	
	texres->tin = density;
	BRICONT;
	
	if (pd->color_source == TEX_PD_COLOR_CONSTANT)
		return retval;
	
	retval |= TEX_RGB;
	
	switch (pd->color_source) {
		case TEX_PD_COLOR_PARTAGE:
			if (pd->coba) {
				if (do_colorband(pd->coba, age, col)) {
					texres->talpha= 1;
					VECCOPY(&texres->tr, col);
					texres->tin *= col[3];
					texres->ta = texres->tin;
				}
			}
			break;
		case TEX_PD_COLOR_PARTSPEED:
		{
			float speed = len_v3(vec) * pd->speed_scale;
			
			if (pd->coba) {
				if (do_colorband(pd->coba, speed, col)) {
					texres->talpha= 1;	
					VECCOPY(&texres->tr, col);
					texres->tin *= col[3];
					texres->ta = texres->tin;
				}
			}
			break;
		}
		case TEX_PD_COLOR_PARTVEL:
			texres->talpha= 1;
			mul_v3_fl(vec, pd->speed_scale);
			VECCOPY(&texres->tr, vec);
			texres->ta = texres->tin;
			break;
		case TEX_PD_COLOR_CONSTANT:
		default:
			texres->tr = texres->tg = texres->tb = texres->ta = 1.0f;
			break;
	}
	BRICONTRGB;
	
	return retval;
	
	/*
	if (texres->nor!=NULL) {
		texres->nor[0] = texres->nor[1] = texres->nor[2] = 0.0f;
	}
	*/
}
Exemplo n.º 12
0
void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *rect)
{
	ColorBand *coba;
	CBData *cbd;
	float x1, y1, sizex, sizey;
	float v3[2], v1[2], v2[2], v1a[2], v2a[2];
	int a;
	float pos, colf[4] = {0, 0, 0, 0}; /* initialize in case the colorband isn't valid */
	struct ColorManagedDisplay *display = NULL;

	coba = (ColorBand *)(but->editcoba ? but->editcoba : but->poin);
	if (coba == NULL) return;

	if (but->block->color_profile)
		display = ui_block_display_get(but->block);

	x1 = rect->xmin;
	y1 = rect->ymin;
	sizex = rect->xmax - x1;
	sizey = rect->ymax - y1;

	/* first background, to show tranparency */

	glColor4ub(UI_TRANSP_DARK, UI_TRANSP_DARK, UI_TRANSP_DARK, 255);
	glRectf(x1, y1, x1 + sizex, y1 + sizey);
	glEnable(GL_POLYGON_STIPPLE);
	glColor4ub(UI_TRANSP_LIGHT, UI_TRANSP_LIGHT, UI_TRANSP_LIGHT, 255);
	glPolygonStipple(checker_stipple_sml);
	glRectf(x1, y1, x1 + sizex, y1 + sizey);
	glDisable(GL_POLYGON_STIPPLE);

	glShadeModel(GL_FLAT);
	glEnable(GL_BLEND);
	
	cbd = coba->data;
	
	v1[0] = v2[0] = x1;
	v1[1] = y1;
	v2[1] = y1 + sizey;
	
	glBegin(GL_QUAD_STRIP);
	
	glColor4fv(&cbd->r);
	glVertex2fv(v1);
	glVertex2fv(v2);

	for (a = 1; a <= sizex; a++) {
		pos = ((float)a) / (sizex - 1);
		do_colorband(coba, pos, colf);
		if (display)
			IMB_colormanagement_scene_linear_to_display_v3(colf, display);
		
		v1[0] = v2[0] = x1 + a;
		
		glColor4fv(colf);
		glVertex2fv(v1);
		glVertex2fv(v2);
	}
	
	glEnd();
	glShadeModel(GL_FLAT);
	glDisable(GL_BLEND);
	
	/* outline */
	glColor4f(0.0, 0.0, 0.0, 1.0);
	fdrawbox(x1, y1, x1 + sizex, y1 + sizey);
	
	/* help lines */
	v1[0] = v2[0] = v3[0] = x1;
	v1[1] = y1;
	v1a[1] = y1 + 0.25f * sizey;
	v2[1] = y1 + 0.5f * sizey;
	v2a[1] = y1 + 0.75f * sizey;
	v3[1] = y1 + sizey;
	
	
	cbd = coba->data;
	glBegin(GL_LINES);
	for (a = 0; a < coba->tot; a++, cbd++) {
		v1[0] = v2[0] = v3[0] = v1a[0] = v2a[0] = x1 + cbd->pos * sizex;
		
		if (a == coba->cur) {
			glColor3ub(0, 0, 0);
			glVertex2fv(v1);
			glVertex2fv(v3);
			glEnd();
			
			setlinestyle(2);
			glBegin(GL_LINES);
			glColor3ub(255, 255, 255);
			glVertex2fv(v1);
			glVertex2fv(v3);
			glEnd();
			setlinestyle(0);
			glBegin(GL_LINES);
			
#if 0
			glColor3ub(0, 0, 0);
			glVertex2fv(v1);
			glVertex2fv(v1a);
			glColor3ub(255, 255, 255);
			glVertex2fv(v1a);
			glVertex2fv(v2);
			glColor3ub(0, 0, 0);
			glVertex2fv(v2);
			glVertex2fv(v2a);
			glColor3ub(255, 255, 255);
			glVertex2fv(v2a);
			glVertex2fv(v3);
#endif
		}
		else {
			glColor3ub(0, 0, 0);
			glVertex2fv(v1);
			glVertex2fv(v2);
			
			glColor3ub(255, 255, 255);
			glVertex2fv(v2);
			glVertex2fv(v3);
		}
	}
	glEnd();

}
Exemplo n.º 13
0
static void do_colorband_composit(bNode *node, float *out, float *in)
{
	do_colorband(node->storage, in[0], out);
}