public static void GetFrustumPlanes(ref OrthoCam ortho, float4 *planes) { planes[0] = VectorUtility.GetPlane(ortho.up, ortho.position + ortho.up * ortho.size); planes[1] = VectorUtility.GetPlane(-ortho.up, ortho.position - ortho.up * ortho.size); planes[2] = VectorUtility.GetPlane(ortho.right, ortho.position + ortho.right * ortho.size); planes[3] = VectorUtility.GetPlane(-ortho.right, ortho.position - ortho.right * ortho.size); planes[4] = VectorUtility.GetPlane(ortho.forward, ortho.position + ortho.forward * ortho.farClipPlane); planes[5] = VectorUtility.GetPlane(-ortho.forward, ortho.position + ortho.forward * ortho.nearClipPlane); }
public static void GetOrthoCullingPlanes(ref OrthoCam orthoCam, float4 *planes) { planes[0] = MathLib.GetPlane(orthoCam.forward, orthoCam.position + orthoCam.forward * orthoCam.farClipPlane); planes[1] = MathLib.GetPlane(-orthoCam.forward, orthoCam.position + orthoCam.forward * orthoCam.nearClipPlane); planes[2] = MathLib.GetPlane(-orthoCam.up, orthoCam.position - orthoCam.up * orthoCam.size); planes[3] = MathLib.GetPlane(orthoCam.up, orthoCam.position + orthoCam.up * orthoCam.size); planes[4] = MathLib.GetPlane(orthoCam.right, orthoCam.position + orthoCam.right * orthoCam.size); planes[5] = MathLib.GetPlane(-orthoCam.right, orthoCam.position - orthoCam.right * orthoCam.size); }
public static void GetFrustumCorner(ref OrthoCam orthoCam, float distance, float3 *corners) { float3 farPoint = orthoCam.position + distance * orthoCam.forward; float3 upVec = orthoCam.size * orthoCam.up; float3 rightVec = orthoCam.size * orthoCam.right; corners[0] = farPoint - upVec - rightVec; corners[1] = farPoint - upVec + rightVec; corners[2] = farPoint + upVec - rightVec; corners[3] = farPoint + upVec + rightVec; }
public void UpdateRender(CommandBuffer buffer) { buffer.SetRenderTarget(colorBuffers, albedoRT.depthBuffer); buffer.ClearRenderTarget(true, true, new Color(0, 0, 0, 0)); foreach (var i in data.allSettings) { buffer.SetGlobalTexture("_BlendAlbedo", i.startAlbedo ? i.startAlbedo : whiteTex); buffer.SetGlobalTexture("_BlendNormal", i.startNormal ? i.startNormal : normalTex); buffer.SetGlobalTexture("_BlendSMO", i.startSMO ? i.startNormal : normalTex); buffer.SetGlobalTexture("_BlendMask", i.maskTex ? i.maskTex : whiteTex); buffer.SetGlobalVector("_BlendScaleOffset", i.scaleOffset); buffer.SetGlobalVector("_MaskScaleOffset", new Vector4(i.maskScale, i.maskOffset)); buffer.DrawMesh(GraphicsUtility.mesh, Matrix4x4.identity, blendTexMat, 0, 0); } OrthoCam orthoCam = new OrthoCam { up = Vector3.forward, right = Vector3.right, forward = Vector3.down, position = transform.position, farClipPlane = 50, nearClipPlane = -50, size = transform.localScale.x * 0.5f }; orthoCam.UpdateProjectionMatrix(); orthoCam.UpdateTRSMatrix(); float4x4 vp = mul(GraphicsUtility.GetGPUProjectionMatrix(orthoCam.projectionMatrix, true), orthoCam.worldToCameraMatrix); buffer.SetGlobalMatrix(ShaderIDs._VP, vp); for (int i = 0; i < transform.childCount; ++i) { VTDecal vtDecal = transform.GetChild(i).GetComponent <VTDecal>(); if (!vtDecal) { continue; } buffer.SetGlobalVector("_DecalScaleOffset", vtDecal.scaleOffset); buffer.SetGlobalTexture("_DecalAlbedo", vtDecal.albedoTex ? vtDecal.albedoTex : whiteTex); buffer.SetGlobalTexture("_DecalNormal", vtDecal.normalTex ? vtDecal.normalTex : normalTex); buffer.SetGlobalTexture("_DecalSMO", vtDecal.smoTex ? vtDecal.smoTex : whiteTex); buffer.SetGlobalTexture("_DecalMask", vtDecal.opaqueMask ? vtDecal.opaqueMask : whiteTex); buffer.SetGlobalVector("_DecalSMOWeight", new Vector4(vtDecal.smoothness, vtDecal.metallic, vtDecal.occlusion, vtDecal.opaque)); buffer.DrawMesh(vtDecal.sharedMesh, vtDecal.transform.localToWorldMatrix, blendTexMat, 0, 1); } testMat.SetTexture("_MainTex", albedoRT); testMat.SetTexture("_BumpMap", normalRT); testMat.SetTexture("_SpecularMap", smoRT); }
public static void GetFrustumCorner(ref OrthoCam orthoCam, float3 *corners) { float3 upVec = orthoCam.size * orthoCam.up; float3 rightVec = orthoCam.size * orthoCam.right; void GetCorner(ref OrthoCam ortho, float dist) { float3 farPoint = ortho.position + dist * ortho.forward; corners[0] = farPoint - upVec - rightVec; corners[1] = farPoint - upVec + rightVec; corners[2] = farPoint + upVec - rightVec; corners[3] = farPoint + upVec + rightVec; corners += 4; } GetCorner(ref orthoCam, orthoCam.nearClipPlane); GetCorner(ref orthoCam, orthoCam.farClipPlane); }