Пример #1
0
void FP_SingleColour::process(const FragmentProcessorInput* input, FragmentProcessorOutput* output) const
{
	const PROCDATA_SINGLECOLOUR* inData = (const PROCDATA_SINGLECOLOUR*)input->user;

	float shadowFactor = PuresoftSamplerProjection::get(m_shadowTex, inData->shadowcoord);

	ALIGN16 float L[4];
	mcemaths_sub_3_4(L, m_lightPos, inData->worldPos);
	mcemaths_norm_3_4(L);

	ALIGN16 float E[4];
	mcemaths_sub_3_4(E, m_cameraPos, inData->worldPos);
	mcemaths_norm_3_4(E);

	ALIGN16 float H[4];
	mcemaths_add_3_4(H, E, L);
	mcemaths_norm_3_4(H);


	enum {LAMBERT, SPECULAR};
	ALIGN16 float factors[4];

	factors[LAMBERT] = mcemaths_dot_3_4(L, inData->normal);

	float yawOfLight = (float)acos(mcemaths_dot_3_4(L, m_lightDir));
	factors[LAMBERT] *= yawOfLight < fieldOfLight ? 1.0f : (float)opt_pow(cos(yawOfLight - fieldOfLight), 150);

	factors[SPECULAR] = opt_pow(mcemaths_dot_3_4(H, inData->normal), (unsigned int)*m_specularExponent);

	mcemaths_clamp_3_4(factors, 0, 1.0f);

	ALIGN16 float outputColour[4];
	mcemaths_quatcpy(outputColour, m_diffuse);
	mcemaths_mul_3_4(outputColour, factors[LAMBERT]);

	ALIGN16 float specularColour[4];
	mcemaths_quatcpy(specularColour, m_diffuse);
	mcemaths_mulvec_3_4(specularColour, m_specularColour);
	mcemaths_mul_3_4(specularColour, factors[SPECULAR]);

	ALIGN16 float ambientColour[4];
	mcemaths_quatcpy(ambientColour, m_diffuse);
	mcemaths_mulvec_3_4(ambientColour, m_ambient);

	mcemaths_add_3_4_ip(outputColour, specularColour);
	mcemaths_mul_3_4(outputColour, shadowFactor);
	mcemaths_add_3_4_ip(outputColour, ambientColour);
	mcemaths_clamp_3_4(outputColour, 0, 1.0f);

	mcemaths_mul_3_4(outputColour, 255.0f);

	PURESOFTBGRA bytesColour;
	bytesColour.elems.r = (unsigned char)outputColour[2];
	bytesColour.elems.g = (unsigned char)outputColour[1];
	bytesColour.elems.b = (unsigned char)outputColour[0];
	bytesColour.elems.a = 0;

	output->write4(0, &bytesColour);
}
Пример #2
0
void FP_DiffuseOnly::process(const FragmentProcessorInput* input, FragmentProcessorOutput* output) const
{
	PURESOFTBGRA bytesColour;
	ALIGN16 float outputColour[4], ambiemtColour[4];

	const PROCDATA_DIFFUSEONLY* inData = (const PROCDATA_DIFFUSEONLY*)input->user;

	float shadowFactor = PuresoftSamplerProjection::get(m_shadowTex, inData->shadowcoord);

	PuresoftSampler2D::get4(m_diffuseTex, inData->texcoord[0], inData->texcoord[1], &bytesColour);
	outputColour[0] = bytesColour.elems.b;
	outputColour[1] = bytesColour.elems.g;
	outputColour[2] = bytesColour.elems.r;
	outputColour[3] = bytesColour.elems.a;

	mcemaths_quatcpy(ambiemtColour, outputColour);
	mcemaths_mulvec_3_4(ambiemtColour, m_ambient);

	ALIGN16 float L[4];
	mcemaths_sub_3_4(L, m_lightPos, inData->worldPos);
	mcemaths_norm_3_4(L);

	ALIGN16 float E[4];
	mcemaths_sub_3_4(E, m_cameraPos, inData->worldPos);
	mcemaths_norm_3_4(E);

	ALIGN16 float H[4];
	mcemaths_add_3_4(H, E, L);
	mcemaths_norm_3_4(H);

	enum {LAMBERT, SPECULAR};
	ALIGN16 float factors[4];

	factors[LAMBERT] = mcemaths_dot_3_4(L, inData->normal);

	float yawOfLight = acos(mcemaths_dot_3_4(L, m_lightDir));
	factors[LAMBERT] *= yawOfLight < fieldOfLight ? 1.0f : opt_pow(cos(yawOfLight - fieldOfLight), 150);

	factors[SPECULAR] = opt_pow(mcemaths_dot_3_4(H, inData->normal), (unsigned int)*m_specularExponent);

	mcemaths_clamp_3_4(factors, 0, 1.0f);

	mcemaths_mul_3_4(outputColour, (factors[LAMBERT] + factors[SPECULAR]) * shadowFactor);
	mcemaths_add_3_4_ip(outputColour, ambiemtColour);
	mcemaths_clamp_3_4(outputColour, 0, 255.0f);

	bytesColour.elems.r = (unsigned char)outputColour[2];
	bytesColour.elems.g = (unsigned char)outputColour[1];
	bytesColour.elems.b = (unsigned char)outputColour[0];
	bytesColour.elems.a = 0;

	output->write4(0, &bytesColour);
}
Пример #3
0
void FP_Satellite::process(const FragmentProcessorInput* input, FragmentProcessorOutput* output) const
{
	ALIGN16 float outputColour[4];
	ALIGN16 float bumpNormal[4];
	PURESOFTBGRA bytesColour;

	const PROCDATA_PLANET* inData = (const PROCDATA_PLANET*)input->user;

	PuresoftSampler2D::get4(m_diffuseTex, inData->texcoord[0], inData->texcoord[1], &bytesColour);
	outputColour[0] = bytesColour.elems.b;
	outputColour[1] = bytesColour.elems.g;
	outputColour[2] = bytesColour.elems.r;
	outputColour[3] = bytesColour.elems.a;

	PuresoftSampler2D::get4(m_bumpTex, inData->texcoord[0], inData->texcoord[1], &bytesColour);
	bumpNormal[0] = bytesColour.elems.r;
	bumpNormal[1] = bytesColour.elems.g;
	bumpNormal[2] = bytesColour.elems.b;
	bumpNormal[3] = 0;

	float shadowFactor = PuresoftSamplerProjection::get(m_shadowTex, inData->shadowcoord);

	mcemaths_div_3_4(bumpNormal, 255.0f);
	mcemaths_mul_3_4(bumpNormal, 2.0f);
	mcemaths_sub_4by1(bumpNormal, 1.0f);

	ALIGN16 float tbn[16];
	mcemaths_make_tbn(tbn, inData->tangent, inData->binormal, inData->normal);

	mcemaths_transform_m4v4_ip(bumpNormal, tbn);
	mcemaths_norm_3_4(bumpNormal);

	ALIGN16 float L[4];
	mcemaths_sub_3_4(L, m_lightPos, inData->worldPos);
	float distance = mcemaths_len_3_4(L);
	mcemaths_div_3_4(L, distance);

	ALIGN16 float E[4];
	mcemaths_sub_3_4(E, m_cameraPos, inData->worldPos);
	mcemaths_norm_3_4(E);
	ALIGN16 float H[4];
	mcemaths_add_3_4(H, E, L);
	mcemaths_norm_3_4(H);

	float lambert = mcemaths_dot_3_4(L, bumpNormal);

	float specular = mcemaths_dot_3_4(H, bumpNormal);
	specular = specular < 0 ? 0 : specular;
	//specular = pow(specular, 50.0f);
	specular = opt_pow(specular, 50);

	mcemaths_add_1to4(outputColour, 255.0f * specular);

	mcemaths_mul_3_4(outputColour, lambert);

	mcemaths_mul_3_4(outputColour, shadowFactor);
	mcemaths_clamp_3_4(outputColour, 0, 255.0f);

	bytesColour.elems.r = (unsigned char)outputColour[2];
	bytesColour.elems.g = (unsigned char)outputColour[1];
	bytesColour.elems.b = (unsigned char)outputColour[0];
	bytesColour.elems.a = 0;

	output->write4(0, &bytesColour);
}