Ejemplo n.º 1
0
        /// <summary>
        /// blah blah blah
        /// </summary>
        public void TestDeleteOrderMethod1()
        {
            Order  order  = new Order();
            Nigiri nigiri = new Nigiri();

            order.addToOrder(nigiri);
            order.deleteFromOrder(nigiri);
            Assert.AreEqual(0, order.sushis.Count);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// blah blah blah
        /// </summary>
        public void TestDeleteOrderMethod3()
        {
            Order  order   = new Order();
            Nigiri nigiri  = new Nigiri();
            Nigiri nigiri2 = new Nigiri();

            order.addToOrder(nigiri);
            order.addToOrder(nigiri2);

            order.addToOrder(new Uramaki());

            order.deleteAllFromOrder(nigiri);
            Assert.AreEqual(1, order.sushis.Count);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// blah blah blah
        /// </summary>
        public void TestDeleteOrderMethod2()
        {
            Order  order   = new Order();
            Nigiri nigiri  = new Nigiri();
            Nigiri nigiri2 = new Nigiri();

            order.addToOrder(nigiri);
            order.addToOrder(nigiri2);

            order.addToOrder(new Uramaki());

            order.deleteAllFromOrder(nigiri);
            Assert.AreEqual(typeof(Uramaki), order.sushis[0].GetType());
        }
Ejemplo n.º 4
0
    void Start()
    {
        nigiriRef = FindObjectOfType <Nigiri>();
        if (!nigiriRef)
        {
            Debug.Log("No Nigiri in Scene");
        }
#if UNITY_5_5_OR_NEWER
        if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.Direct3D11 || SystemInfo.graphicsDeviceType == GraphicsDeviceType.Direct3D12 ||
            SystemInfo.graphicsDeviceType == GraphicsDeviceType.Metal || SystemInfo.graphicsDeviceType == GraphicsDeviceType.PlayStation4 ||
            SystemInfo.graphicsDeviceType == GraphicsDeviceType.Vulkan || SystemInfo.graphicsDeviceType == GraphicsDeviceType.XboxOne)
        {
            _reversedZ = true;
        }
#endif

        _commandBuffer      = new CommandBuffer();
        _commandBuffer.name = "Light Command Buffer";

        _cascadeShadowCommandBuffer      = new CommandBuffer();
        _cascadeShadowCommandBuffer.name = "Dir Light Command Buffer";
        _cascadeShadowCommandBuffer.SetGlobalTexture("_CascadeShadowMapTexture", new UnityEngine.Rendering.RenderTargetIdentifier(UnityEngine.Rendering.BuiltinRenderTextureType.CurrentActive));

        _light = GetComponent <Light>();
        _light.RemoveAllCommandBuffers();
        if (_light.type == LightType.Directional)
        {
            _light.AddCommandBuffer(LightEvent.BeforeScreenspaceMask, _commandBuffer);
            _light.AddCommandBuffer(LightEvent.AfterShadowMap, _cascadeShadowCommandBuffer);
        }
        else
        {
            _light.AddCommandBuffer(LightEvent.AfterShadowMap, _commandBuffer);
        }

        Shader shader = Shader.Find("Nigiri_VolumeLight_VolumetricLight");
        if (shader == null)
        {
            throw new Exception("Critical Error: \"Sandbox/VolumetricLight\" shader is missing. Make sure it is included in \"Always Included Shaders\" in ProjectSettings/Graphics.");
        }
        _material = new Material(shader);
    }
Ejemplo n.º 5
0
    private void SetupDirectionalLight(Nigiri renderer, Matrix4x4 viewProj)
    {
        if (_commandBuffer == null)
        {
            Start();
        }

        _commandBuffer.Clear();

        int pass = 4;

        _material.SetPass(pass);

        if (Noise)
        {
            _material.EnableKeyword("NOISE");
        }
        else
        {
            _material.DisableKeyword("NOISE");
        }

        _material.SetVector("_LightDir", new Vector4(_light.transform.forward.x, _light.transform.forward.y, _light.transform.forward.z, 1.0f / (_light.range * _light.range)));
        _material.SetVector("_LightColor", _light.color * _light.intensity);
        _material.SetFloat("_MaxRayLength", MaxRayLength);

        if (_light.cookie == null)
        {
            _material.EnableKeyword("DIRECTIONAL");
            _material.DisableKeyword("DIRECTIONAL_COOKIE");
        }
        else
        {
            _material.EnableKeyword("DIRECTIONAL_COOKIE");
            _material.DisableKeyword("DIRECTIONAL");

            _material.SetTexture("_LightTexture0", _light.cookie);
        }

        Texture nullTexture = null;

        if (_light.shadows != LightShadows.None)
        {
            _material.EnableKeyword("SHADOWS_DEPTH");
            _commandBuffer.Blit(nullTexture, renderer.GetVolumeLightBuffer(), _material, pass);

            if (CustomRenderEvent != null)
            {
                CustomRenderEvent(renderer, this, _commandBuffer, viewProj);
            }
        }
        else
        {
            _material.DisableKeyword("SHADOWS_DEPTH");
            renderer.GlobalCommandBuffer.Blit(nullTexture, renderer.GetVolumeLightBuffer(), _material, pass);

            if (CustomRenderEvent != null)
            {
                CustomRenderEvent(renderer, this, renderer.GlobalCommandBuffer, viewProj);
            }
        }
    }
Ejemplo n.º 6
0
    private void SetupSpotLight(Nigiri renderer, Matrix4x4 viewProj)
    {
        _commandBuffer.Clear();

        int pass = 1;

        if (!IsCameraInSpotLightBounds())
        {
            pass = 3;
        }

        Mesh mesh = Nigiri.GetSpotLightMesh();

        float scale      = _light.range;
        float angleScale = Mathf.Tan((_light.spotAngle + 1) * 0.5f * Mathf.Deg2Rad) * _light.range;

        Matrix4x4 world = Matrix4x4.TRS(transform.position, transform.rotation, new Vector3(angleScale, angleScale, scale));

        Matrix4x4 view = Matrix4x4.TRS(_light.transform.position, _light.transform.rotation, Vector3.one).inverse;

        Matrix4x4 clip = Matrix4x4.TRS(new Vector3(0.5f, 0.5f, 0.0f), Quaternion.identity, new Vector3(-0.5f, -0.5f, 1.0f));
        Matrix4x4 proj = Matrix4x4.Perspective(_light.spotAngle, 1, 0, 1);

        _material.SetMatrix("_MyLightMatrix0", clip * proj * view);

        _material.SetMatrix("_WorldViewProj", viewProj * world);

        _material.SetVector("_LightPos", new Vector4(_light.transform.position.x, _light.transform.position.y, _light.transform.position.z, 1.0f / (_light.range * _light.range)));
        _material.SetVector("_LightColor", _light.color * _light.intensity);


        Vector3 apex = transform.position;
        Vector3 axis = transform.forward;
        // plane equation ax + by + cz + d = 0; precompute d here to lighten the shader
        Vector3 center = apex + axis * _light.range;
        float   d      = -Vector3.Dot(center, axis);

        // update material
        _material.SetFloat("_PlaneD", d);
        _material.SetFloat("_CosAngle", Mathf.Cos((_light.spotAngle + 1) * 0.5f * Mathf.Deg2Rad));

        _material.SetVector("_ConeApex", new Vector4(apex.x, apex.y, apex.z));
        _material.SetVector("_ConeAxis", new Vector4(axis.x, axis.y, axis.z));

        _material.EnableKeyword("SPOT");

        if (Noise)
        {
            _material.EnableKeyword("NOISE");
        }
        else
        {
            _material.DisableKeyword("NOISE");
        }

        if (_light.cookie == null)
        {
            _material.SetTexture("_LightTexture0", Nigiri.GetDefaultSpotCookie());
        }
        else
        {
            _material.SetTexture("_LightTexture0", _light.cookie);
        }

        bool forceShadowsOff = false;

        if ((_light.transform.position - Camera.current.transform.position).magnitude >= QualitySettings.shadowDistance)
        {
            forceShadowsOff = true;
        }

        if (_light.shadows != LightShadows.None && forceShadowsOff == false)
        {
            clip = Matrix4x4.TRS(new Vector3(0.5f, 0.5f, 0.5f), Quaternion.identity, new Vector3(0.5f, 0.5f, 0.5f));

            if (_reversedZ)
            {
                proj = Matrix4x4.Perspective(_light.spotAngle, 1, _light.range, _light.shadowNearPlane);
            }
            else
            {
                proj = Matrix4x4.Perspective(_light.spotAngle, 1, _light.shadowNearPlane, _light.range);
            }

            Matrix4x4 m = clip * proj;
            m[0, 2] *= -1;
            m[1, 2] *= -1;
            m[2, 2] *= -1;
            m[3, 2] *= -1;

            //view = _light.transform.worldToLocalMatrix;
            _material.SetMatrix("_MyWorld2Shadow", m * view);
            _material.SetMatrix("_WorldView", m * view);

            _material.EnableKeyword("SHADOWS_DEPTH");
            _commandBuffer.SetGlobalTexture("_ShadowMapTexture", BuiltinRenderTextureType.CurrentActive);
            _commandBuffer.SetRenderTarget(renderer.GetVolumeLightBuffer());

            _commandBuffer.DrawMesh(mesh, world, _material, 0, pass);

            if (CustomRenderEvent != null)
            {
                CustomRenderEvent(renderer, this, _commandBuffer, viewProj);
            }
        }
        else
        {
            _material.DisableKeyword("SHADOWS_DEPTH");
            renderer.GlobalCommandBuffer.DrawMesh(mesh, world, _material, 0, pass);

            if (CustomRenderEvent != null)
            {
                CustomRenderEvent(renderer, this, renderer.GlobalCommandBuffer, viewProj);
            }
        }
    }
Ejemplo n.º 7
0
    private void SetupPointLight(Nigiri renderer, Matrix4x4 viewProj)
    {
        if (_commandBuffer == null)
        {
            Start();
        }

        _commandBuffer.Clear();

        int pass = 0;

        if (!IsCameraInPointLightBounds())
        {
            pass = 2;
        }

        _material.SetPass(pass);

        Mesh mesh = Nigiri.GetPointLightMesh();

        float     scale = _light.range * 2.0f;
        Matrix4x4 world = Matrix4x4.TRS(transform.position, _light.transform.rotation, new Vector3(scale, scale, scale));

        _material.SetMatrix("_WorldViewProj", viewProj * world);
        _material.SetMatrix("_WorldView", Camera.current.worldToCameraMatrix * world);

        if (Noise)
        {
            _material.EnableKeyword("NOISE");
        }
        else
        {
            _material.DisableKeyword("NOISE");
        }

        _material.SetVector("_LightPos", new Vector4(_light.transform.position.x, _light.transform.position.y, _light.transform.position.z, 1.0f / (_light.range * _light.range)));
        _material.SetColor("_LightColor", _light.color * _light.intensity);

        if (_light.cookie == null)
        {
            _material.EnableKeyword("POINT");
            _material.DisableKeyword("POINT_COOKIE");
        }
        else
        {
            Matrix4x4 view = Matrix4x4.TRS(_light.transform.position, _light.transform.rotation, Vector3.one).inverse;
            _material.SetMatrix("_MyLightMatrix0", view);

            _material.EnableKeyword("POINT_COOKIE");
            _material.DisableKeyword("POINT");

            _material.SetTexture("_LightTexture0", _light.cookie);
        }

        bool forceShadowsOff = false;

        if ((_light.transform.position - Camera.current.transform.position).magnitude >= QualitySettings.shadowDistance)
        {
            forceShadowsOff = true;
        }

        if (_light.shadows != LightShadows.None && forceShadowsOff == false)
        {
            _material.EnableKeyword("SHADOWS_CUBE");
            _commandBuffer.SetGlobalTexture("_ShadowMapTexture", BuiltinRenderTextureType.CurrentActive);
            _commandBuffer.SetRenderTarget(renderer.GetVolumeLightBuffer());

            _commandBuffer.DrawMesh(mesh, world, _material, 0, pass);

            if (CustomRenderEvent != null)
            {
                CustomRenderEvent(renderer, this, _commandBuffer, viewProj);
            }
        }
        else
        {
            _material.DisableKeyword("SHADOWS_CUBE");
            renderer.GlobalCommandBuffer.DrawMesh(mesh, world, _material, 0, pass);

            if (CustomRenderEvent != null)
            {
                CustomRenderEvent(renderer, this, renderer.GlobalCommandBuffer, viewProj);
            }
        }
    }
Ejemplo n.º 8
0
    private void Nigiri_PreRenderEvent(Nigiri renderer, Matrix4x4 viewProj)
    {
        if (!nigiriRef)
        {
            nigiriRef = renderer;
        }
        if (thisQuality != quality)
        {
            SwitchQuality();
        }
        if (nigiriRef && nigiriQuality != nigiriRef.globalQuality && quality == rayMarchQuality.globalSetting)
        {
            SwitchQuality();
        }
        SetParamaters();
        // light was destroyed without deregistring, deregister now
        if (_light == null || _light.gameObject == null)
        {
            Nigiri.PreRenderEvent -= Nigiri_PreRenderEvent;
            return;
        }
        UpdateCamera(Camera.current, _material);
        //UpdatePosition();

        if (!_light.gameObject.activeInHierarchy || _light.enabled == false)
        {
            return;
        }

        _material.SetVector("_CameraForward", Camera.current.transform.forward);

        _material.SetInt("_SampleCount", SampleCount);
        _material.SetVector("_NoiseVelocity", new Vector4(NoiseVelocity.x, NoiseVelocity.y) * NoiseScale);
        _material.SetVector("_NoiseData", new Vector4(NoiseScale, NoiseIntensity, NoiseIntensityOffset));
        _material.SetVector("_MieG", new Vector4(1 - (MieG * MieG), 1 + (MieG * MieG), 2 * MieG, 1.0f / (4.0f * Mathf.PI)));
        _material.SetVector("_VolumetricLight", new Vector4(ScatteringCoef, ExtinctionCoef, _light.range, 1.0f - SkyboxExtinctionCoef));

        _material.SetTexture("_CameraDepthTexture", renderer.GetVolumeLightDepthBuffer());

        //if (renderer.Resolution == Nigiri.VolumtericResolution.Full)
        {
            //_material.SetFloat("_ZTest", (int)UnityEngine.Rendering.CompareFunction.LessEqual);
            //_material.DisableKeyword("MANUAL_ZTEST");
        }
        //else
        {
            _material.SetFloat("_ZTest", (int)UnityEngine.Rendering.CompareFunction.Always);
            // downsampled light buffer can't use native zbuffer for ztest, try to perform ztest in pixel shader to avoid ray marching for occulded geometry
            //_material.EnableKeyword("MANUAL_ZTEST");
        }

        if (HeightFog)
        {
            _material.EnableKeyword("HEIGHT_FOG");

            _material.SetVector("_HeightFog", new Vector4(GroundLevel, HeightScale));
        }
        else
        {
            _material.DisableKeyword("HEIGHT_FOG");
        }

        if (_light.type == LightType.Point)
        {
            SetupPointLight(renderer, viewProj);
        }
        else if (_light.type == LightType.Spot)
        {
            SetupSpotLight(renderer, viewProj);
        }
        else if (_light.type == LightType.Directional)
        {
            SetupDirectionalLight(renderer, viewProj);
        }
    }