diff --git a/WickedEngine/decalPS.hlsl b/WickedEngine/decalPS.hlsl index 0996f5f30..bc7e77d82 100644 --- a/WickedEngine/decalPS.hlsl +++ b/WickedEngine/decalPS.hlsl @@ -32,22 +32,15 @@ PixelOutputType main(VertexToPixel PSIn) { PixelOutputType Out = (PixelOutputType)0; - float2 screenPos; - screenPos.x = PSIn.pos2D.x/PSIn.pos2D.w/2.0f + 0.5f; - screenPos.y = -PSIn.pos2D.y/PSIn.pos2D.w/2.0f + 0.5f; + float2 screenPos = PSIn.pos2D.xy / PSIn.pos2D.w * float2(0.5f,-0.5f) + 0.5f; float depth = texture_depth.Load(int3(PSIn.pos.xy,0)).r; float3 pos3D = getPosition(screenPos,depth); - float4 projPos; - projPos = mul(float4(pos3D,1),xDecalVP); - float3 projTex; - float3 clipSpace = projPos.xyz / projPos.w; - projTex.xy = clipSpace.xy*float2(0.5f,-0.5f) + 0.5f; - projTex.z = clipSpace.z; + float3 clipSpace = mul(float4(pos3D, 1), xDecalVP).xyz; + float3 projTex = clipSpace.xyz*float3(0.5f, -0.5f, 0.5f) + 0.5f; + clip( ((saturate(projTex.x) == projTex.x) && (saturate(projTex.y) == projTex.y) && (saturate(projTex.z) == projTex.z))?1:-1 ); - - if (hasTexNor & 0x0000010){ float3 normal = normalize(cross(ddx(pos3D), ddy(pos3D))); //clip( dot(normal,front)>-0.2?-1:1 ); //clip at oblique angle @@ -67,7 +60,6 @@ PixelOutputType main(VertexToPixel PSIn) Out.col=texture_0.Sample(sampler_aniso_clamp,projTex.xy); Out.col.a*=opacity; float3 edgeBlend = clipSpace.xyz; - edgeBlend.z = edgeBlend.z * 2 - 1; edgeBlend = abs(edgeBlend); Out.col.a *= 1 - pow(max(max(edgeBlend.x, edgeBlend.y), edgeBlend.z), 8); //Out.col.a *= pow(saturate(-dot(normal,front)), 4); diff --git a/WickedEngine/wiLoader.cpp b/WickedEngine/wiLoader.cpp index b08ba765e..792103ad0 100644 --- a/WickedEngine/wiLoader.cpp +++ b/WickedEngine/wiLoader.cpp @@ -3804,15 +3804,9 @@ void Decal::UpdateTransform() XMMATRIX rotMat = XMMatrixRotationQuaternion(XMLoadFloat4(&rotation)); XMVECTOR eye = XMLoadFloat3(&translation); - XMVECTOR frontV = XMVector3Transform(XMVectorSet(0, 0, 1, 0), rotMat); - XMStoreFloat3(&front, frontV); - XMVECTOR at = XMVectorAdd(eye, frontV); - XMVECTOR up = XMVector3Transform(XMVectorSet(0, 1, 0, 0), rotMat); - XMStoreFloat4x4(&view, XMMatrixLookAtLH(eye, at, up)); - XMStoreFloat4x4(&projection, XMMatrixOrthographicLH(scale.x, scale.y, -scale.z * 0.5f, scale.z * 0.5f)); XMStoreFloat4x4(&world_rest, XMMatrixScalingFromVector(XMLoadFloat3(&scale))*rotMat*XMMatrixTranslationFromVector(eye)); - bounds.createFromHalfWidth(XMFLOAT3(0, 0, 0), XMFLOAT3(scale.x, scale.y, scale.z)); + bounds.createFromHalfWidth(XMFLOAT3(0, 0, 0), XMFLOAT3(scale.x*0.5f, scale.y*0.5f, scale.z*0.5f)); bounds = bounds.get(XMLoadFloat4x4(&world_rest)); } diff --git a/WickedEngine/wiLoader.h b/WickedEngine/wiLoader.h index ca03983b6..1807c4737 100644 --- a/WickedEngine/wiLoader.h +++ b/WickedEngine/wiLoader.h @@ -800,7 +800,6 @@ struct Decal : public Cullable, public Transform { string texName,norName; wiGraphicsTypes::Texture2D* texture,*normal; - XMFLOAT4X4 view,projection; XMFLOAT3 front; float life,fadeStart; diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 0b2ea91e2..a1a3b08a7 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -3243,15 +3243,14 @@ void wiRenderer::DrawDecals(Camera* camera, GRAPHICSTHREAD threadID) GetDevice()->BindResourcePS(decal->texture, TEXSLOT_ONDEMAND0, threadID); GetDevice()->BindResourcePS(decal->normal, TEXSLOT_ONDEMAND1, threadID); + XMMATRIX decalWorld = XMLoadFloat4x4(&decal->world); + MiscCB dcbvs; - dcbvs.mTransform =XMMatrixTranspose(XMLoadFloat4x4(&decal->world)*camera->GetViewProjection()); + dcbvs.mTransform =XMMatrixTranspose(decalWorld*camera->GetViewProjection()); GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MISC], &dcbvs, threadID); DecalCB dcbps; - dcbps.mDecalVP = - XMMatrixTranspose( - XMLoadFloat4x4(&decal->view)*XMLoadFloat4x4(&decal->projection) - ); + dcbps.mDecalVP = XMMatrixTranspose(XMMatrixInverse(nullptr, decalWorld)); dcbps.hasTexNor = 0; if (decal->texture != nullptr) dcbps.hasTexNor |= 0x0000001; diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index d855b15ab..831ed5dcd 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -7,7 +7,7 @@ namespace wiVersion // minor features, major bug fixes const int minor = 8; // minor bug fixes, alterations, refactors - const int revision = 40; + const int revision = 41; long GetVersion()