Jump to content
  • Advertisement
Sign in to follow this  

Blending two textures

This topic is 2054 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a bicycle as shown in the figure, and I have two quads, and one texture, and each quad takes a different UV. One texture is a top view texture for the object, the other one is a side view of the object. I also have a directional light where I can get the angle using the dot product between my object and a ray casted to it.

The problem is: The texture is actually decal mesh that is projected underneath the bike. I would like to blend and morph between the two textures, based on the directional light's, so that when the bike is towards the light, the top projected texture should be blended and shown, when I be far from it, the side texture should be blended and morphed towards the directional light, and the top projected texture is blended out.

 I have maths problem here, but I can't get it correct. In simple words I would like to blend, morph the two textures according light direction.




What I have tried so far:

Quaternion rot = Quaternion.AngleAxis(Source.rotation.eulerAngles.y, normal) * Quaternion.FromToRotation(new Vector3(0, 1, 0), normal);
Vector3 pos = point + new Vector3(0, 0.1f, 0);
Color32 colorSideTexture = mRenderer.sharedMaterial.GetColor("_Color");
colorSideTexture.a = Convert.ToByte(fadingALpha * 255);

Vector3 vxPos1Side = pos + rot * (new Vector3(-1.4f, 0, -0.7f) * scale);
Vector3 vxPos2Side = pos + rot * (new Vector3(-0.7f, 0, -0.7f) * scale);
Vector3 vxPos3Side = pos + rot * (new Vector3(-0.7f, 0, 0.7f) * scale);
Vector3 vxPos4Side = pos + rot * (new Vector3(-1.4f, 0, 0.7f) * scale);

// TOP Projection shadow
Color32 colorTopTexture = mRenderer.sharedMaterial.GetColor("_Color");

Vector3 vxPos1Top = pos + rot * (new Vector3(-0.7f, 0, -0.7f) * scale);
Vector3 vxPos2Top = pos + rot * (new Vector3(0.7f, 0, -0.7f) * scale);
Vector3 vxPos3Top = pos + rot * (new Vector3(0.7f, 0, 0.7f) * scale);
Vector3 vxPos4Top = pos + rot * (new Vector3(-0.7f, 0, 0.7f) * scale);

Global.Log("Rotation Angle" + Source.rotation.eulerAngles.y);

if (Source.rotation.eulerAngles.y > 180)
float angleLerp = Math.Abs(180/Source.rotation.eulerAngles.y);
colorSideTexture.a = Convert.ToByte(Mathf.Lerp(255, 0, angleLerp));

else if ( Source.rotation.eulerAngles.y > 45 && Source.rotation.eulerAngles.y <180)
float angleLerp = Math.Abs(45 / Source.rotation.eulerAngles.y);
colorSideTexture.a = Convert.ToByte(Mathf.Lerp(255, 0, angleLerp));

colorSideTexture.a = 0;

mDecalSide.SetVertex(0, vxPos1Side, colorSideTexture);
mDecalSide.SetVertex(1, vxPos2Side, colorSideTexture);
mDecalSide.SetVertex(2, vxPos3Side, colorSideTexture);
mDecalSide.SetVertex(3, vxPos4Side, colorSideTexture);

mDecalTop.SetVertex(0, vxPos1Top, colorTopTexture);
mDecalTop.SetVertex(1, vxPos2Top, colorTopTexture);
mDecalTop.SetVertex(2, vxPos3Top, colorTopTexture);
mDecalTop.SetVertex(3, vxPos4Top, colorTopTexture);] 
Edited by AhmedCoeia

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!