public void TransformMesh(XMMatrix world, double time) { if (this.AnimationKeysCount == 0) { return; } if (this.AnimationFrameTransformType == SdkMeshFrameTransformType.Relative) { if (this.Frames.Count >= 1) { this.Frames[0].TransformFrame(this, world, time); } // For each frame, move the transform to the bind pose, then // move it to the final position foreach (SdkMeshFrame frame in this.Frames) { XMMatrix m; m = frame.BindPoseFrameMatrix; XMMatrix mInvBindPose = m.Inverse(); m = frame.TransformedFrameMatrix; XMMatrix mFinal = mInvBindPose * m; frame.TransformedFrameMatrix = mFinal; } } else if (this.AnimationFrameTransformType == SdkMeshFrameTransformType.Absolute) { foreach (SdkMeshFrame frame in this.Frames) { frame.TransformFrameAbsolute(this, time); } } }
public void CreateWindowSizeDependentResources() { float fAspectRatio = (float)this.deviceResources.BackBufferWidth / (float)this.deviceResources.BackBufferHeight; this.ProjectionMatrix = XMMatrix.PerspectiveFovLH(XMMath.PIDivFour, fAspectRatio, 0.5f, 100.0f); this.LightProjectionMatrix = XMMatrix.PerspectiveFovLH(XMMath.PIDivFour, fAspectRatio, 10.0f, 100.0f); }
public void TransformBindPose(XMMatrix world) { if (this.Frames.Count >= 1) { this.Frames[0].TransformBindPoseFrame(this, world); } }
public virtual void SetViewParams(XMVector vEyePt, XMVector vLookatPt) { m_vEye = vEyePt; m_vDefaultEye = vEyePt; m_vLookAt = vLookatPt; m_vDefaultLookAt = vLookatPt; // Calc the view matrix XMMatrix mView = XMMatrix.LookAtLH(vEyePt, vLookatPt, XMVector.FromFloat(0.0f, 1.0f, 0.0f, 0.0f)); m_mView = mView; XMMatrix mInvView = mView.Inverse(); // The axis basis vectors and camera position are stored inside the // position matrix in the 4 rows of the camera's world matrix. // To figure out the yaw/pitch of the camera, we just need the Z basis vector XMFloat3 zBasis = new XMFloat3(mInvView.M31, mInvView.M32, mInvView.M33); m_fCameraYawAngle = (float)Math.Atan2(zBasis.X, zBasis.Z); float fLen = (float)Math.Sqrt(zBasis.Z * zBasis.Z + zBasis.X * zBasis.X); m_fCameraPitchAngle = -(float)Math.Atan2(zBasis.Y, fLen); }
public void CreateWindowSizeDependentResources() { // Setup the camera's projection parameters float fAspectRatio = (float)this.deviceResources.BackBufferWidth / (float)this.deviceResources.BackBufferHeight; this.projectionMatrix = XMMatrix.PerspectiveFovLH(XMMath.PIDivFour, fAspectRatio, 0.1f, 1000.0f); }
public BoundingBox Transform(XMMatrix m) { // Load center and extents. XMVector boxCenter = this.center; XMVector boxExtents = this.extents; // Compute and transform the corners and find new min/max bounds. XMVector corner = XMVector.MultiplyAdd(boxExtents, CollisionGlobalConstants.BoxOffsets[0], boxCenter); corner = XMVector3.Transform(corner, m); XMVector min, max; min = max = corner; for (int i = 1; i < BoundingBox.CornerCount; i++) { corner = XMVector.MultiplyAdd(boxExtents, CollisionGlobalConstants.BoxOffsets[i], boxCenter); corner = XMVector3.Transform(corner, m); min = XMVector.Min(min, corner); max = XMVector.Max(max, corner); } // Store center and extents. return(new BoundingBox((min + max) * 0.5f, (max - min) * 0.5f)); }
public static XMVector Project( XMVector v, float viewportX, float viewportY, float viewportWidth, float viewportHeight, float viewportMinZ, float viewportMaxZ, XMMatrix projection, XMMatrix view, XMMatrix world) { float halfViewportWidth = viewportWidth * 0.5f; float halfViewportHeight = viewportHeight * 0.5f; XMVector scale = new XMVector(halfViewportWidth, -halfViewportHeight, viewportMaxZ - viewportMinZ, 0.0f); XMVector offset = new XMVector(viewportX + halfViewportWidth, viewportY + halfViewportHeight, viewportMinZ, 0.0f); XMMatrix transform = XMMatrix.Multiply(world, view); transform = XMMatrix.Multiply(transform, projection); XMVector result = XMVector3.TransformCoord(v, transform); result = XMVector.MultiplyAdd(result, scale, offset); return(result); }
public BoundingSphere Transform(XMMatrix m) { // Load the center of the sphere. XMVector v_center = this.center; // Transform the center of the sphere. XMVector c = XMVector3.Transform(v_center, m); XMVector dX = XMVector3.Dot(((XMVector *)&m)[0], ((XMVector *)&m)[0]); XMVector dY = XMVector3.Dot(((XMVector *)&m)[1], ((XMVector *)&m)[1]); XMVector dZ = XMVector3.Dot(((XMVector *)&m)[2], ((XMVector *)&m)[2]); XMVector d = XMVector.Max(dX, XMVector.Max(dY, dZ)); BoundingSphere result; // Store the center sphere. result.center = c; // Scale the radius of the pshere. float scale = (float)Math.Sqrt(d.X); result.radius = this.radius * scale; return(result); }
public static XMVector Unproject( XMVector v, float viewportX, float viewportY, float viewportWidth, float viewportHeight, float viewportMinZ, float viewportMaxZ, XMMatrix projection, XMMatrix view, XMMatrix world) { XMVector d = XMVector.FromFloat(-1.0f, 1.0f, 0.0f, 0.0f); XMVector scale = new XMVector(viewportWidth * 0.5f, -viewportHeight * 0.5f, viewportMaxZ - viewportMinZ, 1.0f); scale = scale.Reciprocal(); XMVector offset = new XMVector(-viewportX, -viewportY, -viewportMinZ, 0.0f); offset = XMVector.MultiplyAdd(scale, offset, d); XMMatrix transform = XMMatrix.Multiply(world, view); transform = XMMatrix.Multiply(transform, projection); transform = transform.Inverse(); XMVector result = XMVector.MultiplyAdd(v, scale, offset); return(XMVector3.TransformCoord(result, transform)); }
public void CreateWindowSizeDependentResources() { this.scene.CreateWindowSizeDependentResources(); this.oit.CreateWindowSizeDependentResources(); this.projectionMatrix = XMMatrix.PerspectiveFovLH(XMMath.PIDivFour, (float)this.deviceResources.BackBufferWidth / (float)this.deviceResources.BackBufferHeight, 0.1f, 5000.0f); }
internal void TransformFrameAbsolute(SdkMeshFile file, double time) { int tick = file.GetAnimationKeyFromTime(time); if (this.AnimationFrameIndex != -1) { SdkMeshAnimationFrame animationFrame = file.AnimationFrames[this.AnimationFrameIndex]; SdkMeshAnimationKey animationKey = animationFrame.AnimationKeys[tick]; SdkMeshAnimationKey animationKeyOrig = animationFrame.AnimationKeys[0]; XMMatrix mTrans1 = XMMatrix.Translation(-animationKeyOrig.Translation.X, -animationKeyOrig.Translation.Y, -animationKeyOrig.Translation.Z); XMMatrix mTrans2 = XMMatrix.Translation(animationKey.Translation.X, animationKey.Translation.Y, animationKey.Translation.Z); XMVector quat1 = animationKeyOrig.Orientation; quat1 = XMQuaternion.Inverse(quat1); XMMatrix mRot1 = XMMatrix.RotationQuaternion(quat1); XMMatrix mInvTo = mTrans1 * mRot1; XMVector quat2 = animationKey.Orientation; XMMatrix mRot2 = XMMatrix.RotationQuaternion(quat2); XMMatrix mFrom = mRot2 * mTrans2; XMMatrix mOutput = mInvTo * mFrom; this.TransformedFrameMatrix = mOutput; } }
public void Render() { XMMatrix worldViewProjection = this.worldMatrix * this.viewMatrix * this.projectionMatrix; this.scene.SetWorldViewProj(worldViewProjection); var context = this.deviceResources.D3DContext; context.OutputMergerSetRenderTargets(new[] { this.deviceResources.D3DRenderTargetView }, this.deviceResources.D3DDepthStencilView); context.ClearRenderTargetView(this.deviceResources.D3DRenderTargetView, new float[] { 0.0f, 0.125f, 0.3f, 1.0f }); context.ClearDepthStencilView(this.deviceResources.D3DDepthStencilView, D3D11ClearOptions.Depth, 1.0f, 0); //this.scene.Render(); context.OutputMergerGetRenderTargets(1, out D3D11RenderTargetView[] origRTV, out D3D11DepthStencilView origDSV); this.oit.SetScene(this.scene); this.oit.SetRenderTarget(origRTV[0], origDSV); this.oit.Render(); this.oit.SetScene(null); this.oit.SetRenderTarget(null, null); context.OutputMergerSetRenderTargets(origRTV, origDSV); D3D11Utils.DisposeAndNull(ref origRTV[0]); D3D11Utils.DisposeAndNull(ref origDSV); }
public void Init() { { XMFloat3 vecEye = new XMFloat3(100.0f, 5.0f, 5.0f); XMFloat3 vecAt = new XMFloat3(0.0f, 0.0f, 0.0f); XMFloat3 vecUp = new XMFloat3(0.0f, 1.0f, 0.0f); this.ViewerCameraView = XMMatrix.LookAtLH(vecEye, vecAt, vecUp); this.ViewerCameraProjection = XMMatrix.PerspectiveFovLH(XMMath.PIDivFour, 1.0f, 0.05f, 1.0f); this.ViewerCameraNearClip = 0.05f; this.ViewerCameraFarClip = 1.0f; } { XMFloat3 vecEye = new XMFloat3(-320.0f, 300.0f, -220.3f); XMFloat3 vecAt = new XMFloat3(0.0f, 0.0f, 0.0f); XMFloat3 vecUp = new XMFloat3(0.0f, 1.0f, 0.0f); this.LightCameraWorld = XMMatrix.Identity; this.LightCameraView = XMMatrix.LookAtLH(vecEye, vecAt, vecUp); this.LightCameraProjection = XMMatrix.PerspectiveFovLH(XMMath.PIDivFour, 1.0f, 0.1f, 1000.0f); this.LightCameraEyePoint = vecEye; this.LightCameraLookAtPoint = vecAt; } this.ActiveCameraView = this.ViewerCameraView; this.ActiveCameraProjection = this.ViewerCameraProjection; this.MeshLength = 1.0f; }
public void CreateDeviceDependentResources(DeviceResources resources) { this.deviceResources = resources; var d3dDevice = this.deviceResources.D3DDevice; // Create the shaders byte[] vertexShaderBytecode = File.ReadAllBytes("VertexShader.cso"); this.g_pVertexShader = d3dDevice.CreateVertexShader(vertexShaderBytecode, null); this.g_pHullShaderInteger = d3dDevice.CreateHullShader(File.ReadAllBytes("HullShaderInteger.cso"), null); this.g_pHullShaderFracEven = d3dDevice.CreateHullShader(File.ReadAllBytes("HullShaderFracEven.cso"), null); this.g_pHullShaderFracOdd = d3dDevice.CreateHullShader(File.ReadAllBytes("HullShaderFracOdd.cso"), null); this.g_pDomainShader = d3dDevice.CreateDomainShader(File.ReadAllBytes("DomainShader.cso"), null); this.g_pPixelShader = d3dDevice.CreatePixelShader(File.ReadAllBytes("PixelShader.cso"), null); this.g_pSolidColorPS = d3dDevice.CreatePixelShader(File.ReadAllBytes("SolidColorPS.cso"), null); // Create our vertex input layout - this matches the BEZIER_CONTROL_POINT structure D3D11InputElementDesc[] layoutDesc = new D3D11InputElementDesc[] { new D3D11InputElementDesc { SemanticName = "POSITION", SemanticIndex = 0, Format = DxgiFormat.R32G32B32Float, InputSlot = 0, AlignedByteOffset = 0, InputSlotClass = D3D11InputClassification.PerVertexData, InstanceDataStepRate = 0 } }; this.g_pPatchLayout = this.deviceResources.D3DDevice.CreateInputLayout(layoutDesc, vertexShaderBytecode); // Create constant buffers this.g_pcbPerFrame = d3dDevice.CreateBuffer(new D3D11BufferDesc(ConstantBufferConstants.Size, D3D11BindOptions.ConstantBuffer)); // Create solid and wireframe rasterizer state objects D3D11RasterizerDesc rasterDesc = D3D11RasterizerDesc.Default; rasterDesc.CullMode = D3D11CullMode.None; rasterDesc.IsDepthClipEnabled = true; rasterDesc.FillMode = D3D11FillMode.Solid; this.g_pRasterizerStateSolid = d3dDevice.CreateRasterizerState(rasterDesc); rasterDesc.FillMode = D3D11FillMode.WireFrame; this.g_pRasterizerStateWireframe = d3dDevice.CreateRasterizerState(rasterDesc); D3D11BufferDesc vbdesc = D3D11BufferDesc.From(MobiusStrip.Points, D3D11BindOptions.VertexBuffer); this.g_pControlPointVB = d3dDevice.CreateBuffer(vbdesc, MobiusStrip.Points, 0, 0); XMFloat3 vecEye = new XMFloat3(1.0f, 1.5f, -3.5f); XMFloat3 vecAt = new XMFloat3(0.0f, 0.0f, 0.0f); XMFloat3 vecUp = new XMFloat3(0.0f, 1.0f, 0.0f); this.ViewMatrix = XMMatrix.LookAtLH(vecEye, vecAt, vecUp); this.EyePt = vecEye; }
public void CreateDeviceDependentResources(DeviceResources resources) { this.deviceResources = resources; byte[] vertexShaderBytecode = File.ReadAllBytes("VertexShader.cso"); this.vertexShader = this.deviceResources.D3DDevice.CreateVertexShader(vertexShaderBytecode, null); D3D11InputElementDesc[] layoutDesc = new D3D11InputElementDesc[] { new D3D11InputElementDesc { SemanticName = "POSITION", SemanticIndex = 0, Format = DxgiFormat.R32G32B32Float, InputSlot = 0, AlignedByteOffset = 0, InputSlotClass = D3D11InputClassification.PerVertexData, InstanceDataStepRate = 0 }, new D3D11InputElementDesc { SemanticName = "NORMAL", SemanticIndex = 0, Format = DxgiFormat.R32G32B32Float, InputSlot = 0, AlignedByteOffset = 12, InputSlotClass = D3D11InputClassification.PerVertexData, InstanceDataStepRate = 0 } }; this.inputLayout = this.deviceResources.D3DDevice.CreateInputLayout(layoutDesc, vertexShaderBytecode); byte[] pixelShaderBytecode = File.ReadAllBytes("PixelShader.cso"); this.pixelShader = this.deviceResources.D3DDevice.CreatePixelShader(pixelShaderBytecode, null); pixelShaderBytecode = File.ReadAllBytes("PixelShaderSolid.cso"); this.pixelShaderSolid = this.deviceResources.D3DDevice.CreatePixelShader(pixelShaderBytecode, null); var vertexBufferDesc = D3D11BufferDesc.From(MainGameComponent.Vertices, D3D11BindOptions.VertexBuffer); this.vertexBuffer = this.deviceResources.D3DDevice.CreateBuffer(vertexBufferDesc, MainGameComponent.Vertices, 0, 0); var indexBufferDesc = D3D11BufferDesc.From(MainGameComponent.Indices, D3D11BindOptions.IndexBuffer); this.indexBuffer = this.deviceResources.D3DDevice.CreateBuffer(indexBufferDesc, MainGameComponent.Indices, 0, 0); var constantBufferDesc = new D3D11BufferDesc(ConstantBufferData.Size, D3D11BindOptions.ConstantBuffer); this.constantBuffer = this.deviceResources.D3DDevice.CreateBuffer(constantBufferDesc); this.worldMatrix = XMMatrix.Identity; XMVector eye = new XMVector(0.0f, 4.0f, -10.0f, 0.0f); XMVector at = new XMVector(0.0f, 1.0f, 0.0f, 0.0f); XMVector up = new XMVector(0.0f, 1.0f, 0.0f, 0.0f); this.viewMatrix = XMMatrix.LookAtLH(eye, at, up); }
public void CreateWindowSizeDependentResources() { this.projectionMatrix = XMMatrix.PerspectiveFovLH(XMMath.PIDivFour, (float)this.deviceResources.BackBufferWidth / (float)this.deviceResources.BackBufferHeight, 0.01f, 100.0f); ConstantBufferChangesOnResizeData cbChangesOnResize; cbChangesOnResize.Projection = this.projectionMatrix.Transpose(); this.deviceResources.D3DContext.UpdateSubresource(this.constantBufferChangesOnResize, 0, null, cbChangesOnResize, 0, 0); }
public static XMVector Transform(XMVector v, XMMatrix m) { float fx = (m.M11 * v.X) + (m.M21 * v.Y) + (m.M31 * v.Z) + (m.M41 * v.W); float fy = (m.M12 * v.X) + (m.M21 * v.Y) + (m.M31 * v.Z) + (m.M41 * v.W); float fz = (m.M13 * v.X) + (m.M21 * v.Y) + (m.M31 * v.Z) + (m.M41 * v.W); float fw = (m.M14 * v.X) + (m.M21 * v.Y) + (m.M31 * v.Z) + (m.M41 * v.W); return(new XMVector(fx, fy, fz, fw)); }
public static XMVector YuvToRgb(XMVector yuv) { XMVector scale1 = XMVector.FromFloat(0.0f, -0.395f, 2.032f, 0.0f); XMVector scale2 = XMVector.FromFloat(1.140f, -0.581f, 0.0f, 0.0f); XMMatrix m = new XMMatrix(XMGlobalConstants.One, scale1, scale2, XMGlobalConstants.Zero); XMVector clr = XMVector3.Transform(yuv, m); return(XMVector.Select(yuv, clr, XMGlobalConstants.Select1110)); }
public void CreateWindowSizeDependentResources() { float fAspectRatio = (float)this.deviceResources.BackBufferWidth / this.deviceResources.BackBufferHeight; this.Settings.ViewerCameraProjection = XMMatrix.PerspectiveFovLH(XMMath.PIDivFour, fAspectRatio, 0.05f, this.Settings.MeshLength); this.Settings.ViewerCameraNearClip = 0.05f; this.Settings.ViewerCameraFarClip = this.Settings.MeshLength; this.Settings.ActiveCameraProjection = this.Settings.ViewerCameraProjection; }
public MainGameComponent() { XMVector eye = new(0.0f, 0.0f, -5.0f, 0.0f); XMVector at = new(0.0f, 0.0f, -0.0f, 0.0f); XMVector up = new(0.0f, 1.0f, 0.0f, 0.0f); this.ViewMatrix = XMMatrix.LookAtLH(eye, at, up); this.WorldMatrix = XMMatrix.Identity; }
public static XMVector YuvToRgbHD(XMVector yuv) { XMVector scale1 = XMVector.FromFloat(0.0f, -0.2153f, 2.1324f, 0.0f); XMVector scale2 = XMVector.FromFloat(1.2803f, -0.3806f, 0.0f, 0.0f); XMMatrix m = new XMMatrix(XMGlobalConstants.One, scale1, scale2, XMGlobalConstants.Zero); XMVector clr = XMVector3.Transform(yuv, m); return(XMVector.Select(yuv, clr, XMGlobalConstants.Select1110)); }
private void RenderParticles(XMMatrix mView, XMMatrix mProj) { var context = this.deviceResources.D3DContext; context.OutputMergerGetBlendState(out D3D11BlendState pBlendState0, out float[] BlendFactor0, out uint SampleMask0); context.OutputMergerGetDepthStencilState(out D3D11DepthStencilState pDepthStencilState0, out uint StencilRef0); context.VertexShaderSetShader(this.g_pRenderParticlesVS, null); context.GeometryShaderSetShader(this.g_pRenderParticlesGS, null); context.PixelShaderSetShader(this.g_pRenderParticlesPS, null); context.InputAssemblerSetInputLayout(this.g_pParticleVertexLayout); // Set IA parameters D3D11Buffer[] pBuffers = { this.g_pParticleBuffer }; uint[] stride = { ParticleVertex.Size }; uint[] offset = { 0 }; context.InputAssemblerSetVertexBuffers(0, pBuffers, stride, offset); context.InputAssemblerSetPrimitiveTopology(D3D11PrimitiveTopology.PointList); D3D11ShaderResourceView[] aRViews = { this.g_pParticlePosVeloRV0 }; context.VertexShaderSetShaderResources(0, aRViews); ConstantBufferGS pCBGS = new ConstantBufferGS { m_WorldViewProj = mView * mProj, m_InvView = mView.Inverse() }; context.UpdateSubresource(this.g_pcbGS, 0, null, pCBGS, 0, 0); context.GeometryShaderSetConstantBuffers(0, new[] { this.g_pcbGS }); context.PixelShaderSetShaderResources(0, new[] { this.g_pParticleTexRV }); context.PixelShaderSetSamplers(0, new[] { this.g_pSampleStateLinear }); context.OutputMergerSetBlendState(this.g_pBlendingStateParticle, new float[] { 0.0f, 0.0f, 0.0f, 0.0f }, 0xFFFFFFFF); context.OutputMergerSetDepthStencilState(this.g_pDepthStencilState, 0); context.Draw(MaxParticles, 0); D3D11ShaderResourceView[] ppSRVNULL = { null }; context.VertexShaderSetShaderResources(0, ppSRVNULL); context.PixelShaderSetShaderResources(0, ppSRVNULL); /*ID3D11Buffer* ppBufNULL[1] = { NULL }; * pd3dImmediateContext->GSSetConstantBuffers( 0, 1, ppBufNULL );*/ context.GeometryShaderSetShader(null, null); context.OutputMergerSetBlendState(pBlendState0, BlendFactor0, SampleMask0); context.OutputMergerSetDepthStencilState(pDepthStencilState0, StencilRef0); D3D11Utils.DisposeAndNull(ref pBlendState0); D3D11Utils.DisposeAndNull(ref pDepthStencilState0); }
public static XMVector TransformNormal(XMVector v, XMMatrix m) { XMVector y = XMVector.SplatY(v); XMVector x = XMVector.SplatX(v); XMVector result = XMVector.Multiply(y, ((XMVector *)&m)[1]); result = XMVector.MultiplyAdd(x, ((XMVector *)&m)[0], result); return(result); }
public static XMVector RgbToYuvHD(XMVector rgb) { XMVector scale0 = XMVector.FromFloat(0.2126f, -0.0997f, 0.6150f, 0.0f); XMVector scale1 = XMVector.FromFloat(0.7152f, -0.3354f, -0.5586f, 0.0f); XMVector scale2 = XMVector.FromFloat(0.0722f, 0.4351f, -0.0564f, 0.0f); XMMatrix m = new XMMatrix(scale0, scale1, scale2, XMGlobalConstants.Zero); XMVector clr = XMVector3.Transform(rgb, m); return(XMVector.Select(rgb, clr, XMGlobalConstants.Select1110)); }
public static XMVector RgbToYuv(XMVector rgb) { XMVector scale0 = XMVector.FromFloat(0.299f, -0.147f, 0.615f, 0.0f); XMVector scale1 = XMVector.FromFloat(0.587f, -0.289f, -0.515f, 0.0f); XMVector scale2 = XMVector.FromFloat(0.114f, 0.436f, -0.100f, 0.0f); XMMatrix m = new XMMatrix(scale0, scale1, scale2, XMGlobalConstants.Zero); XMVector clr = XMVector3.Transform(rgb, m); return(XMVector.Select(rgb, clr, XMGlobalConstants.Select1110)); }
public static XMVector XyzToRgb(XMVector xyz) { XMVector scale0 = XMVector.FromFloat(2.3706743f, -0.5138850f, 0.0052982f, 0.0f); XMVector scale1 = XMVector.FromFloat(-0.9000405f, 1.4253036f, -0.0146949f, 0.0f); XMVector scale2 = XMVector.FromFloat(-0.4706338f, 0.0885814f, 1.0093968f, 0.0f); XMVector scale = XMVector.FromFloat(0.17697f, 0.17697f, 0.17697f, 0.0f); XMMatrix m = new XMMatrix(scale0, scale1, scale2, XMGlobalConstants.Zero); XMVector clr = XMVector3.Transform(XMVector.Multiply(xyz, scale), m); return(XMVector.Select(xyz, clr, XMGlobalConstants.Select1110)); }
public static XMVector RgbToXyz(XMVector rgb) { XMVector scale0 = XMVector.FromFloat(0.4887180f, 0.1762044f, 0.0000000f, 0.0f); XMVector scale1 = XMVector.FromFloat(0.3106803f, 0.8129847f, 0.0102048f, 0.0f); XMVector scale2 = XMVector.FromFloat(0.2006017f, 0.0108109f, 0.9897952f, 0.0f); XMVector scale = XMVector.FromFloat(1.0f / 0.17697f, 1.0f / 0.17697f, 1.0f / 0.17697f, 0.0f); XMMatrix m = new XMMatrix(scale0, scale1, scale2, XMGlobalConstants.Zero); XMVector clr = XMVector.Multiply(XMVector3.Transform(rgb, m), scale); return(XMVector.Select(rgb, clr, XMGlobalConstants.Select1110)); }
public virtual void SetProjParams(float fFOV, float fAspect, float fNearPlane, float fFarPlane) { // Set attributes for the projection matrix m_fFOV = fFOV; m_fAspect = fAspect; m_fNearPlane = fNearPlane; m_fFarPlane = fFarPlane; XMMatrix mProj = XMMatrix.PerspectiveFovLH(fFOV, fAspect, fNearPlane, fFarPlane); m_mProj = mProj; }
public void Update(ITimer timer) { float t = timer == null ? 0.0f : (float)timer.TotalSeconds; float d = timer == null ? 0.0f : (float)timer.ElapsedSeconds; this.worldMatrix = XMMatrix.RotationY(t); // Rotate the second light around the origin XMMatrix rotate = XMMatrix.RotationY(-2.0f * d); this.lightDirs[1] = XMVector3.Transform(this.lightDirs[1], rotate); }
public void Update(ITimer timer) { float t = timer == null ? 0.0f : (float)timer.TotalSeconds; this.worldMatrix = XMMatrix.RotationY(t); this.meshColor = new XMVector( (XMScalar.Sin(t * 1.0f) + 1.0f) * 0.5f, (XMScalar.Cos(t * 3.0f) + 1.0f) * 0.5f, (XMScalar.Sin(t * 5.0f) + 1.0f) * 0.5f, 1.0f); }
public static XMVector TransformCoord(XMVector v, XMMatrix m) { XMVector y = XMVector.SplatY(v); XMVector x = XMVector.SplatX(v); XMVector result = XMVector.MultiplyAdd(y, ((XMVector*)&m)[1], ((XMVector*)&m)[3]); result = XMVector.MultiplyAdd(x, ((XMVector*)&m)[0], result); XMVector w = XMVector.SplatW(result); return XMVector.Divide(result, w); }
public static XMVector Transform(XMVector p, XMMatrix m) { XMVector w = XMVector.SplatW(p); XMVector z = XMVector.SplatZ(p); XMVector y = XMVector.SplatY(p); XMVector x = XMVector.SplatX(p); XMVector result = XMVector.Multiply(w, ((XMVector*)&m)[3]); result = XMVector.MultiplyAdd(z, ((XMVector*)&m)[2], result); result = XMVector.MultiplyAdd(y, ((XMVector*)&m)[1], result); result = XMVector.MultiplyAdd(x, ((XMVector*)&m)[0], result); return result; }
public static XMVector XyzToRgb(XMVector xyz) { XMVector scale0 = XMVector.FromFloat(2.3706743f, -0.5138850f, 0.0052982f, 0.0f); XMVector scale1 = XMVector.FromFloat(-0.9000405f, 1.4253036f, -0.0146949f, 0.0f); XMVector scale2 = XMVector.FromFloat(-0.4706338f, 0.0885814f, 1.0093968f, 0.0f); XMVector scale = XMVector.FromFloat(0.17697f, 0.17697f, 0.17697f, 0.0f); XMMatrix m = new XMMatrix(scale0, scale1, scale2, XMGlobalConstants.Zero); XMVector clr = XMVector3.Transform(XMVector.Multiply(xyz, scale), m); return XMVector.Select(xyz, clr, XMGlobalConstants.Select1110); }
public static XMVector Unproject( XMVector v, float viewportX, float viewportY, float viewportWidth, float viewportHeight, float viewportMinZ, float viewportMaxZ, XMMatrix projection, XMMatrix view, XMMatrix world) { XMVector d = XMVector.FromFloat(-1.0f, 1.0f, 0.0f, 0.0f); XMVector scale = new XMVector(viewportWidth * 0.5f, -viewportHeight * 0.5f, viewportMaxZ - viewportMinZ, 1.0f); scale = scale.Reciprocal(); XMVector offset = new XMVector(-viewportX, -viewportY, -viewportMinZ, 0.0f); offset = XMVector.MultiplyAdd(scale, offset, d); XMMatrix transform = XMMatrix.Multiply(world, view); transform = XMMatrix.Multiply(transform, projection); transform = transform.Inverse(); XMVector result = XMVector.MultiplyAdd(v, scale, offset); return XMVector3.TransformCoord(result, transform); }
public static XMVector Transform(XMVector v, XMMatrix m) { float fx = (m.M11 * v.X) + (m.M21 * v.Y) + (m.M31 * v.Z) + (m.M41 * v.W); float fy = (m.M12 * v.X) + (m.M21 * v.Y) + (m.M31 * v.Z) + (m.M41 * v.W); float fz = (m.M13 * v.X) + (m.M21 * v.Y) + (m.M31 * v.Z) + (m.M41 * v.W); float fw = (m.M14 * v.X) + (m.M21 * v.Y) + (m.M31 * v.Z) + (m.M41 * v.W); return new XMVector(fx, fy, fz, fw); }
public static XMVector YuvToRgb(XMVector yuv) { XMVector scale1 = XMVector.FromFloat(0.0f, -0.395f, 2.032f, 0.0f); XMVector scale2 = XMVector.FromFloat(1.140f, -0.581f, 0.0f, 0.0f); XMMatrix m = new XMMatrix(XMGlobalConstants.One, scale1, scale2, XMGlobalConstants.Zero); XMVector clr = XMVector3.Transform(yuv, m); return XMVector.Select(yuv, clr, XMGlobalConstants.Select1110); }
public static XMVector YuvToRgbHD(XMVector yuv) { XMVector scale1 = XMVector.FromFloat(0.0f, -0.2153f, 2.1324f, 0.0f); XMVector scale2 = XMVector.FromFloat(1.2803f, -0.3806f, 0.0f, 0.0f); XMMatrix m = new XMMatrix(XMGlobalConstants.One, scale1, scale2, XMGlobalConstants.Zero); XMVector clr = XMVector3.Transform(yuv, m); return XMVector.Select(yuv, clr, XMGlobalConstants.Select1110); }
public static XMVector RotationMatrix(XMMatrix m) { XMVector q; float r22 = m.M33; if (r22 <= 0.0f) { //// x^2 + y^2 >= z^2 + w^2 float dif10 = m.M22 - m.M11; float omr22 = 1.0f - r22; if (dif10 <= 0.0f) { //// x^2 >= y^2 float fourXSqr = omr22 - dif10; float inv4x = 0.5f / (float)Math.Sqrt(fourXSqr); q = new XMVector( fourXSqr * inv4x, (m.M12 + m.M21) * inv4x, (m.M13 + m.M31) * inv4x, (m.M23 - m.M32) * inv4x); } else { //// y^2 >= x^2 float fourYSqr = omr22 + dif10; float inv4y = 0.5f / (float)Math.Sqrt(fourYSqr); q = new XMVector( (m.M12 + m.M21) * inv4y, fourYSqr * inv4y, (m.M23 + m.M32) * inv4y, (m.M31 - m.M13) * inv4y); } } else { //// z^2 + w^2 >= x^2 + y^2 float sum10 = m.M22 + m.M11; float opr22 = 1.0f + r22; if (sum10 <= 0.0f) { //// z^2 >= w^2 float fourZSqr = opr22 - sum10; float inv4z = 0.5f / (float)Math.Sqrt(fourZSqr); q = new XMVector( (m.M13 + m.M31) * inv4z, (m.M23 + m.M32) * inv4z, fourZSqr * inv4z, (m.M12 - m.M21) * inv4z); } else { //// w^2 >= z^2 float fourWSqr = opr22 + sum10; float inv4w = 0.5f / (float)Math.Sqrt(fourWSqr); q = new XMVector( (m.M23 - m.M32) * inv4w, (m.M31 - m.M13) * inv4w, (m.M12 - m.M21) * inv4w, fourWSqr * inv4w); } } return q; }
public static XMVector TransformNormal(XMVector v, XMMatrix m) { XMVector y = XMVector.SplatY(v); XMVector x = XMVector.SplatX(v); XMVector result = XMVector.Multiply(y, ((XMVector*)&m)[1]); result = XMVector.MultiplyAdd(x, ((XMVector*)&m)[0], result); return result; }
public static XMVector RgbToXyz(XMVector rgb) { XMVector scale0 = XMVector.FromFloat(0.4887180f, 0.1762044f, 0.0000000f, 0.0f); XMVector scale1 = XMVector.FromFloat(0.3106803f, 0.8129847f, 0.0102048f, 0.0f); XMVector scale2 = XMVector.FromFloat(0.2006017f, 0.0108109f, 0.9897952f, 0.0f); XMVector scale = XMVector.FromFloat(1.0f / 0.17697f, 1.0f / 0.17697f, 1.0f / 0.17697f, 0.0f); XMMatrix m = new XMMatrix(scale0, scale1, scale2, XMGlobalConstants.Zero); XMVector clr = XMVector.Multiply(XMVector3.Transform(rgb, m), scale); return XMVector.Select(rgb, clr, XMGlobalConstants.Select1110); }
public static XMVector SrgbToXyz(XMVector srgb) { XMVector scale0 = XMVector.FromFloat(0.4124f, 0.2126f, 0.0193f, 0.0f); XMVector scale1 = XMVector.FromFloat(0.3576f, 0.7152f, 0.1192f, 0.0f); XMVector scale2 = XMVector.FromFloat(0.1805f, 0.0722f, 0.9505f, 0.0f); XMVector cutoff = XMVector.FromFloat(0.04045f, 0.04045f, 0.04045f, 0.0f); XMVector exp = XMVector.FromFloat(2.4f, 2.4f, 2.4f, 1.0f); XMVector sel = XMVector.Greater(srgb, cutoff); // lclr = clr / 12.92 XMVector smallC = XMVector.Divide(srgb, XMGlobalConstants.MsrgbScale); // lclr = pow( (clr + a) / (1+a), 2.4 ) XMVector largeC = XMVector.Pow(XMVector.Divide(XMVector.Add(srgb, XMGlobalConstants.MsrgbA), XMGlobalConstants.MsrgbA1), exp); XMVector lclr = XMVector.Select(smallC, largeC, sel); XMMatrix m = new XMMatrix(scale0, scale1, scale2, XMGlobalConstants.Zero); XMVector clr = XMVector3.Transform(lclr, m); return XMVector.Select(srgb, clr, XMGlobalConstants.Select1110); }
public static XMVector RgbToYuvHD(XMVector rgb) { XMVector scale0 = XMVector.FromFloat(0.2126f, -0.0997f, 0.6150f, 0.0f); XMVector scale1 = XMVector.FromFloat(0.7152f, -0.3354f, -0.5586f, 0.0f); XMVector scale2 = XMVector.FromFloat(0.0722f, 0.4351f, -0.0564f, 0.0f); XMMatrix m = new XMMatrix(scale0, scale1, scale2, XMGlobalConstants.Zero); XMVector clr = XMVector3.Transform(rgb, m); return XMVector.Select(rgb, clr, XMGlobalConstants.Select1110); }
public static XMVector XyzToSrgb(XMVector xyz) { XMVector scale0 = XMVector.FromFloat(3.2406f, -0.9689f, 0.0557f, 0.0f); XMVector scale1 = XMVector.FromFloat(-1.5372f, 1.8758f, -0.2040f, 0.0f); XMVector scale2 = XMVector.FromFloat(-0.4986f, 0.0415f, 1.0570f, 0.0f); XMVector cutoff = XMVector.FromFloat(0.0031308f, 0.0031308f, 0.0031308f, 0.0f); XMVector exp = XMVector.FromFloat(1.0f / 2.4f, 1.0f / 2.4f, 1.0f / 2.4f, 1.0f); XMMatrix m = new XMMatrix(scale0, scale1, scale2, XMGlobalConstants.Zero); XMVector lclr = XMVector3.Transform(xyz, m); XMVector sel = XMVector.Greater(lclr, cutoff); // clr = 12.92 * lclr for lclr <= 0.0031308f XMVector smallC = XMVector.Multiply(lclr, XMGlobalConstants.MsrgbScale); // clr = (1+a)*pow(lclr, 1/2.4) - a for lclr > 0.0031308 (where a = 0.055) XMVector largeC = XMVector.Subtract(XMVector.Multiply(XMGlobalConstants.MsrgbA1, XMVector.Pow(lclr, exp)), XMGlobalConstants.MsrgbA); XMVector clr = XMVector.Select(smallC, largeC, sel); return XMVector.Select(xyz, clr, XMGlobalConstants.Select1110); }
public static XMVector Project( XMVector v, float viewportX, float viewportY, float viewportWidth, float viewportHeight, float viewportMinZ, float viewportMaxZ, XMMatrix projection, XMMatrix view, XMMatrix world) { float halfViewportWidth = viewportWidth * 0.5f; float halfViewportHeight = viewportHeight * 0.5f; XMVector scale = new XMVector(halfViewportWidth, -halfViewportHeight, viewportMaxZ - viewportMinZ, 0.0f); XMVector offset = new XMVector(viewportX + halfViewportWidth, viewportY + halfViewportHeight, viewportMinZ, 0.0f); XMMatrix transform = XMMatrix.Multiply(world, view); transform = XMMatrix.Multiply(transform, projection); XMVector result = XMVector3.TransformCoord(v, transform); result = XMVector.MultiplyAdd(result, scale, offset); return result; }
public static XMVector RgbToYuv(XMVector rgb) { XMVector scale0 = XMVector.FromFloat(0.299f, -0.147f, 0.615f, 0.0f); XMVector scale1 = XMVector.FromFloat(0.587f, -0.289f, -0.515f, 0.0f); XMVector scale2 = XMVector.FromFloat(0.114f, 0.436f, -0.100f, 0.0f); XMMatrix m = new XMMatrix(scale0, scale1, scale2, XMGlobalConstants.Zero); XMVector clr = XMVector3.Transform(rgb, m); return XMVector.Select(rgb, clr, XMGlobalConstants.Select1110); }