Exemplo n.º 1
0
void GLES2Video::SetupMultitextureShader()
{
	if (m_blendTextures[1])
	{
		ShaderPtr pixelShader = m_blendModes[1] == Video::BM_ADD ? m_add1 : m_modulate1;
		pixelShader->SetTexture("t1", m_blendTextures[1]);
		SetPixelShader(pixelShader);
	}
}
Exemplo n.º 2
0
void GLSprite::SetDiffuseTexture(ShaderPtr currentPixelShader)
{
	if (!currentPixelShader)
	{
		m_texture->SetTexture(0);
	}
	else
	{
		currentPixelShader->SetTexture("diffuse", m_texture);
		currentPixelShader->SetShader();
	}
}
Exemplo n.º 3
0
void D3D9Sprite::BeginFastRendering()
{
	Video* video = m_video.lock().get();
	video->SetVertexShader(video->GetFontShader());
	ShaderPtr pCurrentVS = video->GetVertexShader();
	pCurrentVS->SetConstant(L"bitmapSize", GetBitmapSizeF());

	// apply textures according to the rendering mode (pixel shaded or not)
	ShaderPtr pCurrentPS = video->GetPixelShader();
	if (!pCurrentPS)
	{
		m_pDevice->SetTexture(0, m_pTexture);
		//for (unsigned int t=1; t<GS_TEXTURE_CHANNELS; t++)
		//	pDevice->SetTexture(t, NULL);
	}
	else
	{
		pCurrentPS->SetShader();
		pCurrentPS->SetTexture(L"diffuse", GetTexture());
	}
	m_pVideoInfo->BeginFastDraw(m_pDevice, m_rectMode);
}
bool ETHPixelLightDiffuseSpecular::BeginLightPass(ETHSpriteEntity *pRender, Vector3 &v3LightPos, const Vector2 &v2Size,
	const ETHLight* light, const float maxHeight, const float minHeight, const float lightIntensity, const bool drawToTarget)
{
	const Vector2 &v2Origin = pRender->ComputeOrigin(v2Size);
	const Vector3 &v3EntityPos = pRender->GetPosition();

	// set the correct light shader
	ShaderPtr pLightShader;
	const bool hasGloss = pRender->GetGloss();
	if (pRender->GetType() == ETH_VERTICAL)
	{
		if (hasGloss)
		{
			pLightShader = m_vPixelLightSpecularPS;
		}
		else
		{
			pLightShader = m_vPixelLightPS;
		}
	}
	else
	{
		if (hasGloss)
		{
			pLightShader = m_hPixelLightSpecularPS;
		}
		else
		{
			pLightShader = m_hPixelLightPS;
		}
	}

	// if it has a gloss map, send specular data to shader
	if (hasGloss)
	{
		pLightShader->SetConstant(GS_L("specularPower"), pRender->GetSpecularPower());
		pLightShader->SetConstant(GS_L("specularBrightness"), pRender->GetSpecularBrightness());
		pLightShader->SetTexture(GS_L("glossMap"), pRender->GetGloss()->GetTexture());
		pLightShader->SetConstant(GS_L("fakeEyePos"), m_fakeEyeManager->ComputeFakeEyePosition(m_video, pLightShader, drawToTarget, v3LightPos, pRender->GetAngle()));
	}

	// choose which normalmap to use
	m_video->SetPixelShader(pLightShader);
	if (pRender->GetNormal())
	{
		pLightShader->SetTexture(GS_L("normalMap"), pRender->GetNormal()->GetTexture());
	}
	else
	{
		pLightShader->SetTexture(GS_L("normalMap"), GetDefaultNormalMap()->GetTexture());
	}

	// sets spatial information to the shader
	if (pRender->GetType() == ETH_VERTICAL)
	{
		m_vPixelLightVS->SetConstant(GS_L("spaceLength"), (maxHeight-minHeight));
		m_vPixelLightVS->SetConstant(GS_L("topLeft3DPos"), v3EntityPos-(Vector3(v2Origin.x,0,-v2Origin.y)));
		m_video->SetVertexShader(m_vPixelLightVS);
	}
	else
	{
		m_hPixelLightVS->SetConstant(GS_L("topLeft3DPos"), v3EntityPos-Vector3(v2Origin,0));
		m_video->SetVertexShader(m_hPixelLightVS);
	}

	const Vector2 v2ScreenDim = (drawToTarget) ? pRender->GetLightmap()->GetBitmapSizeF() : m_video->GetScreenSizeF();

	if (pRender->GetType() != ETH_VERTICAL)
	{
		if (pRender->GetAngle() != 0.0f)
		{
			Vector3 newPos = v3LightPos-v3EntityPos;
			Matrix4x4 matRot = RotateZ(-DegreeToRadian(pRender->GetAngle()));
			newPos = Multiply(newPos, matRot);
			v3LightPos = newPos + v3EntityPos;
		}
	}

	m_lastAM = m_video->GetAlphaMode();
	m_video->SetAlphaMode(GSAM_ADD);

	// Set a depth value depending on the entity type
	pRender->SetDepth(maxHeight, minHeight);
 
	pLightShader->SetConstant(GS_L("lightPos"), v3LightPos);
	pLightShader->SetConstant(GS_L("squaredRange"), light->range * light->range);
	pLightShader->SetConstant(GS_L("lightColor"), Vector4(light->color, 1.0f) * lightIntensity);

	return true;
}
bool ETHPixelLightDiffuseSpecular::BeginLightPass(ETHSpriteEntity *pRender, Vector3 &v3LightPos, const Vector2 &v2Size,
	const ETHLight* light, const float maxHeight, const float minHeight, const float lightIntensity, const bool drawToTarget)
{
	const Vector2 &v2Origin = pRender->ComputeAbsoluteOrigin(v2Size);
	const Vector3 &v3EntityPos = pRender->GetPosition();

	// set the correct light shader
	ShaderPtr pLightShader;
	const bool hasGloss = pRender->GetGloss();
	if (pRender->GetType() == ETHEntityProperties::ET_VERTICAL)
	{
		if (hasGloss)
		{
			pLightShader = m_vPixelLightSpecularPS;
		}
		else
		{
			pLightShader = m_vPixelLightPS;
		}
	}
	else
	{
		if (hasGloss)
		{
			pLightShader = m_hPixelLightSpecularPS;
		}
		else
		{
			pLightShader = m_hPixelLightPS;
		}
	}

	// if it has a gloss map, send specular data to shader
	if (hasGloss)
	{
		pLightShader->SetConstant(GS_L("specularPower"), pRender->GetSpecularPower());
		pLightShader->SetConstant(GS_L("specularBrightness"), pRender->GetSpecularBrightness());
		pLightShader->SetTexture(GS_L("glossMap"), pRender->GetGloss()->GetTexture());
		pLightShader->SetConstant(GS_L("fakeEyePos"), m_fakeEyeManager->ComputeFakeEyePosition(m_video, pLightShader, drawToTarget, v3LightPos, pRender->GetAngle()));
	}

	// choose which normalmap to use
	m_video->SetPixelShader(pLightShader);
	if (pRender->GetNormal())
	{
		pLightShader->SetTexture(GS_L("normalMap"), pRender->GetNormal()->GetTexture());
	}
	else
	{
		pLightShader->SetTexture(GS_L("normalMap"), GetDefaultNormalMap()->GetTexture());
	}

	// sets spatial information to the shader
	if (pRender->GetType() == ETHEntityProperties::ET_VERTICAL)
	{
		m_vPixelLightVS->SetConstant(GS_L("spaceLength"), (maxHeight-minHeight));
		m_vPixelLightVS->SetConstant(GS_L("topLeft3DPos"), v3EntityPos-(Vector3(v2Origin.x,0,-v2Origin.y)));
		m_video->SetVertexShader(m_vPixelLightVS);
	}
	else
	{
		m_hPixelLightVS->SetConstant(GS_L("topLeft3DPos"), v3EntityPos-Vector3(v2Origin,0));
		m_video->SetVertexShader(m_hPixelLightVS);
	}

	// TO-DO it looks like a mess around here...
	if (pRender->GetType() != ETHEntityProperties::ET_VERTICAL)
	{
		if (pRender->GetAngle() != 0.0f)
		{
			Vector3 newPos = v3LightPos-v3EntityPos;
			Matrix4x4 matRot = RotateZ(-DegreeToRadian(pRender->GetAngle()));
			newPos = Multiply(newPos, matRot);
			v3LightPos = newPos + v3EntityPos;
		}
	}

	m_lastAM = m_video->GetAlphaMode();
	m_video->SetAlphaMode(Video::AM_ADD);

	// Set a depth value depending on the entity type
	pRender->SetDepth(maxHeight, minHeight);
 
 	// downscales pixel shader ranges on android to prevent from lower precision glitches
 	float lightPrecisionDownScale = 1.0f;
 	#ifdef GLES2
	 	lightPrecisionDownScale = LIGHT_PRECISION_DOWNSCALE;
 	#endif

	pLightShader->SetConstant(GS_L("lightPos"), v3LightPos * lightPrecisionDownScale);

	const float scaledRange = (light->range * lightPrecisionDownScale);
	pLightShader->SetConstant(GS_L("squaredRange"), scaledRange * scaledRange);
	pLightShader->SetConstant(GS_L("lightColor"), Vector4(light->color, 1.0f) * lightIntensity);

	return true;
}
Exemplo n.º 6
0
bool D3D9Sprite::DrawShaped(
	const Vector2& v2Pos,
	const Vector2& v2Size,
	const Color& color0,
	const Color& color1,
	const Color& color2,
	const Color& color3,
	const float angle)
{
	if (v2Size == Vector2(0,0))
	{
		return true;
	}

	// do the flip (parameters that will be send to the VS)
	Vector2 flipMul(1,1), flipAdd(0,0);
	if (m_flipX)
	{
		flipMul.x =-1;
		flipAdd.x = 1;
	}
	if (m_flipY)
	{
		flipMul.y =-1;
		flipAdd.y = 1;
	}

	// centralizes the sprite according to the origin
	Vector2 v2Center = m_normalizedOrigin*v2Size;

	Video* video = m_video.lock().get();
	ShaderPtr pCurrentVS = video->GetVertexShader();

	Matrix4x4 mRot;
	if (angle != 0.0f)
		mRot = RotateZ(DegreeToRadian(angle));
	pCurrentVS->SetMatrixConstant(L"rotationMatrix", mRot);

	// rounds up the final position to avoid alpha distortion
	Vector2 v2FinalPos;
	if (video->IsRoundingUpPosition())
	{
		v2FinalPos.x = floor(v2Pos.x);
		v2FinalPos.y = floor(v2Pos.y);
	}
	else
	{
		v2FinalPos = v2Pos;
	}

	// subtract 0.5 to align pixel-texel
	v2FinalPos -= math::constant::HALF_VECTOR2;

	pCurrentVS->SetConstant(L"size", v2Size);
	pCurrentVS->SetConstant(L"entityPos", v2FinalPos);
	pCurrentVS->SetConstant(L"center", v2Center);
	pCurrentVS->SetConstant(L"flipMul", flipMul);
	pCurrentVS->SetConstant(L"flipAdd", flipAdd);
	pCurrentVS->SetConstant(L"bitmapSize", GetBitmapSizeF());
	pCurrentVS->SetConstant(L"scroll", GetScroll());
	pCurrentVS->SetConstant(L"multiply", GetMultiply());

	const bool setCameraPos = pCurrentVS->ConstantExist(L"cameraPos");
	if (setCameraPos)
		pCurrentVS->SetConstant(L"cameraPos", video->GetCameraPos());

	if (m_rect.size.x == 0 || m_rect.size.y == 0)
	{
		pCurrentVS->SetConstant(L"rectSize", GetBitmapSizeF());
		pCurrentVS->SetConstant(L"rectPos", 0, 0);
	}
	else
	{
		pCurrentVS->SetConstant(L"rectSize", m_rect.size);
		pCurrentVS->SetConstant(L"rectPos", m_rect.pos);
	}

	pCurrentVS->SetConstant(L"color0", color0);
	pCurrentVS->SetConstant(L"color1", color1);
	pCurrentVS->SetConstant(L"color2", color2);
	pCurrentVS->SetConstant(L"color3", color3);

	if (pCurrentVS->ConstantExist(L"depth"))
		pCurrentVS->SetConstant(L"depth", video->GetSpriteDepth());

	pCurrentVS->SetShader();

	// apply textures according to the rendering mode (pixel shaded or not)
	ShaderPtr pCurrentPS = video->GetPixelShader();
	if (!pCurrentPS)
	{
		m_pDevice->SetTexture(0, m_pTexture);
		//for (unsigned int t=1; t<GS_TEXTURE_CHANNELS; t++)
		//	pDevice->SetTexture(t, NULL);
	}
	else
	{
		pCurrentPS->SetShader();
		pCurrentPS->SetTexture(L"diffuse", GetTexture());
	}

	// draw the one-pixel-quad applying the vertex shader
	m_pVideoInfo->DrawSprite(m_pDevice, m_rectMode);

	m_pDevice->SetVertexShader(NULL);

	return true;
}