|
|
|
@ -20,30 +20,35 @@ namespace ConformalDecals {
|
|
|
|
|
_decalMPB = new MaterialPropertyBlock();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Project(Matrix4x4 orthoMatrix, Transform projector, bool useBaseNormal) {
|
|
|
|
|
_projectionEnabled = true;
|
|
|
|
|
public void Project(Matrix4x4 orthoMatrix, Transform projector, Bounds projectorBounds, bool useBaseNormal) {
|
|
|
|
|
|
|
|
|
|
var targetMaterial = _targetRenderer.sharedMaterial;
|
|
|
|
|
var projectorToTargetMatrix = target.worldToLocalMatrix * projector.localToWorldMatrix;
|
|
|
|
|
if (projectorBounds.Intersects(_targetRenderer.bounds)) {
|
|
|
|
|
_projectionEnabled = true;
|
|
|
|
|
var targetMaterial = _targetRenderer.sharedMaterial;
|
|
|
|
|
var projectorToTargetMatrix = target.worldToLocalMatrix * projector.localToWorldMatrix;
|
|
|
|
|
|
|
|
|
|
var projectionMatrix = orthoMatrix * projectorToTargetMatrix.inverse;
|
|
|
|
|
var decalNormal = projectorToTargetMatrix.MultiplyVector(Vector3.back).normalized;
|
|
|
|
|
var decalTangent = projectorToTargetMatrix.MultiplyVector(Vector3.right).normalized;
|
|
|
|
|
var projectionMatrix = orthoMatrix * projectorToTargetMatrix.inverse;
|
|
|
|
|
var decalNormal = projectorToTargetMatrix.MultiplyVector(Vector3.back).normalized;
|
|
|
|
|
var decalTangent = projectorToTargetMatrix.MultiplyVector(Vector3.right).normalized;
|
|
|
|
|
|
|
|
|
|
_decalMPB.SetMatrix(DecalPropertyIDs._ProjectionMatrix, projectionMatrix);
|
|
|
|
|
_decalMPB.SetVector(DecalPropertyIDs._DecalNormal, decalNormal);
|
|
|
|
|
_decalMPB.SetVector(DecalPropertyIDs._DecalTangent, decalTangent);
|
|
|
|
|
_decalMPB.SetMatrix(DecalPropertyIDs._ProjectionMatrix, projectionMatrix);
|
|
|
|
|
_decalMPB.SetVector(DecalPropertyIDs._DecalNormal, decalNormal);
|
|
|
|
|
_decalMPB.SetVector(DecalPropertyIDs._DecalTangent, decalTangent);
|
|
|
|
|
|
|
|
|
|
if (useBaseNormal && targetMaterial.HasProperty(DecalPropertyIDs._BumpMap)) {
|
|
|
|
|
_decalMPB.SetTexture(DecalPropertyIDs._BumpMap, targetMaterial.GetTexture(DecalPropertyIDs._BumpMap));
|
|
|
|
|
if (useBaseNormal && targetMaterial.HasProperty(DecalPropertyIDs._BumpMap)) {
|
|
|
|
|
_decalMPB.SetTexture(DecalPropertyIDs._BumpMap, targetMaterial.GetTexture(DecalPropertyIDs._BumpMap));
|
|
|
|
|
|
|
|
|
|
var normalScale = targetMaterial.GetTextureScale(DecalPropertyIDs._BumpMap);
|
|
|
|
|
var normalOffset = targetMaterial.GetTextureOffset(DecalPropertyIDs._BumpMap);
|
|
|
|
|
var normalScale = targetMaterial.GetTextureScale(DecalPropertyIDs._BumpMap);
|
|
|
|
|
var normalOffset = targetMaterial.GetTextureOffset(DecalPropertyIDs._BumpMap);
|
|
|
|
|
|
|
|
|
|
_decalMPB.SetVector(DecalPropertyIDs._BumpMap_ST, new Vector4(normalScale.x, normalScale.y, normalOffset.x, normalOffset.y));
|
|
|
|
|
_decalMPB.SetVector(DecalPropertyIDs._BumpMap_ST, new Vector4(normalScale.x, normalScale.y, normalOffset.x, normalOffset.y));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
_decalMPB.SetTexture(DecalPropertyIDs._BumpMap, DecalConfig.BlankNormal);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
_decalMPB.SetTexture(DecalPropertyIDs._BumpMap, DecalConfig.BlankNormal);
|
|
|
|
|
_projectionEnabled = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|