Пример #1
0
void VP_Cloud::process(const VertexProcessorInput* input, VertexProcessorOutput* output) const
{
	PROCDATA_CLOUD* userOutput = (PROCDATA_CLOUD*)output->user;

	const float* position = (const float*)input->data[0];
	const float* normal = (const float*)input->data[3];
	const float* texcoord = (const float*)input->data[4];

	// get vertex position in world space
	mcemaths_transform_m4v4(userOutput->worldPos, m_M, position);

	// project world-position into shadow map's UV space, inp:userOutput->worldPos, outp:userOutput->shadowcoord
	mcemaths_quatcpy(userOutput->shadowcoord, userOutput->worldPos);
	//	ALIGN16 float enlarge[4];
	//	mcemaths_quatcpy(enlarge, normal);
	//	mcemaths_mul_3_4(enlarge, 1.5f);
	//	mcemaths_add_3_4_ip(userOutput->shadowcoord, enlarge); // slightly enlarge the model for anti-acne
	mcemaths_transform_m4v4_ip(userOutput->shadowcoord, m_shadowPV);

	// project world-position into view space
	mcemaths_quatcpy(output->position, userOutput->worldPos);
	mcemaths_transform_m4v4_ip(output->position, m_PV);

	// remove world-position's w (later we'll use it as an xyz coordinate)
	userOutput->worldPos[3] = 0;

	// transform normal
	mcemaths_transform_m4v4(userOutput->normal, m_Mrot, normal);

	// pass on texture coord
	userOutput->texcoord[0] = texcoord[0];
	userOutput->texcoord[1] = texcoord[1];
}
Пример #2
0
void IP_SingleColour::interpolateByContributes(void* interpolatedUserData, const void** vertexUserData, const float* correctedContributes) const
{
	__declspec(align(16)) PROCDATA_SINGLECOLOUR temp[3];
	copyUserDataSingleColour(temp,     (PROCDATA_SINGLECOLOUR*)vertexUserData[0]);
	copyUserDataSingleColour(temp + 1, (PROCDATA_SINGLECOLOUR*)vertexUserData[1]);
	copyUserDataSingleColour(temp + 2, (PROCDATA_SINGLECOLOUR*)vertexUserData[2]);

	mcemaths_mul_3_4(temp[0].normal, correctedContributes[0]);
	mcemaths_mul_3_4(temp[0].worldPos, correctedContributes[0]);
	mcemaths_mul_3_4(temp[0].shadowcoord, correctedContributes[0]);

	mcemaths_mul_3_4(temp[1].normal, correctedContributes[1]);
	mcemaths_mul_3_4(temp[1].worldPos, correctedContributes[1]);
	mcemaths_mul_3_4(temp[1].shadowcoord, correctedContributes[1]);

	mcemaths_mul_3_4(temp[2].normal, correctedContributes[2]);
	mcemaths_mul_3_4(temp[2].worldPos, correctedContributes[2]);
	mcemaths_mul_3_4(temp[2].shadowcoord, correctedContributes[2]);

	PROCDATA_SINGLECOLOUR* output = (PROCDATA_SINGLECOLOUR*)interpolatedUserData;

	mcemaths_quatcpy(output->normal, temp[0].normal);
	mcemaths_quatcpy(output->worldPos, temp[0].worldPos);
	mcemaths_quatcpy(output->shadowcoord, temp[0].shadowcoord);

	mcemaths_add_3_4_ip(output->normal, temp[1].normal);
	mcemaths_add_3_4_ip(output->worldPos, temp[1].worldPos);
	mcemaths_add_3_4_ip(output->shadowcoord, temp[1].shadowcoord);

	mcemaths_add_3_4_ip(output->normal, temp[2].normal);
	mcemaths_add_3_4_ip(output->worldPos, temp[2].worldPos);
	mcemaths_add_3_4_ip(output->shadowcoord, temp[2].shadowcoord);
}
Пример #3
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);
}
Пример #4
0
void VP_Shadow::process(const VertexProcessorInput* input, VertexProcessorOutput* output) const
{
	ALIGN16 float shrink[4];
	mcemaths_quatcpy(shrink, (const float*)input->data[0]);
	mcemaths_mul_3(shrink, 0.9f);
	mcemaths_transform_m4v4(output->position, m_PVM, shrink);
}
Пример #5
0
void VP_DiffuseOnly::process(const VertexProcessorInput* input, VertexProcessorOutput* output) const
{
	PROCDATA_DIFFUSEONLY* userOutput = (PROCDATA_DIFFUSEONLY*)output->user;

	const float* position = (const float*)input->data[0];
	const float* normal = (const float*)input->data[3];
	const float* texcoord = (const float*)input->data[4];

	// get vertex position in world space
	mcemaths_transform_m4v4(userOutput->worldPos, m_M, position);

	// project world-position into shadow map's UV space, inp:userOutput->worldPos, outp:userOutput->shadowcoord
	mcemaths_quatcpy(userOutput->shadowcoord, userOutput->worldPos);
	mcemaths_transform_m4v4_ip(userOutput->shadowcoord, m_shadowPV);

	// project world-position into view space
	mcemaths_transform_m4v4(output->position, m_PVM, position);

	// remove world-position's w (later we'll use it as an xyz coordinate)
	userOutput->worldPos[3] = 0;

	// transform normals
	mcemaths_transform_m4v4(userOutput->normal, m_MR, normal);

	// pass on texture coord
	userOutput->texcoord[0] = texcoord[0];
	userOutput->texcoord[1] = texcoord[1];
}
Пример #6
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);
}
Пример #7
0
void IP_DiffuseOnly::interpolateByContributes(void* interpolatedUserData, const void** vertexUserData, const float* correctedContributes) const
{
	__declspec(align(16)) PROCDATA_DIFFUSEONLY temp[3];
	copyUserDataDiffuseOnly(temp,     (PROCDATA_DIFFUSEONLY*)vertexUserData[0]);
	copyUserDataDiffuseOnly(temp + 1, (PROCDATA_DIFFUSEONLY*)vertexUserData[1]);
	copyUserDataDiffuseOnly(temp + 2, (PROCDATA_DIFFUSEONLY*)vertexUserData[2]);

	mcemaths_mul_3_4(temp[0].normal, correctedContributes[0]);
	mcemaths_mul_3_4(temp[0].worldPos, correctedContributes[0]);
	mcemaths_mul_3_4(temp[0].texcoord, correctedContributes[0]);
	mcemaths_mul_3_4(temp[0].shadowcoord, correctedContributes[0]);

	mcemaths_mul_3_4(temp[1].normal, correctedContributes[1]);
	mcemaths_mul_3_4(temp[1].worldPos, correctedContributes[1]);
	mcemaths_mul_3_4(temp[1].texcoord, correctedContributes[1]);
	mcemaths_mul_3_4(temp[1].shadowcoord, correctedContributes[1]);

	mcemaths_mul_3_4(temp[2].normal, correctedContributes[2]);
	mcemaths_mul_3_4(temp[2].worldPos, correctedContributes[2]);
	mcemaths_mul_3_4(temp[2].texcoord, correctedContributes[2]);
	mcemaths_mul_3_4(temp[2].shadowcoord, correctedContributes[2]);

	PROCDATA_DIFFUSEONLY* output = (PROCDATA_DIFFUSEONLY*)interpolatedUserData;

	mcemaths_quatcpy(output->normal, temp[0].normal);
	mcemaths_quatcpy(output->worldPos, temp[0].worldPos);
	mcemaths_quatcpy(output->texcoord, temp[0].texcoord);
	mcemaths_quatcpy(output->shadowcoord, temp[0].shadowcoord);

	mcemaths_add_3_4_ip(output->normal, temp[1].normal);
	mcemaths_add_3_4_ip(output->worldPos, temp[1].worldPos);
	mcemaths_add_3_4_ip(output->texcoord, temp[1].texcoord);
	mcemaths_add_3_4_ip(output->shadowcoord, temp[1].shadowcoord);

	mcemaths_add_3_4_ip(output->normal, temp[2].normal);
	mcemaths_add_3_4_ip(output->worldPos, temp[2].worldPos);
	mcemaths_add_3_4_ip(output->texcoord, temp[2].texcoord);
	mcemaths_add_3_4_ip(output->shadowcoord, temp[2].shadowcoord);
}
Пример #8
0
void VP_CloudShadow::process(const VertexProcessorInput* input, VertexProcessorOutput* output) const
{
	PROCDATA_CLOUDSHADOW* userOutput = (PROCDATA_CLOUDSHADOW*)output->user;
	const float* position = (const float*)input->data[0];
	const float* texcoord = (const float*)input->data[4];

	ALIGN16 float position_adjusted[4], pvm[16];
	mcemaths_quatcpy(position_adjusted, position);
	mcemaths_mul_3(position_adjusted, 0.95f);
	mcemaths_transform_m4m4(pvm, m_PV, m_M);
	mcemaths_transform_m4v4(output->position, pvm, position_adjusted);

	userOutput->texcoord[0] = texcoord[0];
	userOutput->texcoord[1] = texcoord[1];
}
Пример #9
0
void FP_SingleColourNoLighting::process(const FragmentProcessorInput* input, FragmentProcessorOutput* output) const
{
	const PROCDATA_SINGLECOLOUR* inData = (const PROCDATA_SINGLECOLOUR*)input->user;

	ALIGN16 float outputColour[4];
	mcemaths_quatcpy(outputColour, m_diffuse);
	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);
}
Пример #10
0
void IP_CloudShadow::interpolateByContributes(void* interpolatedUserData, const void** vertexUserData, const float* correctedContributes) const
{
	__declspec(align(16)) PROCDATA_CLOUDSHADOW temp[3];
	copyUserData(temp,     (PROCDATA_CLOUDSHADOW*)vertexUserData[0]);
	copyUserData(temp + 1, (PROCDATA_CLOUDSHADOW*)vertexUserData[1]);
	copyUserData(temp + 2, (PROCDATA_CLOUDSHADOW*)vertexUserData[2]);

	mcemaths_mul_3_4(temp[0].texcoord, correctedContributes[0]);
	mcemaths_mul_3_4(temp[1].texcoord, correctedContributes[1]);
	mcemaths_mul_3_4(temp[2].texcoord, correctedContributes[2]);

	PROCDATA_CLOUDSHADOW* output = (PROCDATA_CLOUDSHADOW*)interpolatedUserData;

	mcemaths_quatcpy(output->texcoord, temp[0].texcoord);
	mcemaths_add_3_4_ip(output->texcoord, temp[1].texcoord);
	mcemaths_add_3_4_ip(output->texcoord, temp[2].texcoord);
}
Пример #11
0
void IP_Planet::interpolateByContributes(void* interpolatedUserData, const void** vertexUserData, const float* correctedContributes) const
{
	__declspec(align(16)) PROCDATA_PLANET temp[3];
	copyUserData(temp,     (PROCDATA_PLANET*)vertexUserData[0]);
	copyUserData(temp + 1, (PROCDATA_PLANET*)vertexUserData[1]);
	copyUserData(temp + 2, (PROCDATA_PLANET*)vertexUserData[2]);

	mcemaths_mul_3_4(temp[0].tangent, correctedContributes[0]);
	mcemaths_mul_3_4(temp[0].binormal, correctedContributes[0]);
	mcemaths_mul_3_4(temp[0].normal, correctedContributes[0]);
	mcemaths_mul_3_4(temp[0].worldPos, correctedContributes[0]);
	mcemaths_mul_3_4(temp[0].texcoord, correctedContributes[0]);
	mcemaths_mul_3_4(temp[0].shadowcoord, correctedContributes[0]);

	mcemaths_mul_3_4(temp[1].tangent, correctedContributes[1]);
	mcemaths_mul_3_4(temp[1].binormal, correctedContributes[1]);
	mcemaths_mul_3_4(temp[1].normal, correctedContributes[1]);
	mcemaths_mul_3_4(temp[1].worldPos, correctedContributes[1]);
	mcemaths_mul_3_4(temp[1].texcoord, correctedContributes[1]);
	mcemaths_mul_3_4(temp[1].shadowcoord, correctedContributes[1]);

	mcemaths_mul_3_4(temp[2].tangent, correctedContributes[2]);
	mcemaths_mul_3_4(temp[2].binormal, correctedContributes[2]);
	mcemaths_mul_3_4(temp[2].normal, correctedContributes[2]);
	mcemaths_mul_3_4(temp[2].worldPos, correctedContributes[2]);
	mcemaths_mul_3_4(temp[2].texcoord, correctedContributes[2]);
	mcemaths_mul_3_4(temp[2].shadowcoord, correctedContributes[2]);

	PROCDATA_PLANET* output = (PROCDATA_PLANET*)interpolatedUserData;

	mcemaths_quatcpy(output->tangent, temp[0].tangent);
	mcemaths_quatcpy(output->binormal, temp[0].binormal);
	mcemaths_quatcpy(output->normal, temp[0].normal);
	mcemaths_quatcpy(output->worldPos, temp[0].worldPos);
	mcemaths_quatcpy(output->texcoord, temp[0].texcoord);
	mcemaths_quatcpy(output->shadowcoord, temp[0].shadowcoord);

	mcemaths_add_3_4_ip(output->tangent, temp[1].tangent);
	mcemaths_add_3_4_ip(output->binormal, temp[1].binormal);
	mcemaths_add_3_4_ip(output->normal, temp[1].normal);
	mcemaths_add_3_4_ip(output->worldPos, temp[1].worldPos);
	mcemaths_add_3_4_ip(output->texcoord, temp[1].texcoord);
	mcemaths_add_3_4_ip(output->shadowcoord, temp[1].shadowcoord);

	mcemaths_add_3_4_ip(output->tangent, temp[2].tangent);
	mcemaths_add_3_4_ip(output->binormal, temp[2].binormal);
	mcemaths_add_3_4_ip(output->normal, temp[2].normal);
	mcemaths_add_3_4_ip(output->worldPos, temp[2].worldPos);
	mcemaths_add_3_4_ip(output->texcoord, temp[2].texcoord);
	mcemaths_add_3_4_ip(output->shadowcoord, temp[2].shadowcoord);
}
Пример #12
0
void VP_SingleColour::process(const VertexProcessorInput* input, VertexProcessorOutput* output) const
{
	PROCDATA_SINGLECOLOUR* userOutput = (PROCDATA_SINGLECOLOUR*)output->user;

	const float* position = (const float*)input->data[0];
	const float* normal = (const float*)input->data[3];
	const float* texcoord = (const float*)input->data[4];

	// get vertex position in world space
	mcemaths_transform_m4v4(userOutput->worldPos, m_M, position);

	// project world-position into shadow map's UV space, inp:userOutput->worldPos, outp:userOutput->shadowcoord
	mcemaths_quatcpy(userOutput->shadowcoord, userOutput->worldPos);
	mcemaths_transform_m4v4_ip(userOutput->shadowcoord, m_shadowPV);

	// remove world-position's w (later we'll use it as an xyz coordinate)
	userOutput->worldPos[3] = 0;

	// project model-position into view space
	mcemaths_transform_m4v4(output->position, m_PVM, position);

	// transform normal
	mcemaths_transform_m4v4(userOutput->normal, m_MR, normal);
}
Пример #13
0
const vec4& vec4::operator=  (const vec4& src)
{
	mcemaths_quatcpy(&x, src);
	return *this;
}