Exemplo n.º 1
0
        private static void DarknessColor(Camera camera, BufferPreset bufferPreset)
        {
            Color color = bufferPreset.darknessColor;

            if (color.a > 0)
            {
                Material material = Lighting2D.materials.GetAlphaBlend();
                material.SetColor("_TintColor", color);
                material.mainTexture = null;

                float cameraRotation = -LightingPosition.GetCameraRotation(camera);

                Universal.Texture.Draw(material, Vector2.zero, LightingRender2D.GetSize(camera), cameraRotation, 0);
            }
        }
Exemplo n.º 2
0
        private static void ShadowAlpha(Camera camera)
        {
            Color color = new Color(0, 0, 0, (1f - Lighting2D.DayLightingSettings.alpha));

            if (color.a > 0)
            {
                color.r = 1f;
                color.g = 1f;
                color.b = 1f;

                Material material = Lighting2D.materials.GetAlphaBlend();
                material.mainTexture = null;
                material.SetColor("_TintColor", color);

                Universal.Texture.Draw(material, Vector2.zero, LightingRender2D.GetSize(camera), camera.transform.eulerAngles.z, 0);
            }
        }
Exemplo n.º 3
0
    public void UpdatePosition()
    {
        Camera camera = mainBuffer.cameraSettings.GetCamera();

        if (camera == null)
        {
            return;
        }


        transform.position = LightingPosition.GetCameraPlanePosition(camera);
        transform.rotation = camera.transform.rotation;

        // Local scale, not great
        transform.localScale = LightingRender2D.GetSize(camera);

        // transform.localScale = LightingRender2D.GetSize(camera);
    }
Exemplo n.º 4
0
        static public void Draw(Light2D light, Camera camera)
        {
            if (light.Buffer == null)
            {
                return;
            }

            if (light.isActiveAndEnabled == false)
            {
                return;
            }

            if (light.InAnyCamera() == false)
            {
                return;
            }

            Vector2 pos  = LightingPosition.GetPosition2D(-camera.transform.position);
            Vector2 size = new Vector2(light.size, light.size);

            if (light.IsPixelPerfect())
            {
                size = LightingRender2D.GetSize(camera);
                pos  = Vector2.zero;
            }
            else
            {
                pos += light.transform2D.position;
            }

            Color lightColor = light.color;

            lightColor.a = light.color.a / 2;

            Material material = Lighting2D.materials.GetLight();

            material.mainTexture = light.Buffer.renderTexture.renderTexture;
            material.SetColor("_TintColor", lightColor);

            Rendering.Universal.Texture.Draw(material, pos, size, 0);
        }
Exemplo n.º 5
0
    public void UpdateLight(Light2D id, MeshMode meshMode)       // Camera
    {
        if (meshModeMaterial != meshMode.materials)
        {
            meshModeMaterial = meshMode.materials;

            ClearMaterial();
        }

        if (meshModeShader != meshMode.shader)
        {
            meshModeShader = meshMode.shader;

            ClearMaterial();
        }

        Material[] materials = GetMaterials();

        if (materials == null)
        {
            return;
        }

        if (id.IsPixelPerfect())
        {
            Camera camera = Camera.main;

            Vector2 cameraSize     = LightingRender2D.GetSize(camera);
            Vector2 cameraPosition = LightingPosition.GetPosition2D(-camera.transform.position);

            transform.position = new Vector3(cameraPosition.x, cameraPosition.y, id.transform.position.z);

            transform.localScale = new Vector3(cameraSize.x, cameraSize.y, 1);
        }
        else
        {
            transform.position = id.transform.position;

            transform.localScale = new Vector3(id.size, id.size, 1);
        }

        transform.rotation = Quaternion.Euler(0, 0, 0);
        // transform.rotation = id.transform.rotation; // only if rotation enabled

        if (id.Buffer != null && meshRenderer != null)
        {
            Color lightColor = id.color;
            lightColor.a = id.meshMode.alpha;

            for (int i = 0; i < materials.Length; i++)
            {
                if (materials[i] == null)
                {
                    continue;
                }

                materials[i].SetColor("_TintColor", lightColor);
                materials[i].color = lightColor;

                materials[i].mainTexture = id.Buffer.renderTexture.renderTexture;
            }

            id.meshMode.sortingLayer.ApplyToMeshRenderer(meshRenderer);

            meshRenderer.sharedMaterials = GetMaterials();

            meshRenderer.enabled = true;

            meshFilter.mesh = GetMeshLight();
        }
    }