decal fixup

This commit is contained in:
turanszkij
2016-08-24 21:51:15 +02:00
parent 090d3d1c8c
commit 8964606bb8
5 changed files with 10 additions and 26 deletions
+4 -12
View File
@@ -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);
+1 -7
View File
@@ -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));
}
-1
View File
@@ -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;
+4 -5
View File
@@ -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;
+1 -1
View File
@@ -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()