public void DrawSunAndMoon(Camera camera) { float globalPrecipitationIntensity = m_subsystemWeather.GlobalPrecipitationIntensity; float timeOfDay = m_subsystemTimeOfDay.TimeOfDay; float f = MathUtils.Max(CalculateDawnGlowIntensity(timeOfDay), CalculateDuskGlowIntensity(timeOfDay)); float num = 2f * timeOfDay * (float)Math.PI; float angle = num + (float)Math.PI; float num2 = MathUtils.Lerp(90f, 160f, f); float num3 = MathUtils.Lerp(60f, 80f, f); Color color = Color.Lerp(new Color(255, 255, 255), new Color(255, 255, 160), f); Color white = Color.White; white *= 1f - SkyLightIntensity; color *= MathUtils.Lerp(1f, 0f, globalPrecipitationIntensity); white *= MathUtils.Lerp(1f, 0f, globalPrecipitationIntensity); Color color2 = color * 0.6f * MathUtils.Lerp(1f, 0f, globalPrecipitationIntensity); Color color3 = color * 0.2f * MathUtils.Lerp(1f, 0f, globalPrecipitationIntensity); TexturedBatch3D batch = m_primitivesRenderer3d.TexturedBatch(m_glowTexture, useAlphaTest: false, 0, DepthStencilState.DepthRead, null, BlendState.Additive); TexturedBatch3D batch2 = m_primitivesRenderer3d.TexturedBatch(m_sunTexture, useAlphaTest: false, 1, DepthStencilState.DepthRead, null, BlendState.AlphaBlend); TexturedBatch3D batch3 = m_primitivesRenderer3d.TexturedBatch(m_moonTextures[MoonPhase], useAlphaTest: false, 1, DepthStencilState.DepthRead, null, BlendState.AlphaBlend); QueueCelestialBody(batch, camera.ViewPosition, color2, 900f, 3.5f * num2, num); QueueCelestialBody(batch, camera.ViewPosition, color3, 900f, 3.5f * num3, angle); QueueCelestialBody(batch2, camera.ViewPosition, color, 900f, num2, num); QueueCelestialBody(batch3, camera.ViewPosition, white, 900f, num3, angle); }
public override void Load(ValuesDictionary valuesDictionary) { m_subsystemSky = base.Project.FindSubsystem <SubsystemSky>(throwOnError: true); m_batchesByType[0] = m_primitivesRenderer.TexturedBatch(ContentManager.Get <Texture2D>("Textures/RoundGlow"), useAlphaTest: false, 0, DepthStencilState.DepthRead, RasterizerState.CullCounterClockwiseScissor, BlendState.AlphaBlend, SamplerState.LinearClamp); m_batchesByType[1] = m_primitivesRenderer.TexturedBatch(ContentManager.Get <Texture2D>("Textures/SquareGlow"), useAlphaTest: false, 0, DepthStencilState.DepthRead, RasterizerState.CullCounterClockwiseScissor, BlendState.AlphaBlend, SamplerState.LinearClamp); m_batchesByType[2] = m_primitivesRenderer.TexturedBatch(ContentManager.Get <Texture2D>("Textures/HorizontalRectGlow"), useAlphaTest: false, 0, DepthStencilState.DepthRead, RasterizerState.CullCounterClockwiseScissor, BlendState.AlphaBlend, SamplerState.LinearClamp); m_batchesByType[3] = m_primitivesRenderer.TexturedBatch(ContentManager.Get <Texture2D>("Textures/VerticalRectGlow"), useAlphaTest: false, 0, DepthStencilState.DepthRead, RasterizerState.CullCounterClockwiseScissor, BlendState.AlphaBlend, SamplerState.LinearClamp); }
public void DrawReticleHighlight(Camera camera) { if (camera.Eye.HasValue && m_highlightRaycastResult is TerrainRaycastResult) { TerrainRaycastResult terrainRaycastResult = (TerrainRaycastResult)m_highlightRaycastResult; Vector3 vector = terrainRaycastResult.HitPoint(); Vector3 vector2 = (!(BlocksManager.Blocks[Terrain.ExtractContents(terrainRaycastResult.Value)] is CrossBlock)) ? CellFace.FaceToVector3(terrainRaycastResult.CellFace.Face) : (-terrainRaycastResult.Ray.Direction); float num = Vector3.Distance(camera.ViewPosition, vector); float s = 0.03f + MathUtils.Min(0.008f * num, 0.04f); float s2 = 0.01f * num; Vector3 v = (MathUtils.Abs(Vector3.Dot(vector2, Vector3.UnitY)) < 0.5f) ? Vector3.UnitY : Vector3.UnitX; Vector3 vector3 = Vector3.Normalize(Vector3.Cross(vector2, v)); Vector3 v2 = Vector3.Normalize(Vector3.Cross(vector2, vector3)); Subtexture subtexture = ContentManager.Get <Subtexture>("Textures/Atlas/Reticle"); TexturedBatch3D texturedBatch3D = m_primitivesRenderer3D.TexturedBatch(subtexture.Texture, useAlphaTest: false, 0, DepthStencilState.DepthRead, null, null, SamplerState.LinearClamp); Vector3 p = vector + s * (-vector3 + v2) + s2 * vector2; Vector3 p2 = vector + s * (vector3 + v2) + s2 * vector2; Vector3 p3 = vector + s * (vector3 - v2) + s2 * vector2; Vector3 p4 = vector + s * (-vector3 - v2) + s2 * vector2; Vector2 texCoord = new Vector2(subtexture.TopLeft.X, subtexture.TopLeft.Y); Vector2 texCoord2 = new Vector2(subtexture.BottomRight.X, subtexture.TopLeft.Y); Vector2 texCoord3 = new Vector2(subtexture.BottomRight.X, subtexture.BottomRight.Y); Vector2 texCoord4 = new Vector2(subtexture.TopLeft.X, subtexture.BottomRight.Y); texturedBatch3D.QueueQuad(p, p2, p3, p4, texCoord, texCoord2, texCoord3, texCoord4, Color.White); texturedBatch3D.Flush(camera.ViewProjectionMatrix); } }
public void DrawSigns(Camera camera) { if (m_nearTexts.Count > 0) { TexturedBatch3D texturedBatch3D = m_primitivesRenderer3D.TexturedBatch(m_renderTarget, useAlphaTest: false, 0, DepthStencilState.DepthRead, RasterizerState.CullCounterClockwiseScissor, null, SamplerState.PointClamp); foreach (TextData nearText in m_nearTexts) { if (nearText.TextureLocation.HasValue) { int cellValue = m_subsystemTerrain.Terrain.GetCellValue(nearText.Point.X, nearText.Point.Y, nearText.Point.Z); int num = Terrain.ExtractContents(cellValue); SignBlock signBlock = BlocksManager.Blocks[num] as SignBlock; if (signBlock != null) { int data = Terrain.ExtractData(cellValue); BlockMesh signSurfaceBlockMesh = signBlock.GetSignSurfaceBlockMesh(data); if (signSurfaceBlockMesh != null) { TerrainChunk chunkAtCell = m_subsystemTerrain.Terrain.GetChunkAtCell(nearText.Point.X, nearText.Point.Z); if (chunkAtCell != null && chunkAtCell.State >= TerrainChunkState.InvalidVertices1) { nearText.Light = Terrain.ExtractLight(cellValue); } float num2 = LightingManager.LightIntensityByLightValue[nearText.Light]; Color color = new Color(num2, num2, num2); float x = 0f; float x2 = nearText.UsedTextureWidth / 128f; float x3 = (float)nearText.TextureLocation.Value / 32f; float x4 = ((float)nearText.TextureLocation.Value + nearText.UsedTextureHeight / 32f) / 32f; Vector3 signSurfaceNormal = signBlock.GetSignSurfaceNormal(data); Vector3 vector = new Vector3(nearText.Point.X, nearText.Point.Y, nearText.Point.Z); float num3 = Vector3.Dot(camera.ViewPosition - (vector + new Vector3(0.5f)), signSurfaceNormal); Vector3 v = MathUtils.Max(0.01f * num3, 0.005f) * signSurfaceNormal; for (int i = 0; i < signSurfaceBlockMesh.Indices.Count / 3; i++) { BlockMeshVertex blockMeshVertex = signSurfaceBlockMesh.Vertices.Array[signSurfaceBlockMesh.Indices.Array[i * 3]]; BlockMeshVertex blockMeshVertex2 = signSurfaceBlockMesh.Vertices.Array[signSurfaceBlockMesh.Indices.Array[i * 3 + 1]]; BlockMeshVertex blockMeshVertex3 = signSurfaceBlockMesh.Vertices.Array[signSurfaceBlockMesh.Indices.Array[i * 3 + 2]]; Vector3 p = blockMeshVertex.Position + vector + v; Vector3 p2 = blockMeshVertex2.Position + vector + v; Vector3 p3 = blockMeshVertex3.Position + vector + v; Vector2 textureCoordinates = blockMeshVertex.TextureCoordinates; Vector2 textureCoordinates2 = blockMeshVertex2.TextureCoordinates; Vector2 textureCoordinates3 = blockMeshVertex3.TextureCoordinates; textureCoordinates.X = MathUtils.Lerp(x, x2, textureCoordinates.X); textureCoordinates2.X = MathUtils.Lerp(x, x2, textureCoordinates2.X); textureCoordinates3.X = MathUtils.Lerp(x, x2, textureCoordinates3.X); textureCoordinates.Y = MathUtils.Lerp(x3, x4, textureCoordinates.Y); textureCoordinates2.Y = MathUtils.Lerp(x3, x4, textureCoordinates2.Y); textureCoordinates3.Y = MathUtils.Lerp(x3, x4, textureCoordinates3.Y); texturedBatch3D.QueueTriangle(p, p2, p3, textureCoordinates, textureCoordinates2, textureCoordinates3, color); } } } } } m_primitivesRenderer3D.Flush(camera.ViewProjectionMatrix); } }
public void drawSign(Camera camera) { TexturedBatch3D texturedBatch3D = primitivesRenderer3D.TexturedBatch(m_renderTarget, false, 0, DepthStencilState.None, RasterizerState.CullCounterClockwiseScissor, BlendState.AlphaBlend, SamplerState.PointWrap); foreach (KeyValuePair <Point3, int> item in pointlist) { renderPoint = item.Key; if (Vector3.DistanceSquared(new Vector3(renderPoint), camera.ViewPosition) > 400f) { continue; //超出20f视野 } ComponentSingleChest singleChest = subsystemBlockEntities.GetBlockEntity(renderPoint.X, renderPoint.Y, renderPoint.Z).Entity.FindComponent <ComponentSingleChest>(true); if (singleChest == null || singleChest.GetSlotCount(0) == 0) { continue; } int mvalue = subsystemTerrain.Terrain.GetCellValue(renderPoint.X, renderPoint.Y, renderPoint.Z); int mpos = ILibrary.GetDirection(mvalue); BlockMesh signSurfaceBlockMesh = MekiasmInit.faceMeshes.Array[ILibrary.normalpos[mpos]]; float s = LightingManager.LightIntensityByLightValue[Terrain.ExtractLight(mvalue)]; Color color = new Color(s, s, s); Vector3 signSurfaceNormal = MekiasmInit.faceNormals.Array[ILibrary.normalface[ILibrary.normalpos[mpos]]]; Vector3 vector = new Vector3(renderPoint); float num3 = Vector3.Dot(camera.ViewPosition - (vector + new Vector3(0.5f)), signSurfaceNormal); Vector3 v = MathUtils.Max(0.01f * num3, 0.005f) * signSurfaceNormal; int indecies = signSurfaceBlockMesh.Indices.Count / 3; for (int i = 0; i < indecies; i += 2) { if (i >= indecies) { break; } BlockMeshVertex blockMeshVertex = signSurfaceBlockMesh.Vertices.Array[signSurfaceBlockMesh.Indices.Array[i * 3]]; BlockMeshVertex blockMeshVertex2 = signSurfaceBlockMesh.Vertices.Array[signSurfaceBlockMesh.Indices.Array[i * 3 + 1]]; BlockMeshVertex blockMeshVertex3 = signSurfaceBlockMesh.Vertices.Array[signSurfaceBlockMesh.Indices.Array[i * 3 + 2]]; Vector3 p = blockMeshVertex.Position + vector + v; Vector3 p2 = blockMeshVertex2.Position + vector + v; Vector3 p3 = blockMeshVertex3.Position + vector + v; Vector2 textureCoordinates = ILibrary.getTexcoord(2); Vector2 textureCoordinates2 = ILibrary.getTexcoord(3); Vector2 textureCoordinates3 = ILibrary.getTexcoord(4); texturedBatch3D.QueueTriangle(p, p2, p3, textureCoordinates, textureCoordinates2, textureCoordinates3, color); BlockMeshVertex blockMeshVertex11 = signSurfaceBlockMesh.Vertices.Array[signSurfaceBlockMesh.Indices.Array[++i * 3]]; BlockMeshVertex blockMeshVertex22 = signSurfaceBlockMesh.Vertices.Array[signSurfaceBlockMesh.Indices.Array[i * 3 + 1]]; BlockMeshVertex blockMeshVertex33 = signSurfaceBlockMesh.Vertices.Array[signSurfaceBlockMesh.Indices.Array[i * 3 + 2]]; Vector3 p11 = blockMeshVertex11.Position + vector + v; Vector3 p22 = blockMeshVertex22.Position + vector + v; Vector3 p33 = blockMeshVertex33.Position + vector + v; Vector2 textureCoordinates11 = ILibrary.getTexcoord(2); Vector2 textureCoordinates22 = ILibrary.getTexcoord(4); Vector2 textureCoordinates33 = ILibrary.getTexcoord(1); texturedBatch3D.QueueTriangle(p11, p22, p33, textureCoordinates11, textureCoordinates22, textureCoordinates33, color); } Updated(singleChest.GetSlotValue(0), singleChest.GetSlotCount(0)); primitivesRenderer3D.Flush(camera.ViewProjectionMatrix); } }
public void Draw(Camera camera, int drawOrder) { if (camera.GameWidget != m_componentPlayer.GameWidget) { return; } if (m_componentPlayer.ComponentHealth.Health > 0f && m_componentPlayer.ComponentGui.ControlsContainerWidget.IsVisible) { if (IsSightsVisible) { Texture2D texture = ContentManager.Get <Texture2D>("Textures/Gui/Sights"); float s = (!camera.Eye.HasValue) ? 8f : 2.5f; Vector3 v = m_sightsPosition + m_sightsDirection * 50f; Vector3 vector = Vector3.Normalize(Vector3.Cross(m_sightsDirection, Vector3.UnitY)); Vector3 v2 = Vector3.Normalize(Vector3.Cross(m_sightsDirection, vector)); Vector3 p = v + s * (-vector - v2); Vector3 p2 = v + s * (vector - v2); Vector3 p3 = v + s * (vector + v2); Vector3 p4 = v + s * (-vector + v2); TexturedBatch3D texturedBatch3D = m_primitivesRenderer3D.TexturedBatch(texture, useAlphaTest: false, 0, DepthStencilState.None); int count = texturedBatch3D.TriangleVertices.Count; texturedBatch3D.QueueQuad(p, p2, p3, p4, new Vector2(0f, 0f), new Vector2(1f, 0f), new Vector2(1f, 1f), new Vector2(0f, 1f), Color.White); texturedBatch3D.TransformTriangles(camera.ViewMatrix, count); } if (!camera.Eye.HasValue && !camera.UsesMovementControls && !IsSightsVisible && (SettingsManager.LookControlMode == LookControlMode.SplitTouch || !m_componentPlayer.ComponentInput.IsControlledByTouch)) { Subtexture subtexture = ContentManager.Get <Subtexture>("Textures/Atlas/Crosshair"); float s2 = 1.25f; Vector3 v3 = camera.ViewPosition + camera.ViewDirection * 50f; Vector3 vector2 = Vector3.Normalize(Vector3.Cross(camera.ViewDirection, Vector3.UnitY)); Vector3 v4 = Vector3.Normalize(Vector3.Cross(camera.ViewDirection, vector2)); Vector3 p5 = v3 + s2 * (-vector2 - v4); Vector3 p6 = v3 + s2 * (vector2 - v4); Vector3 p7 = v3 + s2 * (vector2 + v4); Vector3 p8 = v3 + s2 * (-vector2 + v4); TexturedBatch3D texturedBatch3D2 = m_primitivesRenderer3D.TexturedBatch(subtexture.Texture, useAlphaTest: false, 0, DepthStencilState.None); int count2 = texturedBatch3D2.TriangleVertices.Count; texturedBatch3D2.QueueQuad(p5, p6, p7, p8, new Vector2(subtexture.TopLeft.X, subtexture.TopLeft.Y), new Vector2(subtexture.BottomRight.X, subtexture.TopLeft.Y), new Vector2(subtexture.BottomRight.X, subtexture.BottomRight.Y), new Vector2(subtexture.TopLeft.X, subtexture.BottomRight.Y), Color.White); texturedBatch3D2.TransformTriangles(camera.ViewMatrix, count2); } } m_primitivesRenderer2D.Flush(); m_primitivesRenderer3D.Flush(camera.ProjectionMatrix); }
public static void DrawFlatBlock(PrimitivesRenderer3D primitivesRenderer, int value, float size, ref Matrix matrix, Texture2D texture, Color color, bool isEmissive, DrawBlockEnvironmentData environmentData) { environmentData = (environmentData ?? m_defaultEnvironmentData); if (!isEmissive) { float s = LightingManager.LightIntensityByLightValue[environmentData.Light]; color = Color.MultiplyColorOnly(color, s); } Vector3 translation = matrix.Translation; Vector3 vector; Vector3 v; if (environmentData.BillboardDirection.HasValue) { vector = Vector3.Normalize(Vector3.Cross(environmentData.BillboardDirection.Value, Vector3.UnitY)); v = -Vector3.Normalize(Vector3.Cross(environmentData.BillboardDirection.Value, vector)); } else { vector = matrix.Right; v = matrix.Up; } Vector3 v2 = translation + 0.85f * size * (-vector - v); Vector3 v3 = translation + 0.85f * size * (vector - v); Vector3 v4 = translation + 0.85f * size * (-vector + v); Vector3 v5 = translation + 0.85f * size * (vector + v); if (environmentData.ViewProjectionMatrix.HasValue) { Matrix m = environmentData.ViewProjectionMatrix.Value; Vector3.Transform(ref v2, ref m, out v2); Vector3.Transform(ref v3, ref m, out v3); Vector3.Transform(ref v4, ref m, out v4); Vector3.Transform(ref v5, ref m, out v5); } int num = Terrain.ExtractContents(value); Block block = Blocks[num]; Vector4 vector2; if (texture != null) { vector2 = new Vector4(0f, 0f, 1f, 1f); } else { texture = ((environmentData.SubsystemTerrain != null) ? environmentData.SubsystemTerrain.SubsystemAnimatedTextures.AnimatedBlocksTexture : BlocksTexturesManager.DefaultBlocksTexture); vector2 = m_slotTexCoords[block.GetFaceTextureSlot(-1, value)]; } TexturedBatch3D texturedBatch3D = primitivesRenderer.TexturedBatch(texture, useAlphaTest: true, 0, null, RasterizerState.CullCounterClockwiseScissor, null, SamplerState.PointClamp); texturedBatch3D.QueueQuad(v2, v4, v5, v3, new Vector2(vector2.X, vector2.W), new Vector2(vector2.X, vector2.Y), new Vector2(vector2.Z, vector2.Y), new Vector2(vector2.Z, vector2.W), color); if (!environmentData.BillboardDirection.HasValue) { texturedBatch3D.QueueQuad(v2, v3, v5, v4, new Vector2(vector2.X, vector2.W), new Vector2(vector2.Z, vector2.W), new Vector2(vector2.Z, vector2.Y), new Vector2(vector2.X, vector2.Y), color); } }
public FengliAnimate() { Model model = ContentManager.Get <Model>("Mekiasm/Models/风力发电机"); Texture2D texture = ContentManager.Get <Texture2D>("Mekiasm/Textures/风力发电机"); for (int i = 0; i < eles.Length; i++) { Matrix matrix = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh(eles[i]).ParentBone); blockMesh.AppendModelMeshPart(model.FindMesh(eles[i]).MeshParts[0], matrix, false, false, false, false, Color.White); } texturedBatch3D = primitives.TexturedBatch(texture, false, 0, DepthStencilState.DepthWrite, RasterizerState.CullCounterClockwiseScissor, BlendState.Opaque); }
public static List <int> normalpos = new List <int>(); //位置面修正 public static void DrawCubeBlock(PrimitivesRenderer3D primitivesRenderer, int value, Vector3 size, ref Matrix matrix, Color color, Color topColor, DrawBlockEnvironmentData environmentData) { TexturedBatch3D texturedBatch3D = primitivesRenderer.TexturedBatch(texture, useAlphaTest: true, 0, null, RasterizerState.CullCounterClockwiseScissor, null, SamplerState.PointClamp); float s = LightingManager.LightIntensityByLightValue[environmentData.Light];//光强 color = Color.MultiplyColorOnly(color, s); topColor = Color.MultiplyColorOnly(topColor, s); Vector3 translation = matrix.Translation; Vector3 vector = matrix.Right * size.X; Vector3 v = matrix.Up * size.Y; Vector3 v2 = matrix.Forward * size.Z; Vector3 v3 = translation + 0.5f * (-vector - v - v2); Vector3 v4 = translation + 0.5f * (vector - v - v2); Vector3 v5 = translation + 0.5f * (-vector + v - v2); Vector3 v6 = translation + 0.5f * (vector + v - v2); Vector3 v7 = translation + 0.5f * (-vector - v + v2); Vector3 v8 = translation + 0.5f * (vector - v + v2); Vector3 v9 = translation + 0.5f * (-vector + v + v2); Vector3 v10 = translation + 0.5f * (vector + v + v2); if (environmentData.ViewProjectionMatrix.HasValue) { Matrix m = environmentData.ViewProjectionMatrix.Value; Vector3.Transform(ref v3, ref m, out v3); Vector3.Transform(ref v4, ref m, out v4); Vector3.Transform(ref v5, ref m, out v5); Vector3.Transform(ref v6, ref m, out v6); Vector3.Transform(ref v7, ref m, out v7); Vector3.Transform(ref v8, ref m, out v8); Vector3.Transform(ref v9, ref m, out v9); Vector3.Transform(ref v10, ref m, out v10); } Block block = BlocksManager.Blocks[Terrain.ExtractContents(value)]; Vector4 vector2 = m_slotTexCoords[block.GetFaceTextureSlot(0, value)]; texturedBatch3D.QueueQuad(color: Color.MultiplyColorOnly(color, LightingManager.CalculateLighting(-matrix.Forward)), p1: v3, p2: v5, p3: v6, p4: v4, texCoord1: new Vector2(vector2.X, vector2.W), texCoord2: new Vector2(vector2.X, vector2.Y), texCoord3: new Vector2(vector2.Z, vector2.Y), texCoord4: new Vector2(vector2.Z, vector2.W)); Vector4 vector3 = m_slotTexCoords[block.GetFaceTextureSlot(2, value)]; texturedBatch3D.QueueQuad(color: Color.MultiplyColorOnly(color, LightingManager.CalculateLighting(matrix.Forward)), p1: v7, p2: v8, p3: v10, p4: v9, texCoord1: new Vector2(vector3.Z, vector3.W), texCoord2: new Vector2(vector3.X, vector3.W), texCoord3: new Vector2(vector3.X, vector3.Y), texCoord4: new Vector2(vector3.Z, vector3.Y)); Vector4 vector4 = m_slotTexCoords[block.GetFaceTextureSlot(5, value)]; texturedBatch3D.QueueQuad(color: Color.MultiplyColorOnly(color, LightingManager.CalculateLighting(-matrix.Up)), p1: v3, p2: v4, p3: v8, p4: v7, texCoord1: new Vector2(vector4.X, vector4.Y), texCoord2: new Vector2(vector4.Z, vector4.Y), texCoord3: new Vector2(vector4.Z, vector4.W), texCoord4: new Vector2(vector4.X, vector4.W)); Vector4 vector5 = m_slotTexCoords[block.GetFaceTextureSlot(4, value)]; texturedBatch3D.QueueQuad(color: Color.MultiplyColorOnly(topColor, LightingManager.CalculateLighting(matrix.Up)), p1: v5, p2: v9, p3: v10, p4: v6, texCoord1: new Vector2(vector5.X, vector5.W), texCoord2: new Vector2(vector5.X, vector5.Y), texCoord3: new Vector2(vector5.Z, vector5.Y), texCoord4: new Vector2(vector5.Z, vector5.W)); Vector4 vector6 = m_slotTexCoords[block.GetFaceTextureSlot(1, value)]; texturedBatch3D.QueueQuad(color: Color.MultiplyColorOnly(color, LightingManager.CalculateLighting(-matrix.Right)), p1: v3, p2: v7, p3: v9, p4: v5, texCoord1: new Vector2(vector6.Z, vector6.W), texCoord2: new Vector2(vector6.X, vector6.W), texCoord3: new Vector2(vector6.X, vector6.Y), texCoord4: new Vector2(vector6.Z, vector6.Y)); Vector4 vector7 = m_slotTexCoords[block.GetFaceTextureSlot(3, value)]; texturedBatch3D.QueueQuad(color: Color.MultiplyColorOnly(color, LightingManager.CalculateLighting(matrix.Right)), p1: v4, p2: v6, p3: v10, p4: v8, texCoord1: new Vector2(vector7.X, vector7.W), texCoord2: new Vector2(vector7.X, vector7.Y), texCoord3: new Vector2(vector7.Z, vector7.Y), texCoord4: new Vector2(vector7.Z, vector7.W)); }
public override void Load(ValuesDictionary valuesDictionary) { m_subsystemTerrain = base.Project.FindSubsystem <SubsystemTerrain>(throwOnError: true); m_batch = m_primitivesRenderer.TexturedBatch(ContentManager.Get <Texture2D>("Textures/Shadow"), useAlphaTest: false, 0, DepthStencilState.DepthRead, RasterizerState.CullCounterClockwiseScissor, BlendState.AlphaBlend, SamplerState.LinearClamp); }
public static void DrawMeshBlock(PrimitivesRenderer3D primitivesRenderer, BlockMesh blockMesh, Texture2D texture, Color color, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData) { environmentData = (environmentData ?? m_defaultEnvironmentData); float num = LightingManager.LightIntensityByLightValue[environmentData.Light]; Vector4 v = new Vector4(color); v.X *= num; v.Y *= num; v.Z *= num; bool flag = v == Vector4.One; TexturedBatch3D texturedBatch3D = primitivesRenderer.TexturedBatch(texture, useAlphaTest: true, 0, null, RasterizerState.CullCounterClockwiseScissor, null, SamplerState.PointClamp); bool flag2 = false; Matrix m = (!environmentData.ViewProjectionMatrix.HasValue) ? matrix : (matrix * environmentData.ViewProjectionMatrix.Value); if (size != 1f) { m = Matrix.CreateScale(size) * m; } if (m.M14 != 0f || m.M24 != 0f || m.M34 != 0f || m.M44 != 1f) { flag2 = true; } int count = blockMesh.Vertices.Count; BlockMeshVertex[] array = blockMesh.Vertices.Array; int count2 = blockMesh.Indices.Count; ushort[] array2 = blockMesh.Indices.Array; DynamicArray <VertexPositionColorTexture> triangleVertices = texturedBatch3D.TriangleVertices; int count3 = triangleVertices.Count; int count4 = triangleVertices.Count; triangleVertices.Count += count; for (int i = 0; i < count; i++) { BlockMeshVertex blockMeshVertex = array[i]; if (flag2) { Vector4 v2 = new Vector4(blockMeshVertex.Position, 1f); Vector4.Transform(ref v2, ref m, out v2); float num2 = 1f / v2.W; blockMeshVertex.Position = new Vector3(v2.X * num2, v2.Y * num2, v2.Z * num2); } else { Vector3.Transform(ref blockMeshVertex.Position, ref m, out blockMeshVertex.Position); } if (flag || blockMeshVertex.IsEmissive) { triangleVertices.Array[count4++] = new VertexPositionColorTexture(blockMeshVertex.Position, blockMeshVertex.Color, blockMeshVertex.TextureCoordinates); continue; } Color color2 = new Color((byte)((float)(int)blockMeshVertex.Color.R * v.X), (byte)((float)(int)blockMeshVertex.Color.G * v.Y), (byte)((float)(int)blockMeshVertex.Color.B * v.Z), (byte)((float)(int)blockMeshVertex.Color.A * v.W)); triangleVertices.Array[count4++] = new VertexPositionColorTexture(blockMeshVertex.Position, color2, blockMeshVertex.TextureCoordinates); } DynamicArray <ushort> triangleIndices = texturedBatch3D.TriangleIndices; int count5 = triangleIndices.Count; triangleIndices.Count += count2; for (int j = 0; j < count2; j++) { triangleIndices.Array[count5++] = (ushort)(count3 + array2[j]); } }
public static void DrawMeshBlock(PrimitivesRenderer3D primitivesRenderer, BlockMesh blockMesh, Texture2D texture, Color color, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData) { environmentData = environmentData ?? m_defaultEnvironmentData; var num1 = LightingManager.LightIntensityByLightValue[environmentData.Light]; var vector4 = new Vector4(color); vector4.X *= num1; vector4.Y *= num1; vector4.Z *= num1; var flag1 = vector4 == Vector4.One; var texturedBatch3D = primitivesRenderer.TexturedBatch(texture, true, 0, null, RasterizerState.CullCounterClockwiseScissor, null, SamplerState.PointClamp); var flag2 = false; var m = !environmentData.ViewProjectionMatrix.HasValue ? matrix : matrix * environmentData.ViewProjectionMatrix.Value; if (size != 1.0) { m = Matrix.CreateScale(size) * m; } flag2 |= m.M14 != 0.0 || m.M24 != 0.0 || m.M34 != 0.0 || m.M44 != 1.0; var count1 = blockMesh.Vertices.Count; var array1 = blockMesh.Vertices.Array; var count2 = blockMesh.Indices.Count; var array2 = blockMesh.Indices.Array; var triangleVertices = texturedBatch3D.TriangleVertices; var count3 = triangleVertices.Count; var count4 = triangleVertices.Count; triangleVertices.Count += count1; for (var index = 0; index < count1; ++index) { var blockMeshVertex = array1[index]; if (flag2) { var result = new Vector4(blockMeshVertex.Position, 1f); Vector4.Transform(ref result, ref m, out result); var num2 = 1f / result.W; blockMeshVertex.Position = new Vector3(result.X * num2, result.Y * num2, result.Z * num2); } else { Vector3.Transform(ref blockMeshVertex.Position, ref m, out blockMeshVertex.Position); } if (flag1 || blockMeshVertex.IsEmissive) { triangleVertices.Array[count4++] = new VertexPositionColorTexture(blockMeshVertex.Position, blockMeshVertex.Color, blockMeshVertex.TextureCoordinates); } else { var color1 = new Color((byte)(blockMeshVertex.Color.R * (double)vector4.X), (byte)(blockMeshVertex.Color.G * (double)vector4.Y), (byte)(blockMeshVertex.Color.B * (double)vector4.Z), (byte)(blockMeshVertex.Color.A * (double)vector4.W)); triangleVertices.Array[count4++] = new VertexPositionColorTexture(blockMeshVertex.Position, color1, blockMeshVertex.TextureCoordinates); } } var triangleIndices = texturedBatch3D.TriangleIndices; var count5 = triangleIndices.Count; triangleIndices.Count += count2; for (var index = 0; index < count2; ++index) { triangleIndices.Array[count5++] = (ushort)((uint)count3 + array2[index]); } }
public static void DrawFlatBlock(PrimitivesRenderer3D primitivesRenderer, int value, float size, ref Matrix matrix, Texture2D texture, Color color, bool isEmissive, DrawBlockEnvironmentData environmentData) { environmentData = environmentData ?? m_defaultEnvironmentData; if (!isEmissive) { color = Color.MultiplyColorOnly(color, LightingManager.LightIntensityByLightValue[environmentData.Light]); } var translation = matrix.Translation; Vector3 v2; Vector3 vector3; if (environmentData.BillboardDirection.HasValue) { v2 = Vector3.Normalize(Vector3.Cross(environmentData.BillboardDirection.Value, Vector3.UnitY)); vector3 = -Vector3.Normalize(Vector3.Cross(environmentData.BillboardDirection.Value, v2)); } else { v2 = matrix.Right; vector3 = matrix.Up; } var result1 = translation + 0.85f * size * (-v2 - vector3); var result2 = translation + 0.85f * size * (v2 - vector3); var result3 = translation + 0.85f * size * (-v2 + vector3); var result4 = translation + 0.85f * size * (v2 + vector3); if (environmentData.ViewProjectionMatrix.HasValue) { var m = environmentData.ViewProjectionMatrix.Value; Vector3.Transform(ref result1, ref m, out result1); Vector3.Transform(ref result2, ref m, out result2); Vector3.Transform(ref result3, ref m, out result3); Vector3.Transform(ref result4, ref m, out result4); } var block = Blocks[Terrain.ExtractContents(value)]; Vector4 vector4; if (texture == null) { texture = environmentData.SubsystemTerrain != null ? environmentData.SubsystemTerrain.SubsystemAnimatedTextures.AnimatedBlocksTexture : BlocksTexturesManager.DefaultBlocksTexture; vector4 = m_slotTexCoords[block.GetFaceTextureSlot(-1, value)]; } else { vector4 = new Vector4(0.0f, 0.0f, 1f, 1f); } var texturedBatch3D = primitivesRenderer.TexturedBatch(texture, true, 0, null, RasterizerState.CullCounterClockwiseScissor, null, SamplerState.PointClamp); texturedBatch3D.QueueQuad(result1, result3, result4, result2, new Vector2(vector4.X, vector4.W), new Vector2(vector4.X, vector4.Y), new Vector2(vector4.Z, vector4.Y), new Vector2(vector4.Z, vector4.W), color); if (environmentData.BillboardDirection.HasValue) { return; } texturedBatch3D.QueueQuad(result1, result2, result4, result3, new Vector2(vector4.X, vector4.W), new Vector2(vector4.Z, vector4.W), new Vector2(vector4.Z, vector4.Y), new Vector2(vector4.X, vector4.Y), color); }
public static void DrawCubeBlock(PrimitivesRenderer3D primitivesRenderer, int value, Vector3 size, ref Matrix matrix, Color color, Color topColor, DrawBlockEnvironmentData environmentData) { environmentData = environmentData ?? m_defaultEnvironmentData; var texture = environmentData.SubsystemTerrain != null ? environmentData.SubsystemTerrain.SubsystemAnimatedTextures.AnimatedBlocksTexture : BlocksTexturesManager.DefaultBlocksTexture; var texturedBatch3D = primitivesRenderer.TexturedBatch(texture, true, 0, null, RasterizerState.CullCounterClockwiseScissor, null, SamplerState.PointClamp); var s = LightingManager.LightIntensityByLightValue[environmentData.Light]; color = Color.MultiplyColorOnly(color, s); topColor = Color.MultiplyColorOnly(topColor, s); var translation = matrix.Translation; var vector3_1 = matrix.Right * size.X; var vector3_2 = matrix.Up * size.Y; var vector3_3 = matrix.Forward * size.Z; var result1 = translation + 0.5f * (-vector3_1 - vector3_2 - vector3_3); var result2 = translation + 0.5f * (vector3_1 - vector3_2 - vector3_3); var result3 = translation + 0.5f * (-vector3_1 + vector3_2 - vector3_3); var result4 = translation + 0.5f * (vector3_1 + vector3_2 - vector3_3); var result5 = translation + 0.5f * (-vector3_1 - vector3_2 + vector3_3); var result6 = translation + 0.5f * (vector3_1 - vector3_2 + vector3_3); var result7 = translation + 0.5f * (-vector3_1 + vector3_2 + vector3_3); var result8 = translation + 0.5f * (vector3_1 + vector3_2 + vector3_3); if (environmentData.ViewProjectionMatrix.HasValue) { var m = environmentData.ViewProjectionMatrix.Value; Vector3.Transform(ref result1, ref m, out result1); Vector3.Transform(ref result2, ref m, out result2); Vector3.Transform(ref result3, ref m, out result3); Vector3.Transform(ref result4, ref m, out result4); Vector3.Transform(ref result5, ref m, out result5); Vector3.Transform(ref result6, ref m, out result6); Vector3.Transform(ref result7, ref m, out result7); Vector3.Transform(ref result8, ref m, out result8); } var block = Blocks[Terrain.ExtractContents(value)]; var slotTexCoord1 = m_slotTexCoords[block.GetFaceTextureSlot(0, value)]; var color1 = Color.MultiplyColorOnly(color, LightingManager.CalculateLighting(-matrix.Forward)); texturedBatch3D.QueueQuad(result1, result3, result4, result2, new Vector2(slotTexCoord1.X, slotTexCoord1.W), new Vector2(slotTexCoord1.X, slotTexCoord1.Y), new Vector2(slotTexCoord1.Z, slotTexCoord1.Y), new Vector2(slotTexCoord1.Z, slotTexCoord1.W), color1); var slotTexCoord2 = m_slotTexCoords[block.GetFaceTextureSlot(2, value)]; var color2 = Color.MultiplyColorOnly(color, LightingManager.CalculateLighting(matrix.Forward)); texturedBatch3D.QueueQuad(result5, result6, result8, result7, new Vector2(slotTexCoord2.Z, slotTexCoord2.W), new Vector2(slotTexCoord2.X, slotTexCoord2.W), new Vector2(slotTexCoord2.X, slotTexCoord2.Y), new Vector2(slotTexCoord2.Z, slotTexCoord2.Y), color2); var slotTexCoord3 = m_slotTexCoords[block.GetFaceTextureSlot(5, value)]; var color3 = Color.MultiplyColorOnly(color, LightingManager.CalculateLighting(-matrix.Up)); texturedBatch3D.QueueQuad(result1, result2, result6, result5, new Vector2(slotTexCoord3.X, slotTexCoord3.Y), new Vector2(slotTexCoord3.Z, slotTexCoord3.Y), new Vector2(slotTexCoord3.Z, slotTexCoord3.W), new Vector2(slotTexCoord3.X, slotTexCoord3.W), color3); var slotTexCoord4 = m_slotTexCoords[block.GetFaceTextureSlot(4, value)]; var color4 = Color.MultiplyColorOnly(topColor, LightingManager.CalculateLighting(matrix.Up)); texturedBatch3D.QueueQuad(result3, result7, result8, result4, new Vector2(slotTexCoord4.X, slotTexCoord4.W), new Vector2(slotTexCoord4.X, slotTexCoord4.Y), new Vector2(slotTexCoord4.Z, slotTexCoord4.Y), new Vector2(slotTexCoord4.Z, slotTexCoord4.W), color4); var slotTexCoord5 = m_slotTexCoords[block.GetFaceTextureSlot(1, value)]; var color5 = Color.MultiplyColorOnly(color, LightingManager.CalculateLighting(-matrix.Right)); texturedBatch3D.QueueQuad(result1, result5, result7, result3, new Vector2(slotTexCoord5.Z, slotTexCoord5.W), new Vector2(slotTexCoord5.X, slotTexCoord5.W), new Vector2(slotTexCoord5.X, slotTexCoord5.Y), new Vector2(slotTexCoord5.Z, slotTexCoord5.Y), color5); var slotTexCoord6 = m_slotTexCoords[block.GetFaceTextureSlot(3, value)]; var color6 = Color.MultiplyColorOnly(color, LightingManager.CalculateLighting(matrix.Right)); texturedBatch3D.QueueQuad(result2, result4, result8, result6, new Vector2(slotTexCoord6.X, slotTexCoord6.W), new Vector2(slotTexCoord6.X, slotTexCoord6.Y), new Vector2(slotTexCoord6.Z, slotTexCoord6.Y), new Vector2(slotTexCoord6.Z, slotTexCoord6.W), color6); }
public static void DrawVrQuad() { QueueQuad(m_pr3.TexturedBatch(m_uiRenderTarget, useAlphaTest: false, 0, DepthStencilState.Default, RasterizerState.CullNoneScissor, BlendState.Opaque, SamplerState.LinearClamp), m_vrQuadMatrix.Translation, m_vrQuadMatrix.Right, m_vrQuadMatrix.Up, Color.White); }
public void DrawIceOverlay(Camera camera, float factor) { Vector2 viewportSize = camera.ViewportSize; float s = camera.Eye.HasValue ? 1.3f : 1f; float num = camera.Eye.HasValue ? MathUtils.Pow(factor, 0.4f) : factor; Vector2 v = camera.Eye.HasValue ? viewportSize : new Vector2(1f); float num2 = v.Length(); Point2 point = new Point2((int)MathUtils.Round(12f * viewportSize.X / viewportSize.Y), (int)MathUtils.Round(12f)); if (m_iceVertices == null || m_cellsCount != point) { m_cellsCount = point; m_random.Seed(0); m_iceVertices = new Vector2[(point.X + 1) * (point.Y + 1)]; for (int i = 0; i <= point.X; i++) { for (int j = 0; j <= point.Y; j++) { float num3 = i; float num4 = j; if (i != 0 && i != point.X) { num3 += m_random.Float(-0.4f, 0.4f); } if (j != 0 && j != point.Y) { num4 += m_random.Float(-0.4f, 0.4f); } float x = num3 / (float)point.X; float y = num4 / (float)point.Y; m_iceVertices[i + j * (point.X + 1)] = new Vector2(x, y); } } } Vector3 vector = Vector3.UnitX / camera.ProjectionMatrix.M11 * 2f * 0.2f * s; Vector3 vector2 = Vector3.UnitY / camera.ProjectionMatrix.M22 * 2f * 0.2f * s; Vector3 v2 = -0.2f * Vector3.UnitZ - 0.5f * (vector + vector2); if (!m_light.HasValue || Time.PeriodicEvent(0.05000000074505806, 0.0)) { m_light = (LightingManager.CalculateSmoothLight(m_subsystemTerrain, camera.ViewPosition) ?? m_light ?? 1f); } Color color = Color.MultiplyColorOnly(Color.White, m_light.Value); m_random.Seed(0); Texture2D texture = ContentManager.Get <Texture2D>("Textures/IceOverlay"); TexturedBatch3D texturedBatch3D = m_primitivesRenderer3D.TexturedBatch(texture, useAlphaTest: false, 0, DepthStencilState.None, RasterizerState.CullNoneScissor, BlendState.AlphaBlend, SamplerState.PointWrap); Vector2 v3 = new Vector2(viewportSize.X / viewportSize.Y, 1f); Vector2 vector3 = new Vector2(point.X - 1, point.Y - 1); for (int k = 0; k < point.X; k++) { for (int l = 0; l < point.Y; l++) { float num5 = (new Vector2((float)(2 * k) / vector3.X - 1f, (float)(2 * l) / vector3.Y - 1f) * v).Length() / num2; if (1f - num5 + m_random.Float(0f, 0.05f) < num) { Vector2 v4 = m_iceVertices[k + l * (point.X + 1)]; Vector2 v5 = m_iceVertices[k + 1 + l * (point.X + 1)]; Vector2 v6 = m_iceVertices[k + 1 + (l + 1) * (point.X + 1)]; Vector2 v7 = m_iceVertices[k + (l + 1) * (point.X + 1)]; Vector3 vector4 = v2 + v4.X * vector + v4.Y * vector2; Vector3 p = v2 + v5.X * vector + v5.Y * vector2; Vector3 vector5 = v2 + v6.X * vector + v6.Y * vector2; Vector3 p2 = v2 + v7.X * vector + v7.Y * vector2; Vector2 vector6 = v4 * v3; Vector2 texCoord = v5 * v3; Vector2 vector7 = v6 * v3; Vector2 texCoord2 = v7 * v3; texturedBatch3D.QueueTriangle(vector4, p, vector5, vector6, texCoord, vector7, color); texturedBatch3D.QueueTriangle(vector5, p2, vector4, vector7, texCoord2, vector6, color); } } } texturedBatch3D.Flush(camera.ProjectionMatrix); }