Пример #1
0
        private void Update()
        {
            _materialPropertyBlock.SetFloat("_PolarBlend", slider.value);

            for (var i = 0; i < Count * Count; ++i)
            {
                var t = Time.time * 3.0f;

                _colors[i] = new Vector4(
                    Mathf.Sin((i + t) * 0.7f) * 0.5f,
                    Mathf.Sin((i + t) * 1.3f) * 0.5f,
                    Mathf.Sin((i + t) * 2.3f) * 0.5f,
                    0
                    );
            }
            _materialPropertyBlock.SetVectorArray(ColorProperty, _colors);

            Graphics.DrawMeshInstanced(_mesh, 0, surfaceMaterial, _matrices, _materialPropertyBlock);

            for (var i = 0; i < Count * Count; ++i)
            {
                var t = Time.time * 3.0f;

                _colors[i] = new Vector4(
                    Mathf.Sin((i + t) * 0.7f) * 0.5f + 0.5f,
                    Mathf.Sin((i + t) * 1.3f) * 0.5f + 0.5f,
                    Mathf.Sin((i + t) * 2.3f) * 0.5f + 0.5f,
                    0
                    );
            }
            _materialPropertyBlock.SetVectorArray(ColorProperty, _colors);

            Graphics.DrawMeshInstanced(_mesh, 1, lineMaterial, _matrices, _materialPropertyBlock);
        }
Пример #2
0
    private void HitPlasmaWall(Transform bullet)
    {
        if (!bulletPosList.Contains(bullet))
        {
            bulletPosList.Add(bullet);
        }


        for (int i = 0; i < bulletPosList.Count; i++)
        {
            if (bulletPosList[i] == bullet)
            {
                _vectorPositions[i] = new Vector4(bulletPosList[i].position.x,
                                                  bulletPosList[i].position.y,
                                                  bulletPosList[i].position.z, 0);
            }
        }

        _mpb.SetVectorArray("myObjects", _vectorPositions);
        _rend.SetPropertyBlock(_mpb);

        for (int i = 0; i < bulletPosList.Count; i++)
        {
            StartCoroutine(FadeAfter(i));
        }
    }
Пример #3
0
    private void OnValidate()
    {
        if (count <= 0)
        {
            count = 1;
        }


        if (block == null)
        {
            block = new MaterialPropertyBlock();
        }

        block.Clear();
        colorList.Clear();
        offList.Clear();
        cutOffList.Clear();
        matrix = new Matrix4x4[count];
        for (int i = 0; i < count; i++)
        {
            matrix[i] = Matrix4x4.TRS((transform.position + Random.insideUnitSphere * range), Quaternion.identity, Vector3.one);
            colorList.Add(new Vector4(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f), 1));
            offList.Add(new Vector4(Random.Range(0.1f, 5f), Random.Range(0.1f, 5f), Random.Range(0.1f, 1f), Random.Range(0.1f, 1f)));
            cutOffList.Add(Random.Range(0.0f, 1));
        }
        block.SetFloatArray(cutOff, cutOffList);
        block.SetVectorArray(maintexST, offList);
        block.SetVectorArray(baseColorId, colorList);
    }
Пример #4
0
    public void Draw()
    {
        var ListEnum = Lod.GetEnumerator();
        int n        = 0;

        Mpb.Clear();

        while (ListEnum.MoveNext())
        {
            _matrices[n] = ListEnum.Current.LocalToWorldMatrix;
            _colors[n]   = ListEnum.Current.ArmyColor;
            _wreckage[n] = ListEnum.Current.IsWreckage;
            n++;

            if (n == MaxInstancingCount)
            {
                Mpb.SetVectorArray("_Color", _colors);
                Mpb.SetFloatArray("_Wreckage", _wreckage);
                Graphics.DrawMeshInstanced(BP.LODs[0].Mesh, 0, BP.LODs[0].Mat, _matrices, n, Mpb, ShadowCasting);
                //Graphics.DrawMeshInstancedIndirect(SharedMesh, 0, SharedMaterial, , null, 0, null, ShadowCasting);
                n = 0;
                Mpb.Clear();
            }
        }

        if (n > 0)
        {
            Mpb.SetVectorArray("_Color", _colors);
            Mpb.SetFloatArray("_Wreckage", _wreckage);
            Graphics.DrawMeshInstanced(BP.LODs[0].Mesh, 0, BP.LODs[0].Mat, _matrices, n, Mpb, ShadowCasting);
        }
    }
Пример #5
0
    public void HitPlasmaWall(Vector3 hitPos)
    {
        if (!hitPositionsList.Contains(hitPos))
        {
            hitPositionsList.Add(hitPos);
        }


        for (int i = 0; i < hitPositionsList.Count; i++)
        {
            if (hitPositionsList[i] == hitPos)
            {
                _vectorPositions.Add(new Vector4(hitPositionsList[i].x,
                                                 hitPositionsList[i].y,
                                                 hitPositionsList[i].z, 0));
            }
        }

        _mpb.SetVectorArray("myObjects", _vectorPositions.ToArray());
        _rend.SetPropertyBlock(_mpb);

        for (int i = 0; i < hitPositionsList.Count; i++)
        {
            StartCoroutine(FadeAfter(i));
        }
    }
Пример #6
0
 public void LoadInto([NotNull] MaterialPropertyBlock properties, int layerInputStartId, int layerInputExtentId, int layerOutputStartId, int layerOutputEndId)
 {
     properties.SetVectorArray(layerInputStartId, LayerInputStart);
     properties.SetVectorArray(layerInputExtentId, LayerInputExtent);
     properties.SetVectorArray(layerOutputStartId, LayerOutputStart);
     properties.SetVectorArray(layerOutputEndId, LayerOutputEnd);
 }
Пример #7
0
    //Vector4[] originalSensorsPos = new Vector4[VertExmotion.MAX_SENSOR];

    void LateUpdate()
    {
        if (m_reference == null)
        {
            return;
        }

        if (m_meshRenderer == null && m_skinMeshRenderer == null)
        {
            return;
        }

        //get shader properties from original
        m_matPropBlk = m_reference.m_matPropBlk;

        if (newSensorsPos.Length != m_reference.m_shaderSensorPos.Length)
        {
            newSensorsPos = new Vector4[m_reference.m_shaderSensorPos.Length];
        }


        //for (int i=0; i<VertExmotion.MAX_SENSOR; ++i)
        for (int i = 0; i < m_reference.m_shaderSensorPos.Length; ++i)
        {
            /*
             * //unity 5.3
             * Vector3 sensorPos = m_matPropBlk.GetVector( m_reference.m_shaderParamNames[ "_SensorPosition" ][i] );
             * m_matPropBlk.SetVector ( m_reference.m_shaderParamNames[ "_SensorPosition" ][i],  transform.TransformPoint( m_reference.transform.InverseTransformPoint( sensorPos )) );
             * originalSensorsPos[i] = sensorPos;
             */

            //unity 5.4
            newSensorsPos[i] = transform.TransformPoint(m_reference.transform.InverseTransformPoint(m_reference.m_shaderSensorPos[i]));
        }
        m_matPropBlk.SetVectorArray("_SensorPosition", newSensorsPos);

        m_meshRenderer.SetPropertyBlock(m_reference.m_matPropBlk);

        //restore values of the original
        m_matPropBlk.SetVectorArray("_SensorPosition", m_reference.m_shaderSensorPos);

        /*
         * //unity 5.3
         *      for (int i=0; i<VertExmotion.MAX_SENSOR; ++i)
         *              m_matPropBlk.SetVector ( m_reference.m_shaderParamNames[ "_SensorPosition" ][i] , originalSensorsPos[i] );
         */

        if (m_copyDeltaPosition)
        {
            transform.position += m_reference.transform.position - m_referenceLastPosition;
        }

        if (m_copyRotation)
        {
            transform.rotation = m_reference.transform.rotation;
        }

        m_referenceLastPosition = m_reference.transform.position;
    }
Пример #8
0
        public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData)
        {
            Camera camera = renderingData.cameraData.camera;

            LookingGlassUtil.SetupCameraInfo(camera, perCameraInfo.fov, perCameraInfo.size, perCameraInfo.nearClipFactor, perCameraInfo.farClipFactor);

            // clear Tile Texture
            commandBuffer.SetRenderTarget(dstTiledTexture);
            commandBuffer.ClearRenderTarget(true, true, Color.black);
            context.ExecuteCommandBuffer(commandBuffer);

            // setup
            CalculateVpMatrixOffsetsAndTileRects(camera);
            Shader.SetGlobalVector("LookingQuiltSize", new Vector4(dstTiledTexture.width, dstTiledTexture.height, 0, 0));

            MaterialPropertyBlock materialPropertyBlock = new MaterialPropertyBlock();

            materialPropertyBlock.SetVectorArray("LookingVPOffset", m_VpOffsetParam);
            materialPropertyBlock.SetVectorArray("LookingScreenRect", m_ScreenRectParam);
            DebugSetup(camera, materialPropertyBlock);


            Shader.EnableKeyword(LgInstancingShaderKeyword);
            // todo メッシュ一覧取得周りの仕組みつくる

            var meshFilters = Resources.FindObjectsOfTypeAll <MeshFilter>();

            foreach (var meshFilter in meshFilters)
            {
                var meshRenderer = meshFilter.GetComponent <MeshRenderer>();
                var mesh         = meshFilter.sharedMesh;
                if (mesh == null)
                {
                    continue;
                }
                if (meshRenderer == null || meshRenderer.sharedMaterial == null)
                {
                    continue;
                }
                var material = meshRenderer.sharedMaterial;

                if (!material.enableInstancing)
                {
                    continue;
                }

                var matrix = meshFilter.transform.localToWorldMatrix;
                this.CalculateInstancingMatrix(ref matrix);


                commandBuffer.DrawMeshInstanced(mesh, 0, material, 0, this.m_RenderMatrix,
                                                m_RenderMatrix.Length, materialPropertyBlock);
            }
            context.ExecuteCommandBuffer(commandBuffer);
            context.Submit();
            commandBuffer.Clear();

            Shader.DisableKeyword(LgInstancingShaderKeyword);
        }
Пример #9
0
    void Update()
    {
        MeshHeight = mMeshFilter.sharedMesh.bounds.size.y;

        WindDirection.Normalize();
        var perpendicularWindDirection = new Vector3(WindDirection.z, 0.0f, -WindDirection.x);
        var modulation = WindDirectionModulationStrength * Mathf.Sin(Time.time * WindDirectionModulationTimeScale);

        WindDirectionModulated = WindDirection + perpendicularWindDirection * modulation;
        WindDirectionModulated.Normalize();

        CurTime             += Time.deltaTime;
        RollingWindOffset.x -= WindDirectionModulated.x * (WindScrollSpeed * Time.deltaTime);
        RollingWindOffset.y -= WindDirectionModulated.z * (WindScrollSpeed * Time.deltaTime);

        for (int i = 0; i < Buckets.Count; ++i)
        {
            BatchBucket bucket = Buckets[i];

            propertyBlock.SetVectorArray("_Color", bucket.ColorArray);
            propertyBlock.SetVectorArray("_InstancePosition", bucket.PositionArray);

            propertyBlock.SetFloat("_CurTime", CurTime);
            propertyBlock.SetFloat("_DisplacementStrength", DisplacementStrength);
            propertyBlock.SetFloat("_Flexibility", Flexibility);
            propertyBlock.SetFloat("_WindStrength", WindStrength);
            propertyBlock.SetVector("_WindDirection", WindDirectionModulated);
            propertyBlock.SetFloat("_RollingWindPositionScale", RollingWindPositionScale);
            propertyBlock.SetTexture("_RollingWindTex", RollingWindTex);
            propertyBlock.SetVector("_RollingWindOffset", RollingWindOffset);
            propertyBlock.SetFloat("_MeshHeight", MeshHeight);
            propertyBlock.SetVector("_Scale", Scale);
            propertyBlock.SetTexture("_Displacement", DisplacementMap.Get().rt);
            propertyBlock.SetColor("_FreezeColor", FreezeColor);
            propertyBlock.SetFloat("_FreezeFactor", FreezeFactor);

            var grassBounds = new Vector4();
            grassBounds.x = targetBounds.center.x - targetBounds.extents.x;
            grassBounds.y = targetBounds.center.z - targetBounds.extents.z;
            grassBounds.z = targetBounds.size.x;
            grassBounds.w = targetBounds.size.z;
            propertyBlock.SetVector("_Bounds", grassBounds);

            Graphics.DrawMeshInstanced(
                mMeshFilter.sharedMesh,
                0,
                meshMaterial,
                bucket.MatrixArray,
                bucket.NumInstances,
                propertyBlock,
                UnityEngine.Rendering.ShadowCastingMode.On,
                true,
                GRASS_GEOMETRY_LAYER_MASK
                );
        }
    }
Пример #10
0
    private Vector4[] _uvs;// = new Vector4[MAX];


    void Start()
    {
        //モーションを10個くらいつくっとく
        //


        //motion
        int numMotion = 7;

        _motions = new SolitaireMotion[numMotion];
        for (int i = 0; i < numMotion; i++)
        {
            _motions[i]        = new SolitaireMotion();
            _motions[i]._limit = _bottomDistance;
            _motions[i].Init(_startPosSpace);
        }

        _propertyBlock = new MaterialPropertyBlock();
        _matrices      = new Matrix4x4[_count];
        _data          = new SolitaireData[_count];
        _colors        = new Vector4[_count];
        _randoms       = new Vector4[_count];
        _uvs           = new Vector4[_count];

        for (int i = 0; i < _count; i++)
        {
            _matrices[i] = Matrix4x4.identity;
            _data[i]     = new SolitaireData();//
            _data[i].rot = Quaternion.Euler(
                0, 0, 0
                );
            _randoms[i] = _data[i].random;
            _colors[i]  = new Vector4(
                1f,
                1f,
                1f,
                1f
                );

            _matrices[i].SetTRS(
                _data[i].pos,
                _data[i].rot,
                _data[i].scale
                );

            _uvs[i] = SolitaireUV.GetUV(0, 0, 4, 13);
            //_uvs[i] = SolitaireUV.GetUV2(0,0);
        }

        _mat.SetVectorArray("_Random", _randoms);
        _propertyBlock.SetVectorArray("_Uv", _uvs);
        _propertyBlock.SetVectorArray("_Color", _colors);

        //_Loop();
    }
Пример #11
0
    public void Draw()
    {
        if (Lod == null || Lod.Count == 0)
        {
            return;
        }

        if (BP.LODs[0].Mesh == null)
        {
            //Missing mesh or material, skip rendering
            Debug.LogWarning("Missing mesh for blueprint " + BP.CodeName, gameObject);
            return;
        }
        else if (BP.LODs[0].Mat == null)
        {
            Debug.LogWarning("Missing material for blueprint " + BP.CodeName, gameObject);
            return;
        }

        var ListEnum = Lod.GetEnumerator();
        int n        = 0;

        Mpb.Clear();


        while (ListEnum.MoveNext())
        {
            _matrices[n] = ListEnum.Current.LocalToWorldMatrix;
            _colors[n]   = ListEnum.Current.ArmyColor;
            _wreckage[n] = ListEnum.Current.IsWreckage;
            n++;

            if (n == MaxInstancingCount)
            {
                Mpb.SetVectorArray("_Color", _colors);
                Mpb.SetFloatArray("_Wreckage", _wreckage);
                Graphics.DrawMeshInstanced(BP.LODs[0].Mesh, 0, BP.LODs[0].Mat, _matrices, n, Mpb, ShadowCasting, true, 0, null, UnityEngine.Rendering.LightProbeUsage.Off, null);
                //Graphics.DrawMeshInstanced(UnitsInfo.Current.StrategicMesh, 0, BP.strategicMaterial, _matrices, n, Mpb, UnityEngine.Rendering.ShadowCastingMode.Off, false, 0, null, UnityEngine.Rendering.LightProbeUsage.Off, null);
                //Graphics.DrawMeshInstancedIndirect(SharedMesh, 0, SharedMaterial, , null, 0, null, ShadowCasting);
                n = 0;
                Mpb.Clear();
            }
        }

        if (n > 0)
        {
            Mpb.SetVectorArray("_Color", _colors);
            Mpb.SetFloatArray("_Wreckage", _wreckage);
            Graphics.DrawMeshInstanced(BP.LODs[0].Mesh, 0, BP.LODs[0].Mat, _matrices, n, Mpb, ShadowCasting, true, 0, null, UnityEngine.Rendering.LightProbeUsage.Off, null);
            //Graphics.DrawMeshInstanced(UnitsInfo.Current.StrategicMesh, 0, BP.strategicMaterial, _matrices, n, Mpb, UnityEngine.Rendering.ShadowCastingMode.Off, false, 0, null, UnityEngine.Rendering.LightProbeUsage.Off, null);
        }
    }
Пример #12
0
            public void Render()
            {
                if (boneCount == 0)
                {
                    return;
                }

                Material mat = material;

                mat.SetPass(0);

                MaterialPropertyBlock propertyBlock = new MaterialPropertyBlock();
                CommandBuffer         cb            = new CommandBuffer();

                Matrix4x4[] matrices = null;

                int chunkCount = RenderChunkCount(boneCount);

                for (int i = 0; i < chunkCount; ++i)
                {
                    cb.Clear();
                    matrices = GetRenderChunk(m_BoneMatrices, i);
                    propertyBlock.SetVectorArray("_Color", GetRenderChunk(m_BoneColors, i));

                    material.DisableKeyword("WIRE_ON");
                    cb.DrawMeshInstanced(mesh, (int)SubMeshType.BoneFaces, material, 0, matrices, matrices.Length, propertyBlock);
                    Graphics.ExecuteCommandBuffer(cb);

                    cb.Clear();
                    material.EnableKeyword("WIRE_ON");
                    cb.DrawMeshInstanced(mesh, (int)SubMeshType.BoneWire, material, 0, matrices, matrices.Length, propertyBlock);
                    Graphics.ExecuteCommandBuffer(cb);
                }

                if (boneLeafCount == 0)
                {
                    return;
                }

                chunkCount = RenderChunkCount(boneLeafCount);
                cb.Clear();
                material.EnableKeyword("WIRE_ON");

                for (int i = 0; i < chunkCount; ++i)
                {
                    matrices = GetRenderChunk(m_BoneLeafMatrices, i);
                    propertyBlock.SetVectorArray("_Color", GetRenderChunk(m_BoneLeafColors, i));
                    cb.DrawMeshInstanced(mesh, (int)SubMeshType.BoneLeafWire, material, 0, matrices, matrices.Length, propertyBlock);
                }
                Graphics.ExecuteCommandBuffer(cb);
            }
Пример #13
0
        //Vector4[] originalSensorsPos = new Vector4[VertExmotion.MAX_SENSOR];

        void LateUpdate()
        {
            if (m_reference == null)
            {
                return;
            }

            if (m_meshRenderer == null && m_skinMeshRenderer == null)
            {
                return;
            }

            //get shader properties from original
            m_matPropBlk = m_reference.m_matPropBlk;


            if (newSensorsPos.Length != m_reference.m_shaderSensorPos.Length)
            {
                newSensorsPos = new Vector4[m_reference.m_shaderSensorPos.Length];
            }

            for (int i = 0; i < m_reference.m_shaderSensorPos.Length; ++i)
            {
                newSensorsPos[i] = transform.TransformPoint(m_reference.transform.InverseTransformPoint(m_reference.m_shaderSensorPos[i]));
            }
            m_matPropBlk.SetVectorArray("KVM_SensorPosition", newSensorsPos);

            if (m_meshRenderer != null)
            {
                m_meshRenderer.SetPropertyBlock(m_reference.m_matPropBlk);
            }
            if (m_skinMeshRenderer != null)
            {
                m_skinMeshRenderer.SetPropertyBlock(m_reference.m_matPropBlk);
            }

            //restore values of the original
            m_matPropBlk.SetVectorArray("KVM_SensorPosition", m_reference.m_shaderSensorPos);

            if (m_copyDeltaPosition)
            {
                transform.position += m_reference.transform.position - m_referenceLastPosition;
            }

            if (m_copyRotation)
            {
                transform.rotation = m_reference.transform.rotation;
            }

            m_referenceLastPosition = m_reference.transform.position;
        }
Пример #14
0
    void TranscribeUVFromMeshToWall(int debugindex, MeshRenderer _meshRenderer, MaterialPropertyBlock _propBlock, Material _mat, Vector3 _vertex0, Vector3 _vertex1, Vector3 _vertex2, Vector3 _vertex3, Vector2 _p0, Vector2 _p1, Vector2 _p2, Vector2 _p3)
    {
        _meshRenderer.GetPropertyBlock(_propBlock);

        var     p0      = _p0;
        var     p1      = _p1;
        var     p2      = _p2;
        var     p3      = _p3;
        Vector2 vertex0 = new Vector2(_vertex0.y, _vertex0.z);
        Vector2 vertex1 = new Vector2(_vertex1.y, _vertex1.z);
        Vector2 vertex2 = new Vector2(_vertex2.y, _vertex2.z);
        Vector2 vertex3 = new Vector2(_vertex3.y, _vertex3.z);

        Vector3[] source      = new[] { new Vector3(_p0.x, _p0.y, 0), new Vector3(_p2.x, _p2.y, 0), new Vector3(_p1.x, _p1.y, 0), new Vector3(_p3.x, _p3.y, 0) };
        Vector3[] destination = new[] { new Vector3(_vertex0.y, _vertex0.z, 0), new Vector3(_vertex2.y, _vertex2.z, 0), new Vector3(_vertex1.y, _vertex1.z, 0), new Vector3(_vertex3.y, _vertex3.z, 0) };

        FindHomography(ref source, ref destination, ref _matrix);
        _inverseMatrix = CalcInverseMatrix(_matrix);
        _propBlock.SetFloatArray("_Homography", _matrix);
        _propBlock.SetFloatArray("_InvHomography", _inverseMatrix);

        _homographyVertex    = CalcHomographyMatrix(vertex0, vertex2, vertex1, vertex3);
        _invHomographyVertex = CalcInverseMatrix(_homographyVertex);

        _homography    = CalcHomographyMatrix(p0, p2, p1, p3);
        _invHomography = CalcInverseMatrix(_homography);
        _propBlock.SetFloatArray("_InvHomographyUV", _invHomography);
        _propBlock.SetVectorArray("_VertexValues", new Vector4[] {
            new Vector4(vertex0.x, vertex0.y, 0.0f, 1.0f),
            new Vector4(vertex1.x, vertex1.y, 0.0f, 1.0f),
            new Vector4(vertex2.x, vertex2.y, 0.0f, 1.0f),
            new Vector4(vertex3.x, vertex3.y, 0.0f, 1.0f)
        });
        _propBlock.SetVectorArray("_UVValues", new Vector4[] {
            new Vector4(0, 0, 0.0f, 1.0f),
            new Vector4(1, 0, 0.0f, 1.0f),
            new Vector4(0, 1, 0.0f, 1.0f),
            new Vector4(1, 1, 0.0f, 1.0f)
            //new Vector4(p0.x, p0.y, 0.0f, 1.0f),
            //new Vector4(p1.x, p1.y, 0.0f, 1.0f),
            //new Vector4(p2.x, p2.y, 0.0f, 1.0f),
            //new Vector4(p3.x, p3.y, 0.0f, 1.0f)
        });
        _propBlock.SetTexture("_SpoutTex", _checkboard);// SpoutRT); //

        //Graphics.Blit(null, _uvQuadRef, _mat, 0);

        _meshRenderer.SetPropertyBlock(_propBlock);
    }
Пример #15
0
    protected override void OnUpdate()
    {
        var cubeMesh     = RunnerManager.Instance.cubeMesh;
        var cubeMaterial = RunnerManager.Instance.cubeMaterial;

        using (var chunks = componentGroup.CreateArchetypeChunkArray(Allocator.TempJob))
        {
            ArchetypeChunkComponentType <BoneMatrices> BoneMatricesType = GetArchetypeChunkComponentType <BoneMatrices>();
            ArchetypeChunkComponentType <BoneColor>    BoneColorType    = GetArchetypeChunkComponentType <BoneColor>();
            int written = 0;
            int toWrite = instancesPerBatch;
            for (var i = 0; i < chunks.Length; ++i)
            {
                var chunk          = chunks[i];
                var nativematrices = (Matrix4x4 *)chunk.GetNativeArray(BoneMatricesType).GetUnsafePtr();
                var nativecolors   = (Vector4 *)chunk.GetNativeArray(BoneColorType).GetUnsafePtr();
                int read           = 0;
                int toRead         = chunk.Count * BoneMatrices.Length;
                while (toRead > 0)
                {
                    var toCopy = toRead < toWrite ? toRead : toWrite;

                    fixed(Vector4 *c = colors)
                    for (var j = 0; j < toCopy; ++j)
                        c[written + j] = nativecolors[(read + j) / BoneMatrices.Length];
                    fixed(Matrix4x4 *m = matrices)
                    UnsafeUtility.MemCpy(m + written, nativematrices + read, sizeof(Matrix4x4) * toCopy);

                    read    += toCopy;
                    written += toCopy;
                    toRead  -= toCopy;
                    toWrite -= toCopy;
                    if (toWrite == 0)
                    {
                        matProps.SetVectorArray("_Color", colors);
                        Graphics.DrawMeshInstanced(cubeMesh, 0, cubeMaterial, matrices, written, matProps);
                        written = 0;
                        toWrite = instancesPerBatch;
                    }
                }
            }

            if (written != 0)
            {
                matProps.SetVectorArray("_Color", colors);
                Graphics.DrawMeshInstanced(cubeMesh, 0, cubeMaterial, matrices, written, matProps);
            }
        }
    }
Пример #16
0
        public void SetData(ClipBatch data)
        {
            Array.Copy(data.transforms.array, 0, transformData, 0, data.transforms.size);
            Array.Copy(data.objectData.array, 0, objectData, 0, data.objectData.size);
            Array.Copy(data.colorData.array, 0, colorData, 0, data.colorData.size);

            matBlock.SetMatrixArray(s_TransformDataKey, transformData);
            matBlock.SetVectorArray(s_ColorDataKey, colorData);
            matBlock.SetVectorArray(s_ObjectDataKey, objectData);

            if (data.texture != null)
            {
                material.SetTexture(s_MainTextureKey, data.texture);
            }
        }
Пример #17
0
 public void SetVectorArray(
     int propertyId,
     Vector4[] value,
     bool isInstanced)
 {
     if (isInstanced)
     {
         materialPropertyBlock.SetVectorArray(propertyId, value);
         renderer.SetPropertyBlock(materialPropertyBlock);
         instancedProperties.Add(propertyId);
     }
     else
     {
         material.SetVectorArray(propertyId, value);
     }
 }
Пример #18
0
    public MaterialPropertyBlock UpdateBlock()
    {
        if (_block == null)
        {
            _block = new MaterialPropertyBlock();                // make it lazy
        }
        HEX hex = _weak_hex.Target as HEX;
        Dictionary <int, int> TSet   = new Dictionary <int, int> ();
        List <Vector4>        TArray = new List <Vector4> ();

        for (int i = 0; i < spriteIds.Count; i++)
        {
            Vector4 pos = hex.GetSpritePosInfoByName(spriteIds [i]);
            TArray.Add(pos);
        }
        if (TArray.Count > 0)
        {
            _block.SetVectorArray("_ARRAY", TArray.ToArray());
        }

        _block.SetTexture("_ATLAS", hex.altasTexture);

        var mr = gameObject.GetComponent <MeshRenderer>();

        if (mr != null)
        {
            mr.SetPropertyBlock(_block);
        }

        return(_block);
    }
    void Update()
    {
        for (int i = 0; i < _count; i++)
        {
            //_data[i].pos = _posComputer.Positions[i];
            _data[i].pos = _posComputer.PosDataList[i].position;

            _matrices[i].SetTRS(
                _data[i].pos,
                _data[i].rot,
                _data[i].scale
                );
            _matrices[i] = transform.localToWorldMatrix * _matrices[i];
        }

        _propertyBlock.SetVectorArray("_Color", _colors);
        //_propertyBlock.SetVectorArray("_Uv", _uvs);

        Graphics.DrawMeshInstanced(
            _mesh,
            0,
            _mat,
            _matrices,
            _count,
            _propertyBlock,
            ShadowCastingMode.On,
            false,
            gameObject.layer
            );
    }
Пример #20
0
    public void OnSelected()
    {
        if (selectedItem != this)
        {
            if (selectedItem != null)
            {
                //tell the other selected one that it's time to stop
                selectedItem.OnEscape();
            }
            //just chosen to be spawned on the map. Put our object under the mouse cursor
            cursorObject = Instantiate(cursorPrefab, transform.root);
            SpriteRenderer curRend = cursorObject.GetComponent <SpriteRenderer>();
            curRend.sprite = image.sprite;

            if (isPaletted)
            {
                curRend.material = prefab.GetComponentInChildren <SpriteRenderer>().sharedMaterial;
                MaterialPropertyBlock block = new MaterialPropertyBlock();
                curRend.GetPropertyBlock(block);
                List <Vector4> pal = palette.ConvertAll((Color c) => new Vector4(c.r, c.g, c.b, c.a));
                block.SetVectorArray("_ColorPalette", pal);
                block.SetInt("_IsPaletted", 1);
                curRend.SetPropertyBlock(block);
            }

            UIManager.IsMouseInteractionDisabled = true;
            escapeKeyTarget.enabled = true;
            selectedItem            = this;
            drawingMessage.SetActive(true);
            lightingSystem.enabled = false;
        }
    }
Пример #21
0
        protected override void OnUpdate()
        {
            var    propertyBlock = new MaterialPropertyBlock();
            var    uv            = new Vector4[1];
            float3 drawPos;

            Entities.ForEach((SpritePresetComponent presetComp, ref SpriteAnimComponent animComp, ref Rotation rotation, ref Translation pos) => {
                if (false == presetComp.preset.datas.TryGetValue(animComp.hash, out var presetData))
                {
                    return;
                }

                uv[0] = presetData.rects[animComp.frame];
                propertyBlock.SetVectorArray(_mainTexUv, uv);
                propertyBlock.SetTexture(_mainTex, presetData.texture);

                drawPos = pos.Value + presetData.posOffset;

                Graphics.DrawMesh(
                    presetComp.preset.mesh,
                    matrix: float4x4.TRS(drawPos, rotation.Value, presetData.scale),
                    presetComp.preset.material,
                    0,
                    Camera.main,
                    0,
                    propertyBlock);
            });
        }
Пример #22
0
    private void ApplyMaterialPropertyBlock()
    {
        MaterialPropertyBlock materialPropertyBlock = new MaterialPropertyBlock();

        materialPropertyBlock.SetVectorArray(AVATAR_SHADER_COLOR,
                                             LocalAvatarConfig.MaterialPropertyBlock.Colors);
        materialPropertyBlock.SetFloatArray(AVATAR_SHADER_DIFFUSEINTENSITY,
                                            LocalAvatarConfig.MaterialPropertyBlock.DiffuseIntensities);
        materialPropertyBlock.SetFloatArray(AVATAR_SHADER_RIMINTENSITY,
                                            LocalAvatarConfig.MaterialPropertyBlock.RimIntensities);
        materialPropertyBlock.SetFloatArray(AVATAR_SHADER_REFLECTIONINTENSITY,
                                            LocalAvatarConfig.MaterialPropertyBlock.ReflectionIntensities);
        TargetRenderer.GetClosestReflectionProbes(ReflectionProbes);

        if (ReflectionProbes != null && ReflectionProbes.Count > 0 && ReflectionProbes[0].probe.texture != null)
        {
            materialPropertyBlock.SetTexture(AVATAR_SHADER_CUBEMAP, ReflectionProbes[0].probe.texture);
        }

        for (int i = 0; i < TextureArrays.Length; i++)
        {
            materialPropertyBlock.SetTexture(TextureTypeToShaderProperties[i],
                                             TextureArrays[(int)(TextureType)i].TextureArray);
        }

        TargetRenderer.SetPropertyBlock(materialPropertyBlock);
    }
Пример #23
0
    private void Update()
    {
        for (int i = 0; i < currentParticulesCount; i++)
        {
            timeToLive[i] -= Time.deltaTime;
            if (timeToLive[i] <= 0)
            {
                currentParticulesCount--;
                particules[i] = particules[currentParticulesCount];
                timeToLive[i] = timeToLive[currentParticulesCount];
                velocities[i] = velocities[currentParticulesCount];
                colors[i]     = colors[currentParticulesCount];
            }

            if (particules[i].m23 < minZ)
            {
                velocities[i].x *= 1 - (lossOfMomentum * Time.deltaTime);
                velocities[i].y *= 1 - (lossOfMomentum * Time.deltaTime);
                velocities[i].z -= (gravity * Time.deltaTime);
                Vector4 newPosition = new Vector4(
                    particules[i].m03 + (velocities[i].x * Time.deltaTime),
                    particules[i].m13 + (velocities[i].y * Time.deltaTime),
                    particules[i].m23 + (velocities[i].z * Time.deltaTime),
                    particules[i].m33);
                particules[i].SetColumn(3, newPosition);
            }
        }

        if (lawnMower.Mowing && currentParticulesCount != 0)
        {
            colorsProperty = new MaterialPropertyBlock();
            colorsProperty.SetVectorArray("_Colors", colors);
            Graphics.DrawMeshInstanced(quad, 0, particulesMaterial, particules, currentParticulesCount, colorsProperty);
        }
    }
Пример #24
0
        public void Convert()
        {
            if (ControlArray.Count <= 0)
            {
                return;
            }

            _block.Clear();

            for (int i = 0; i < ControlArray.Count; i++)
            {
                var control = ControlArray[i];
                _block.SetTexture($"_Control_{i}", control);
            }

            _block.SetTexture("_DiffuseArray", DiffuseArray);
            _block.SetTexture("_NormalArray", NormalArray);

            _block.SetFloatArray("_DiffuseIndexes", DiffuseIndexes);
            _block.SetFloatArray("_NormalIndexes", NormalIndexes);
            _block.SetVectorArray("_Splats_ST", Tillings);
            _block.SetFloatArray("_NormalScales", NormalScales);

            var terrain = GetComponent <Terrain>();

            terrain.SetSplatMaterialPropertyBlock(_block);
        }
Пример #25
0
 void Update()
 {
     if (block == null)
     {
         block = new MaterialPropertyBlock();
         block.SetVectorArray(baseColorId, baseColors);
         block.SetFloatArray(metallicId, metallic);
         block.SetFloatArray(smoothnessId, smoothness);
         if (!lightProbeVolume)
         {
             var positions = new Vector3[1023];
             for (int i = 0; i < matrices.Length; i++)
             {
                 positions[i] = matrices[i].GetColumn(3);
             }
             var lightProbes     = new SphericalHarmonicsL2[1023];
             var occlusionProbes = new Vector4[1023];
             LightProbes.CalculateInterpolatedLightAndOcclusionProbes(
                 positions, lightProbes, occlusionProbes
                 );
             block.CopySHCoefficientArraysFrom(lightProbes);
             block.CopyProbeOcclusionArrayFrom(occlusionProbes);
         }
     }
     Graphics.DrawMeshInstanced(
         mesh, 0, material, matrices, 1023, block,
         ShadowCastingMode.On, true, 0, null,
         lightProbeVolume ?
         LightProbeUsage.UseProxyVolume : LightProbeUsage.CustomProvided,
         lightProbeVolume
         );
 }
Пример #26
0
    private void SetSprite(SpriteInfo animationStills, List <Color> palette = null)
    {
        timeElapsed = 0;
        waitTime    = animationStills.waitTime;
        if (spriteRenderer == null)
        {
            spriteRenderer = GetComponent <SpriteRenderer>();
            if (spriteRenderer == null)
            {
                Logger.Log($"There is no spriterenderer on this object {name}");
                return;
            }
        }
        spriteRenderer.sprite = animationStills.sprite;
        MaterialPropertyBlock block = new MaterialPropertyBlock();

        spriteRenderer.GetPropertyBlock(block);

        if (palette != null)
        {
            List <Vector4> pal = palette.ConvertAll <Vector4>((Color c) => new Vector4(c.r, c.g, c.b, c.a));
            block.SetVectorArray("_ColorPalette", pal);
            block.SetInt("_IsPaletted", 1);
        }
        else
        {
            block.SetInt("_IsPaletted", 0);
        }
        spriteRenderer.SetPropertyBlock(block);
    }
Пример #27
0
    protected override void OnUpdate()
    {
        MaterialPropertyBlock materialPropertyBlock = new MaterialPropertyBlock();

        Vector4[] uv = new Vector4[1];
        Entities.WithNone <Planetoid>().ForEach((ref Translation translation, ref SpriteSheetAnimation_Data spriteSheetAnimation_Data) =>
        {
            /* calculation moved to job
             * int uvOffsetXDivisor = spriteSheetAnimation_Data.currentFrame % 8;
             * int uvOffsetYDivisor = (int) math.floor((spriteSheetAnimation_Data.frameCount - spriteSheetAnimation_Data.currentFrame) / 8);
             * float uvWidth = 1f / 8; //columns
             * float uvHeight = 1f / 6; //rows
             * float uvOffsetX = uvWidth * uvOffsetXDivisor;
             * float uvOffsetY = uvHeight * uvOffsetYDivisor;
             * Vector4 uv = new Vector4(uvWidth, uvHeight, uvOffsetX, uvOffsetY);
             */
            uv[0] = spriteSheetAnimation_Data.uv;
            materialPropertyBlock.SetVectorArray("_MainTex_UV", uv);//new Vector4[] { spriteSheetAnimation_Data.uv });

            Graphics.DrawMesh(
                GameHandler.meshData.explosionMesh,
                //translation.Value,
                //Quaternion.identity,
                //are replaced by matrix which will is also necessary for DrawInstanced:
                spriteSheetAnimation_Data.matrix,
                GameHandler.meshData.explosionMaterial,
                0, //Layer
                Camera.main,
                0, //Submesh
                materialPropertyBlock
                );
        });
    }
Пример #28
0
    void Start()
    {
        bees        = new List <Bee>(50000);
        teamsOfBees = new List <Bee> [2];
        pooledBees  = new List <Bee>(50000);

        beeMatrices = new List <List <Matrix4x4> >();
        beeMatrices.Add(new List <Matrix4x4>());
        beeColors = new List <List <Vector4> >();
        beeColors.Add(new List <Vector4>());

        matProps = new MaterialPropertyBlock();

        for (int i = 0; i < 2; i++)
        {
            teamsOfBees[i] = new List <Bee>(25000);
        }
        for (int i = 0; i < startBeeCount; i++)
        {
            int team = i % 2;
            SpawnBee(team);
        }

        matProps = new MaterialPropertyBlock();
        matProps.SetVectorArray("_Color", new Vector4[beesPerBatch]);
    }
Пример #29
0
 private void SetImageSprite(Sprite value)
 {
     if (spriteRenderer != null)
     {
         spriteRenderer.sprite = value;
         MaterialPropertyBlock block = new MaterialPropertyBlock();
         spriteRenderer.GetPropertyBlock(block);
         var palette = getPaletteOrNull();
         if (palette != null)
         {
             List <Vector4> pal = palette.ConvertAll <Vector4>((Color c) => new Vector4(c.r, c.g, c.b, c.a));
             block.SetVectorArray("_ColorPalette", pal);
             block.SetInt("_IsPaletted", 1);
         }
         else
         {
             block.SetInt("_IsPaletted", 0);
         }
         spriteRenderer.SetPropertyBlock(block);
     }
     else if (image != null)
     {
         image.sprite = value;
     }
 }
Пример #30
0
        void Start()
        {
            _propertyBlock = new MaterialPropertyBlock();
            _matrices      = new Matrix4x4[_count];
            _data          = new PieceData[_count];
            _colors        = new Vector4[_count];
            _randoms       = new Vector4[_count];

            for (int i = 0; i < _count; i++)
            {
                _matrices[i] = Matrix4x4.identity;
                _data[i]     = new PieceData();//
                _data[i].rot = Quaternion.Euler(
                    Random.value * 360f,
                    Random.value * 360f,
                    Random.value
                    );
                _randoms[i] = _data[i].random;
                _colors[i]  = new Vector4(
                    1f,
                    1f,
                    1f,
                    1f
                    );
                _data[i].Reset(transform.localToWorldMatrix);
            }

            _mat.SetVectorArray("_Random", _randoms);
            _propertyBlock.SetVectorArray("_Color", _colors);

            _Loop();
        }