Beispiel #1
0
        void Update()
        {
            if (!_initialized)
            {
                InitializeResources();
            }

            if (IsAlmostZero(bend) &&
                IsAlmostZero(twist) &&
                IsAlmostZero(spike) &&
                IsAlmostZero(voxel))
            {
                _splitTimer -= Time.deltaTime;
            }
            else
            {
                _splitTimer = 1;
            }

            if (_splitTimer > 0)
            {
                var bendAngle = _randomSeed * Mathf.PI * 200;
                var bendAxes  = new Vector4(
                    Mathf.Cos(bendAngle), -Mathf.Sin(bendAngle),
                    Mathf.Sin(bendAngle), Mathf.Cos(bendAngle)
                    );
                var bendDist = 1 / (bend + 1e-6f);

                _mpblock.
                Property("_Bend", bendDist).
                Property("_Axes", bendAxes).
                Property("_Twist", twist * 3).
                Property("_Spike", spike * 2, 0.003f, _randomSeed).
                Property("_Voxel", 4 / (voxel + 1e-6f));

                var matrix = transformMatrix;

                Graphics.DrawMesh(
                    _splitMesh1, matrix,
                    _splitMaterial, gameObject.layer, null, 0, _mpblock
                    );

                Graphics.DrawMesh(
                    _splitMesh2, matrix,
                    _splitMaterial, gameObject.layer, null, 0, _mpblock
                    );
            }
            else
            {
                _mpblock.
                Property("_Highlight", highlight).
                Property("_Cutout", cutout);

                Graphics.DrawMesh(
                    _unifiedMesh, transformMatrix,
                    _unifiedMaterial, gameObject.layer, null, 0, _mpblock
                    );
            }
        }
Beispiel #2
0
 void ChangeMaterial()
 {
     _materialProperties.
     Property("_Color", RandomColor()).
     Property("_Glossiness", Random.value).
     Property("_Metallic", Random.value);
 }
Beispiel #3
0
        void Update()
        {
            if (_surfaceMaterial == null)
            {
                OnEnable();                           // delayed initialization
            }
            _noiseOffset += Vector3.forward * (_noiseMotion * Time.deltaTime);

            _surfaceMaterial
            .Property("_Color", _color)
            .Property("_MainTex", _albedoTexture)
            .Property("_TexScale", _textureScale)
            .Property("_Metallic", _metallic)
            .Property("_Glossiness", _smoothness)
            .Property("_NormalTex", _normalTexture)
            .Property("_NormalScale", _normalScale);

            _lineMaterial.Property("_Color", _lineColor);

            _materialProps
            .Property("_ScaleParams", _radius, _scale)
            .Property("_RandomParams", _randomness, _randomSeed)
            .Property("_NoiseParams", _noiseAmplitude, _noiseFrequency)
            .Property("_NoiseOffs", _noiseOffset + RandomNoiseOffset);

            Graphics.DrawMesh(
                _mesh.sharedMesh, transform.localToWorldMatrix,
                _surfaceMaterial, 0, null, 0, _materialProps);

            Graphics.DrawMesh(
                _mesh.sharedMesh, transform.localToWorldMatrix,
                _lineMaterial, 0, null, 1, _materialProps);
        }
Beispiel #4
0
        void Update()
        {
            // State update
            var spikeDir = new Vector3(1, 0.5f, 0.2f).normalized;
            var maskDir  = new Vector3(-0.3f, -1, -0.1f).normalized;

            _spikeOffset += spikeDir * (_spikeMotion * Time.deltaTime);
            _maskOffset  += maskDir * (_maskMotion * Time.deltaTime);

            // Material setup
            _shaderArgs.
            Property("_Cutoff", _cutoff).
            Property("_Shrink", _shrink).
            Property("_SpikeOffset", _spikeOffset).
            Property("_SpikeAmplitude", _spikeAmplitude).
            Property("_SpikeExponent", _spikeExponent).
            Property("_SpikeFrequency", _spikeFrequency).
            Property("_MaskOffset", _maskOffset).
            Property("_MaskFrequency", _maskFrequency);

            _surfaceMaterial.
            Property("_Color", _surfaceColor).
            Property("_BackColor", _backSurfaceColor).
            Property("_Glossiness", _smoothness).
            Property("_Metallic", _metallic).
            Property("_EmissionColor", _emission);

            _lineMaterial.color = _lineColor;

            // Draw call
            var matrix = transform.localToWorldMatrix;
            var scale1 = Matrix4x4.Scale(Vector3.one * (_radius - 0.02f));
            var scale2 = Matrix4x4.Scale(Vector3.one * _radius);

            if (_cutoff < 0.999f)
            {
                Graphics.DrawMesh(
                    _mesh.sharedMesh, matrix * scale1, _surfaceMaterial,
                    gameObject.layer, null, 0, _shaderArgs
                    );
            }

            if (_lineColor.a > 0.001f)
            {
                Graphics.DrawMesh(
                    _mesh.sharedMesh, matrix * scale2, _lineMaterial,
                    gameObject.layer, null, 1, _shaderArgs
                    );
            }
        }