SetTexture() приватный Метод

private SetTexture ( int nameID, Texture value ) : void
nameID int
value Texture
Результат void
 public void UpdatePropertyBlock()
 {
     MaterialPropertyBlock propBlock = new MaterialPropertyBlock();
     render.GetPropertyBlock(propBlock);
     propBlock.SetTexture("_MainTex", maskSprite.texture);
     propBlock.SetTexture("_SprTex", springSprite);
     propBlock.SetTexture("_SumTex", summerSprite);
     propBlock.SetTexture("_AutTex", autumnSprite);
     propBlock.SetTexture("_WinTex", winterSprite);
     render.SetPropertyBlock(propBlock);
 }
Пример #2
0
    static int SetTexture(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 3 && TypeChecker.CheckTypes <string, UnityEngine.Texture>(L, 2))
            {
                UnityEngine.MaterialPropertyBlock obj = (UnityEngine.MaterialPropertyBlock)ToLua.CheckObject(L, 1, typeof(UnityEngine.MaterialPropertyBlock));
                string arg0 = ToLua.ToString(L, 2);
                UnityEngine.Texture arg1 = (UnityEngine.Texture)ToLua.ToObject(L, 3);
                obj.SetTexture(arg0, arg1);
                return(0);
            }
            else if (count == 3 && TypeChecker.CheckTypes <int, UnityEngine.Texture>(L, 2))
            {
                UnityEngine.MaterialPropertyBlock obj = (UnityEngine.MaterialPropertyBlock)ToLua.CheckObject(L, 1, typeof(UnityEngine.MaterialPropertyBlock));
                int arg0 = (int)LuaDLL.lua_tonumber(L, 2);
                UnityEngine.Texture arg1 = (UnityEngine.Texture)ToLua.ToObject(L, 3);
                obj.SetTexture(arg0, arg1);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.MaterialPropertyBlock.SetTexture"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Пример #3
0
 static public int SetTexture(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         if (matchType(l, argc, 2, typeof(int), typeof(UnityEngine.Texture)))
         {
             UnityEngine.MaterialPropertyBlock self = (UnityEngine.MaterialPropertyBlock)checkSelf(l);
             System.Int32 a1;
             checkType(l, 2, out a1);
             UnityEngine.Texture a2;
             checkType(l, 3, out a2);
             self.SetTexture(a1, a2);
             pushValue(l, true);
             return(1);
         }
         else if (matchType(l, argc, 2, typeof(string), typeof(UnityEngine.Texture)))
         {
             UnityEngine.MaterialPropertyBlock self = (UnityEngine.MaterialPropertyBlock)checkSelf(l);
             System.String a1;
             checkType(l, 2, out a1);
             UnityEngine.Texture a2;
             checkType(l, 3, out a2);
             self.SetTexture(a1, a2);
             pushValue(l, true);
             return(1);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function SetTexture to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
        public void TransferToUnityComponents(Entity entity, IBindingContext context)
        {
            try
            {
                var spriteRenderer   = context.GetUnityComponent <UnityEngine.SpriteRenderer>(entity);
                var sprite2DRenderer = context.GetComponentData <Sprite2DRenderer>(entity);
                var sprite           = context.GetUnityObject <UnityEngine.Sprite>(sprite2DRenderer.sprite);

                var block = new UnityEngine.MaterialPropertyBlock();
                spriteRenderer.GetPropertyBlock(block);
                block.Clear();

                spriteRenderer.color = sprite2DRenderer.color.Convert();
                block.SetColor("_Color", sprite2DRenderer.color.Convert());

                if (sprite)
                {
                    spriteRenderer.sprite = sprite;
                    var blending = sprite2DRenderer.blending;
                    if (k_BlendModes.TryGetValue(blending, out var blendMode))
                    {
                        spriteRenderer.sharedMaterial.SetFloat("_SrcMode", blendMode.x);
                        spriteRenderer.sharedMaterial.SetFloat("_DstMode", blendMode.y);
                    }
                    else
                    {
                        UnityEngine.Debug.Log($"Tiny: Unknown blending mode, of value '{blending}'");
                    }

                    block.SetTexture("_MainTex", sprite.texture);
                }
                else
                {
                    spriteRenderer.sprite = s_WhiteSprite;
                    if (!context.HasComponent <Sprite2DRendererOptions>(entity))
                    {
                        spriteRenderer.size = UnityEngine.Vector2.one;
                    }
                }

                spriteRenderer.SetPropertyBlock(block);

                if (context.HasComponent <Sprite2DRendererOptions>(entity))
                {
                    var options = context.GetComponentData <Sprite2DRendererOptions>(entity);
                    SetDrawMode(spriteRenderer, options.drawMode);
                    spriteRenderer.size = options.size;
                }
                else
                {
                    spriteRenderer.drawMode = UnityEngine.SpriteDrawMode.Simple;
                }
            }
            finally
            {
                UnityEditor.SceneView.RepaintAll();
            }
        }
Пример #5
0
 static public int SetTexture(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         int argc = LuaDLL.lua_gettop(l);
         if (matchType(l, argc, 2, typeof(int), typeof(UnityEngine.Texture)))
         {
             UnityEngine.MaterialPropertyBlock self = (UnityEngine.MaterialPropertyBlock)checkSelf(l);
             System.Int32 a1;
             checkType(l, 2, out a1);
             UnityEngine.Texture a2;
             checkType(l, 3, out a2);
             self.SetTexture(a1, a2);
             pushValue(l, true);
             return(1);
         }
         else if (matchType(l, argc, 2, typeof(string), typeof(UnityEngine.Texture)))
         {
             UnityEngine.MaterialPropertyBlock self = (UnityEngine.MaterialPropertyBlock)checkSelf(l);
             System.String a1;
             checkType(l, 2, out a1);
             UnityEngine.Texture a2;
             checkType(l, 3, out a2);
             self.SetTexture(a1, a2);
             pushValue(l, true);
             return(1);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function SetTexture to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
 static public int SetTexture__Int32__Texture(IntPtr l)
 {
     try {
         UnityEngine.MaterialPropertyBlock self = (UnityEngine.MaterialPropertyBlock)checkSelf(l);
         System.Int32 a1;
         checkType(l, 2, out a1);
         UnityEngine.Texture a2;
         checkType(l, 3, out a2);
         self.SetTexture(a1, a2);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Пример #7
0
    void Start()
    {
        _rnd = GetComponent<Renderer>();
        _rnd.GetPropertyBlock(_block = new MaterialPropertyBlock());

        _inputs = input.GetPixels();

        _width = input.width;
        _height = input.height;
        _pixelCount = _inputs.Length;
        _texSize = new Vector2(_width, _height);

        output = new Texture2D(_width, _height, TextureFormat.ARGB32, false);
        _outputs = input.GetPixels();
        output.SetPixels(_outputs);
        output.Apply();

        _block.SetTexture(PROP_MAIN_TEX, output);
        _rnd.SetPropertyBlock(_block);
        _mcmc = new MCMC(output, stdDev);

        StartCoroutine (Pinning (0.01f, 200));
    }
Пример #8
0
        void Start()
        {
            if (width <= 0)
                width = Screen.width;
            if (height <= 0)
                height = Screen.height;
            if (depth <= 0f)
                depth = srcCamera.nearClipPlane;

            _capture = new RenderTexture(width, height, 24, RenderTextureFormat.ARGB32);
            _capture.antiAliasing = (QualitySettings.antiAliasing == 0 ? 1 : QualitySettings.antiAliasing);
            _capture.filterMode = FilterMode.Bilinear;
            _capture.wrapMode = TextureWrapMode.Clamp;
            _props = new MaterialPropertyBlock();
            _props.SetTexture(PROP_MAIN_TEXTURE, _capture);
            GetComponent<Renderer>().SetPropertyBlock(_props);

            srcCamera.targetTexture = _capture;
            var viewport = srcCamera.rect;
            var size = srcCamera.ViewportToWorldPoint(new Vector3(viewport.width, viewport.height, depth))
                - srcCamera.ViewportToWorldPoint(new Vector3(0f, 0f, depth));
            size.z = 1f;
            transform.localScale = size;
        }
Пример #9
0
        void Update()
        {
            if (_needsReset) ResetResources();

            UpdateKernelShader();

            if (Application.isPlaying)
            {
                // Swap the particle buffers.
                var temp = _positionBuffer1;
                _positionBuffer1 = _positionBuffer2;
                _positionBuffer2 = temp;

                temp = _rotationBuffer1;
                _rotationBuffer1 = _rotationBuffer2;
                _rotationBuffer2 = temp;

                // Call the kernel shader.
                Graphics.Blit(_positionBuffer1, _positionBuffer2, _kernelMaterial, 2);
                Graphics.Blit(_rotationBuffer1, _rotationBuffer2, _kernelMaterial, 3);
            }
            else
            {
                InitializeAndPrewarmBuffers();
            }

            // Make a material property block for the following drawcalls.
            var props = new MaterialPropertyBlock();
            props.SetTexture("_PositionBuffer", _positionBuffer2);
            props.SetTexture("_RotationBuffer", _rotationBuffer2);
            props.SetFloat("_ScaleMin", _minScale);
            props.SetFloat("_ScaleMax", _maxScale);
            props.SetFloat("_RandomSeed", _randomSeed);

            // Temporary variables
            var mesh = _bulkMesh.mesh;
            var position = transform.position;
            var rotation = transform.rotation;
            var material = _material ? _material : _defaultMaterial;
            var uv = new Vector2(0.5f / _positionBuffer2.width, 0);

            // Draw a bulk mesh repeatedly.
            for (var i = 0; i < _positionBuffer2.height; i++)
            {
                uv.y = (0.5f + i) / _positionBuffer2.height;
                props.AddVector("_BufferOffset", uv);
                Graphics.DrawMesh(
                    mesh, position, rotation,
                    material, 0, null, 0, props,
                    _castShadows, _receiveShadows);
            }
        }
Пример #10
0
 public LUT3D SetProperty(MaterialPropertyBlock block)
 {
     block.SetFloat (PROP_SCALE, (float)(_dim - 1) / _dim);
     block.SetFloat (PROP_OFFSET, 1f / (2f * _dim));
     block.SetTexture (PROP_3DLUT, _3dlut);
     return this;
 }
Пример #11
0
		private void ApplyToBlock(ref MaterialPropertyBlock block, ShaderIDs bids) {
		#if USE_PROPERTY_BLOCKS
			#if UNITY_5 && !UNITY_5_0 && !UNITY_5_1 && !UNITY_5_2

				block.SetVector(bids.exposureIBL,	exposures);
				block.SetVector(bids.exposureLM,	exposuresLM);
				block.SetMatrix(bids.skyMatrix,		skyMatrix);
				block.SetMatrix(bids.invSkyMatrix,	invMatrix);

				block.SetVector(bids.skyMin, skyMin);
				block.SetVector(bids.skyMax, skyMax);			

				if(specularCube) block.SetTexture(bids.specCubeIBL, specularCube);
				else 			 block.SetTexture(bids.specCubeIBL, blackCube);

				block.SetVector(bids.SH[0],	SH.cBuffer[0]);
				block.SetVector(bids.SH[1],	SH.cBuffer[1]);
				block.SetVector(bids.SH[2],	SH.cBuffer[2]);
				block.SetVector(bids.SH[3],	SH.cBuffer[3]);
				block.SetVector(bids.SH[4],	SH.cBuffer[4]);
				block.SetVector(bids.SH[5],	SH.cBuffer[5]);
				block.SetVector(bids.SH[6],	SH.cBuffer[6]);
				block.SetVector(bids.SH[7],	SH.cBuffer[7]);
				block.SetVector(bids.SH[8], SH.cBuffer[8]);

			#else 

				block.AddVector(bids.exposureIBL,	exposures);
				block.AddVector(bids.exposureLM,	exposuresLM);

				block.AddMatrix(bids.skyMatrix,		skyMatrix);
				block.AddMatrix(bids.invSkyMatrix,	invMatrix);

				block.AddVector(bids.skyMin, skyMin);
				block.AddVector(bids.skyMax, skyMax);			

				if(specularCube) block.AddTexture(bids.specCubeIBL, specularCube);
				else 			 block.AddTexture(bids.specCubeIBL, blackCube);

				block.AddVector(bids.SH[0],	SH.cBuffer[0]);
				block.AddVector(bids.SH[1],	SH.cBuffer[1]);
				block.AddVector(bids.SH[2],	SH.cBuffer[2]);
				block.AddVector(bids.SH[3],	SH.cBuffer[3]);
				block.AddVector(bids.SH[4],	SH.cBuffer[4]);
				block.AddVector(bids.SH[5],	SH.cBuffer[5]);
				block.AddVector(bids.SH[6],	SH.cBuffer[6]);
				block.AddVector(bids.SH[7],	SH.cBuffer[7]);
				block.AddVector(bids.SH[8], SH.cBuffer[8]);

			#endif
		#endif
		}
Пример #12
0
    public void CreateMesh()
    {
        if (meshF == null) {
            meshF = GetComponent<MeshFilter>() as MeshFilter;
        }
        if (rend == null) {
            rend = GetComponent<Renderer>() as Renderer;
        }
        if (meshF.sharedMesh) {
            DestroyImmediate(meshF.sharedMesh);
        }
        if (mesh) {
            DestroyImmediate(mesh);
        }

        if (useSprite == null) {
            return;
        }

        MaterialPropertyBlock pBlock = new MaterialPropertyBlock();
        pBlock.SetTexture(0, useSprite.texture);
        rend.SetPropertyBlock(pBlock);

        float ppu = useSprite.pixelsPerUnit;
        float cornerWidth = (float)(slicePixels) / ppu;
        float cornerHeight = (float)(slicePixels) / ppu;

        mesh = new Mesh();

        Vector3[] vertices = new Vector3[16];
        Vector3[] normals = new Vector3[16];
        Vector2[] uvs = new Vector2[16];

        float[] xPValues = new float[4];
        float[] yPValues = new float[4];

        float cornerWidthP = cornerWidth / width;
        float cornerHeightP = cornerHeight / height;

        xPValues[0] = 0.0f;
        yPValues[0] = 0.0f;
        xPValues[1] = cornerWidthP;
        yPValues[1] = cornerHeightP;
        xPValues[2] = 1.0f - cornerWidthP;
        yPValues[2] = 1.0f - cornerHeightP;
        xPValues[3] = 1.0f;
        yPValues[3] = 1.0f;

        for (int x = 0; x < 4; x++) {
            for (int y = 0; y < 4; y++) {
                float xP = xPValues[x];
                float yP = yPValues[y];

                int index = OneDee(x, y);
                vertices[index] = new Vector3(
                    Mathf.Lerp(-1.0f, 1.0f, xP) * width * 0.5f,
                    Mathf.Lerp(-1.0f, 1.0f, yP) * height * 0.5f,
                    0.0f);
                uvs[index] = new Vector2((float)x / 3.0f, (float)y / 3.0f);
                normals[index] = -Vector3.forward;
            }
        }

        int[] tris = new int[9 * 2 * 3];
        int i = 0;
        for (int x = 0; x < 3; x++) {
            for (int y = 0; y < 3; y++) {
                tris[i] = OneDee(x + 1, y);
                i++;
                tris[i] = OneDee(x, y);
                i++;
                tris[i] = OneDee(x + 1, y + 1);
                i++;
                tris[i] = OneDee(x, y);
                i++;
                tris[i] = OneDee(x, y + 1);
                i++;
                tris[i] = OneDee(x + 1, y + 1);
                i++;
            }
        }

        mesh.MarkDynamic();
        mesh.vertices = vertices;
        mesh.uv = uvs;
        mesh.triangles = tris;
        mesh.normals = normals;
        mesh.RecalculateBounds();

        meshF.sharedMesh = mesh;
    }
 public override void SetTexture(Texture2D texture)
 {
     base.SetTexture(texture);
     MaterialPropertyBlock props = new MaterialPropertyBlock();
     #if UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_5_0 || UNITY_5_1 || UNITY_5_2
     props.AddTexture("_MainTex", texture);
     #else
     props.SetTexture("_MainTex", texture);
     #endif
     spriteRenderer.SetPropertyBlock(props);
 }
Пример #14
0
        void Update()
        {
            if (_needsReset) ResetResources();

            // Call the kernels.
            UpdateKernelShader();
            Graphics.Blit(null, _positionBuffer, _kernelMaterial, 0);
            Graphics.Blit(null, _rotationBuffer, _kernelMaterial, 1);
            Graphics.Blit(null, _scaleBuffer,    _kernelMaterial, 2);

            // Make a material property block for the following drawcalls.
            var props = new MaterialPropertyBlock();
            props.SetTexture("_PositionTex", _positionBuffer);
            props.SetTexture("_RotationTex", _rotationBuffer);
            props.SetTexture("_ScaleTex", _scaleBuffer);
            props.SetVector("_ColumnRow", new Vector2(_columns, _rows));
            props.SetVector("_UVOffset", UVOffset);

            // Temporary variables.
            var mesh = _bulkMesh.mesh;
            var position = transform.position;
            var rotation = transform.rotation;
            var material = _material ? _material : _defaultMaterial;
            var uv = new Vector2(0.5f / _positionBuffer.width, 0);

            position += transform.right * XOffset;
            position += transform.up * YOffset;

            // Draw mesh segments.
            for (var i = 0; i < _positionBuffer.height; i++)
            {
                uv.y = (0.5f + i) / _positionBuffer.height;
                props.SetVector("_BufferOffset", uv);
                Graphics.DrawMesh(
                    mesh, position, rotation,
                    material, 0, null, 0, props,
                    _castShadows, _receiveShadows);
            }
        }
Пример #15
0
        void LateUpdate()
        {
            if (_needsReset) ResetResources();

            // Call the kernels.
            UpdateKernelShader();
            Graphics.Blit(null, _positionBuffer, _kernelMaterial, 0);
            Graphics.Blit(_positionBuffer, _normalBuffer1, _kernelMaterial, 1);
            Graphics.Blit(_positionBuffer, _normalBuffer2, _kernelMaterial, 2);

            // Update the line material.
            _lineMaterial.SetColor("_Color", _lineColor);

            // Make a material property block for the following drawcalls.
            var props1 = new MaterialPropertyBlock();
            var props2 = new MaterialPropertyBlock();

            props1.SetTexture("_PositionBuffer", _positionBuffer);
            props2.SetTexture("_PositionBuffer", _positionBuffer);

            props1.SetTexture("_NormalBuffer", _normalBuffer1);
            props2.SetTexture("_NormalBuffer", _normalBuffer2);

            var mapOffs = new Vector3(0, 0, VOffset);
            props1.SetVector("_MapOffset", mapOffs);
            props2.SetVector("_MapOffset", mapOffs);

            props1.SetFloat("_UseBuffer", 1);
            props2.SetFloat("_UseBuffer", 1);

            // Temporary variables.
            var mesh = _bulkMesh.mesh;
            var position = transform.position;
            var rotation = transform.rotation;
            var uv = new Vector2(0.5f / _positionBuffer.width, 0);

            position += transform.forward * ZOffset;

            // Draw mesh segments.
            for (var i = 0; i < _totalStacks; i += _stacksPerSegment)
            {
                uv.y = (0.5f + i) / _positionBuffer.height;

                props1.SetVector("_BufferOffset", uv);
                props2.SetVector("_BufferOffset", uv);

                if (_material)
                {
                    // 1st half
                    Graphics.DrawMesh(
                        mesh, position, rotation,
                        _material, 0, null, 0, props1,
                        _castShadows, _receiveShadows);

                    // 2nd half
                    Graphics.DrawMesh(
                        mesh, position, rotation,
                        _material, 0, null, 1, props2,
                        _castShadows, _receiveShadows);
                }

                // lines
                if (_lineColor.a > 0.0f)
                    Graphics.DrawMesh(
                        mesh, position, rotation,
                        _lineMaterial, 0, null, 2,
                        props1, false, false);
            }
        }
Пример #16
0
        public void UpdateCards()
        {
            if (!Visible)
                foreach (var c in cards)
                    c.transform.parent = transform;

            if (UpdatesDisabled)
                return;

            //print("Updating cards on deck " + (TopCard == null ? "Empty" : TopCard.ToString()));

            var localCardSpacerX = cardSpacerX;
            var localCardSpacerY = cardSpacerY;

            if ((maxCardsSpace > 0) && (cards.Count > maxCardsSpace))
            {
                //override the spacers values to squeeze cards
                localCardSpacerX = (cardSpacerX * maxCardsSpace) / cards.Count;
                localCardSpacerY = (cardSpacerY * maxCardsSpace) / cards.Count;
            }

            //Loop on the Deck Cards (not playing cards)
            var lastTransform = transform;
            for (int i = 0; i < cards.Count; i++)
            {
                //Get the card object
                var card = cards[i];
                //var spriteRenderer = card.GetComponent<SpriteRenderer>();
                //if (spriteRenderer)
                //    spriteRenderer.sprite = card.desc.sprite;
                var meshRenderer = card.GetComponent<MeshRenderer>();
                if (meshRenderer)
                {
                    MaterialPropertyBlock mpb = new MaterialPropertyBlock ();
                    //mpb.SetTexture ("_DetailAlbedoMap", card.desc.texture);
                    mpb.SetTexture ("_MainTex", card.desc.texture);
                    meshRenderer.SetPropertyBlock (mpb);
                }
                card.transform.parent = lastTransform;
                //lastTransform = card.transform;

                var localSortOrder = sortStep*(i+1) + ((selected == card)?cards.Count:0);
                var targetLocalPosition = new Vector3(0, 0, (-localSortOrder) * 0.03f); // z needs to be set for mouse hit detection
                targetLocalPosition += new Vector3(localCardSpacerX, localCardSpacerY) * ((float)i - (centered?1:0) * cards.Count/2.0f);

                var targetLocalScale = Game.Instance.cardPrefab.transform.localScale;
                if (selected == card)
                {
                    targetLocalScale = targetLocalScale * 1.75f;
                    targetLocalPosition -= Vector3.forward * 0.5f;
                }

                targetLocalScale += targetLocalScale * (0.1f * (card.multiplier-1));

#if NGUI
                TweenPosition.Begin(card.gameObject, 0.25f, targetLocalPosition);
                TweenSize.Begin(card.gameObject, 0.25f, targetLocalScale);
#else
                iTween.MoveTo(card.gameObject, iTween.Hash("position", targetLocalPosition, "islocal", true, "time", 0.25f));
                iTween.ScaleTo(card.gameObject, iTween.Hash("scale", targetLocalScale, "islocal", true, "time", 0.25f));
#endif
                card.GetComponent<Collider2D>().enabled = false; // disable the collider until the card is finished moving.

                var sortOrder = order + localSortOrder; // Right decks are on top of left decks when squeezing together
                card.GetComponent<Renderer>().sortingOrder = sortOrder; // sort order needs to be set for visual to render correctly
                StartCoroutine(Delay(() => // schedule this for when the card finishes moving
                {
                    card.GetComponent<Collider2D>().enabled = card.IsDragable;
                }, 0.25f));
            }
        }
Пример #17
0
        void Update()
        {
            if (_needsReset) ResetResources();

            if (Application.isPlaying)
            {
                UpdateKernelShader();
                SwapBuffersAndInvokeKernels();
            }
            else
            {
                InitializeAndPrewarmBuffers();
            }

            // Make a material property block for the following drawcalls.
            var props = new MaterialPropertyBlock();
            props.SetTexture("_PositionBuffer", _positionBuffer2);
            props.SetTexture("_RotationBuffer", _rotationBuffer2);
            props.SetFloat("_ScaleMin", _scale * (1 - _scaleRandomness));
            props.SetFloat("_ScaleMax", _scale);
            props.SetFloat("_RandomSeed", _randomSeed);

            // Temporary variables
            var mesh = _bulkMesh.mesh;
            var position = transform.position;
            var rotation = transform.rotation;
            var material = _material ? _material : _defaultMaterial;
            var uv = new Vector2(0.5f / _positionBuffer2.width, 0);

            // Draw a bulk mesh repeatedly.
            for (var i = 0; i < _positionBuffer2.height; i++)
            {
                uv.y = (0.5f + i) / _positionBuffer2.height;
                props.SetVector("_BufferOffset", uv);
                Graphics.DrawMesh(
                    mesh, position, rotation,
                    material, 0, null, 0, props,
                    _castShadows, _receiveShadows);
            }
        }
Пример #18
0
    void UpdateMaterial()
    {
        if (! initialised) {
            // Parameters changed before Awake() has been run, do a full update when appropriate.
            // (Can't rely on Awake() when the GameObject is disabled. It does a lousy job as a constructor.)
            regenerateMesh = true;
            return;
        }

        if ((renderer.sharedMaterials.Length != 1) || (renderer.sharedMaterials[0] != m_material)) {
            // Update only when necessary to prevent false scene changes.
            renderer.sharedMaterials = new Material[] {m_material};
        }

        MaterialPropertyBlock materialProperties = new MaterialPropertyBlock();
        renderer.GetPropertyBlock(materialProperties);

        if ((m_sprite != null) && (m_sprite.texture != null)) {
            materialProperties.SetTexture("_MainTex", m_sprite.texture);
        }
        else if (m_material != null) {
            if (materialProperties.GetTexture("_MainTex") != null) {
                materialProperties.Clear();
            }
            m_material.SetTexture("_MainTex", null);
        }

        renderer.SetPropertyBlock(materialProperties);
    }
Пример #19
0
        void Update()
        {
            if (_needsReset) ResetResources();

            // Advance the time variables.
            _rotationNoiseTime += _rotationNoiseSpeed * Time.deltaTime;

            // Call the kernels.
            UpdateKernelShader();

            if (_needsReset || _positionUpdateFlag)
                Graphics.Blit(null, _positionBuffer, _kernelMaterial, 0);

            Graphics.Blit(null, _rotationBuffer, _kernelMaterial, 1);

            if (_needsReset || _scaleUpdateFlag)
                Graphics.Blit(null, _scaleBuffer,    _kernelMaterial, 2);

            // Make a material property block for the following drawcalls.
            var props = new MaterialPropertyBlock();
            props.SetTexture("_PositionTex", _positionBuffer);
            props.SetTexture("_RotationTex", _rotationBuffer);
            props.SetTexture("_ScaleTex", _scaleBuffer);

            // Temporary variables.
            var mesh = _bulkMesh.mesh;
            var position = transform.position;
            var rotation = transform.rotation;
            var material = _material ? _material : _defaultMaterial;
            var uv = new Vector2(0.5f / _positionBuffer.width, 0);

            // Draw mesh segments.
            for (var i = 0; i < _positionBuffer.height; i++)
            {
                uv.y = (0.5f + i) / _positionBuffer.height;
                props.SetVector("_BufferOffset", uv);
                Graphics.DrawMesh(
                    mesh, position, rotation,
                    material, 0, null, 0, props,
                    _castShadows, _receiveShadows);
            }

            // Clear flag variables.
            _positionUpdateFlag = true;
            _scaleUpdateFlag = true;
            _needsReset = false;
        }