SetVector() public method

Set a vector property.

public SetVector ( int nameID, Vector4 value ) : void
nameID int The name ID of the property retrieved by Shader.PropertyToID.
value Vector4 The Vector4 value to set.
return void
Example #1
0
    static int SetVector(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 3 && TypeChecker.CheckTypes <int, UnityEngine.Vector4>(L, 2))
            {
                UnityEngine.MaterialPropertyBlock obj = (UnityEngine.MaterialPropertyBlock)ToLua.CheckObject(L, 1, typeof(UnityEngine.MaterialPropertyBlock));
                int arg0 = (int)LuaDLL.lua_tonumber(L, 2);
                UnityEngine.Vector4 arg1 = ToLua.ToVector4(L, 3);
                obj.SetVector(arg0, arg1);
                return(0);
            }
            else if (count == 3 && TypeChecker.CheckTypes <string, UnityEngine.Vector4>(L, 2))
            {
                UnityEngine.MaterialPropertyBlock obj = (UnityEngine.MaterialPropertyBlock)ToLua.CheckObject(L, 1, typeof(UnityEngine.MaterialPropertyBlock));
                string arg0 = ToLua.ToString(L, 2);
                UnityEngine.Vector4 arg1 = ToLua.ToVector4(L, 3);
                obj.SetVector(arg0, arg1);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.MaterialPropertyBlock.SetVector"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Example #2
0
 static public int SetVector(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         if (matchType(l, argc, 2, typeof(int), typeof(UnityEngine.Vector4)))
         {
             UnityEngine.MaterialPropertyBlock self = (UnityEngine.MaterialPropertyBlock)checkSelf(l);
             System.Int32 a1;
             checkType(l, 2, out a1);
             UnityEngine.Vector4 a2;
             checkType(l, 3, out a2);
             self.SetVector(a1, a2);
             pushValue(l, true);
             return(1);
         }
         else if (matchType(l, argc, 2, typeof(string), typeof(UnityEngine.Vector4)))
         {
             UnityEngine.MaterialPropertyBlock self = (UnityEngine.MaterialPropertyBlock)checkSelf(l);
             System.String a1;
             checkType(l, 2, out a1);
             UnityEngine.Vector4 a2;
             checkType(l, 3, out a2);
             self.SetVector(a1, a2);
             pushValue(l, true);
             return(1);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function SetVector to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Example #3
0
 static public int SetVector(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.Vector4)))
         {
             UnityEngine.MaterialPropertyBlock self = (UnityEngine.MaterialPropertyBlock)checkSelf(l);
             System.Int32 a1;
             checkType(l, 2, out a1);
             UnityEngine.Vector4 a2;
             checkType(l, 3, out a2);
             self.SetVector(a1, a2);
             pushValue(l, true);
             return(1);
         }
         else if (matchType(l, argc, 2, typeof(string), typeof(UnityEngine.Vector4)))
         {
             UnityEngine.MaterialPropertyBlock self = (UnityEngine.MaterialPropertyBlock)checkSelf(l);
             System.String a1;
             checkType(l, 2, out a1);
             UnityEngine.Vector4 a2;
             checkType(l, 3, out a2);
             self.SetVector(a1, a2);
             pushValue(l, true);
             return(1);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function SetVector 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 SetVector__Int32__Vector4(IntPtr l)
 {
     try {
         UnityEngine.MaterialPropertyBlock self = (UnityEngine.MaterialPropertyBlock)checkSelf(l);
         System.Int32 a1;
         checkType(l, 2, out a1);
         UnityEngine.Vector4 a2;
         checkType(l, 3, out a2);
         self.SetVector(a1, a2);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Example #5
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.AddTexture("_PositionTex", _positionBuffer);
            props.AddTexture("_RotationTex", _rotationBuffer);
            props.AddTexture("_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.AddVector("_BufferOffset", uv);
                Graphics.DrawMesh(
                    mesh, position, rotation,
                    material, 0, null, 0, props,
                    _castShadows, _receiveShadows);
            }
        }
Example #6
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);
            }
        }
Example #7
0
        void Update()
        {
            if (_needsReset) ResetResources();

            if (Application.isPlaying)
            {
                // Execute the kernel shaders.
                SwapBuffers();
                UpdateKernelShader();

                _kernelMaterial.SetTexture("_PositionTex", _positionBuffer1);
                _kernelMaterial.SetTexture("_VelocityTex", _velocityBuffer1);
                Graphics.Blit(null, _velocityBuffer2, _kernelMaterial, 3);

                _kernelMaterial.SetTexture("_VelocityTex", _velocityBuffer2);
                Graphics.Blit(null, _positionBuffer2, _kernelMaterial, 2);
            }
            else
            {
                // Reset and execute the kernel shaders repeatedly.
                Graphics.Blit(null, _positionBuffer2, _kernelMaterial, 0);
                Graphics.Blit(null, _velocityBuffer2, _kernelMaterial, 1);

                for (var i = 0; i < 32; i++) {
                    SwapBuffers();
                    UpdateKernelShader(i);

                    _kernelMaterial.SetTexture("_PositionTex", _positionBuffer1);
                    _kernelMaterial.SetTexture("_VelocityTex", _velocityBuffer1);
                    Graphics.Blit(null, _velocityBuffer2, _kernelMaterial, 3);

                    _kernelMaterial.SetTexture("_VelocityTex", _velocityBuffer2);
                    Graphics.Blit(null, _positionBuffer2, _kernelMaterial, 2);
                }
            }

            // Draw lines.
            UpdateLineShader();

            var matrix = transform.localToWorldMatrix;
            var stride = LinesPerDraw;
            var total = TotalLineCount;

            var props = new MaterialPropertyBlock();
            var uv = new Vector2(0.5f / _historyLength, 0);

            for (var i = 0; i < total; i += stride)
            {
                uv.y = (0.5f + i) / total;
                props.SetVector("_BufferOffset", uv);
                Graphics.DrawMesh(_mesh, matrix, _lineMaterial, 0, null, 0, props);
            }
        }
Example #8
0
        void Update()
        {
            if (_needsReset)
            {
                ResetResources();
                ResetState();
                _needsReset = false;
            }

            if (Application.isPlaying)
            {
                float deltaTime;
                int steps;

                if (_fixTimeStep)
                {
                    // fixed time step
                    deltaTime = 1.0f / _stepsPerSecond;
                    steps = Mathf.RoundToInt(Time.deltaTime * _stepsPerSecond);
                }
                else
                {
                    // variable time step
                    deltaTime = Time.smoothDeltaTime;
                    steps = 1;
                }

                // time steps
                for (var i = 0; i < steps; i++)
                    StepKernel(deltaTime);
            }
            else
            {
                ResetState();

                // warming up
                for (var i = 0; i < 32; i++)
                    StepKernel(0.1f);
            }

            // drawing lines
            UpdateLineShader();

            var matrix = transform.localToWorldMatrix;
            var stride = LinesPerDraw;
            var total = TotalLineCount;

            var props = new MaterialPropertyBlock();
            var uv = new Vector2(0.5f / _historyLength, 0);

            for (var i = 0; i < total; i += stride)
            {
                uv.y = (0.5f + i) / total;
                props.SetVector("_BufferOffset", uv);

                // front face
                props.SetFloat("_Flip", 1);
                Graphics.DrawMesh(
                    _mesh, matrix, _lineMaterial, gameObject.layer,
                    null, 0, props, _castShadows, _receiveShadows
                );

                // back face
                props.SetFloat("_Flip", -1);
                Graphics.DrawMesh(
                    _mesh, matrix, _lineMaterial, gameObject.layer,
                    null, 0, props, _castShadows, _receiveShadows
                );
            }
        }
        public void SetPropertyBlock(MaterialPropertyBlock block,
                                     Transform modelTransform)
        {
            // model local space to world space matrix
            var l2w = modelTransform.localToWorldMatrix;

            // world space to effector local space matrix
            var w2e = transform.worldToLocalMatrix;

            // effector local space to normalized effector space matrix
            var es = _effectorSize;
            var invs = new Vector3(1.0f / es.x, 1.0f / es.y, 1.0f / es.z);
            var e2n = Matrix4x4.Scale(invs);

            block.SetMatrix("_Effector", e2n * w2e * l2w);

            block.SetVector("_Steepness", new Vector3(
                _transitionSteepness,
                _emissionTransitionSteepness,
                _scaleTransitionSteepness
            ));

            block.SetColor("_InitialEmission", _initialEmission);
            block.SetFloat("_InitialScale", _initialScale);

            if (_effectType == EffectType.Destruction)
                SetDestructionProps(block, modelTransform);
            else
                SetDisintegrationProps(block);
        }
        void SetDisintegrationProps(MaterialPropertyBlock block)
        {
            block.SetVector("_PNoise", new Vector3(
                _positionNoiseAmplitude,
                _positionNoiseFrequency,
                _positionNoiseSpeed
            ));

            block.SetVector("_RNoise", new Vector3(
                _rotationNoiseAmplitude,
                _rotationNoiseFrequency,
                _rotationNoiseSpeed
            ));
        }
 public bool AddToMaterialPropertyBlock(UnityEngine.MaterialPropertyBlock materialPropertyBlock)
 {
     materialPropertyBlock.SetVector(this.PropertyName, this.PropertyValue);
     return(false);
 }
Example #12
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
		}
Example #13
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);
            }
        }
Example #14
0
    void Update()
    {
        if (_needsReset) ResetResources();

        if( Input.GetKeyDown( KeyCode.Space ) )
        {
            ResetResources();
        }

        // Variable time step.
        float deltaTime = Time.smoothDeltaTime;
        int steps = 1;

        // Time steps.
        for (var i = 0; i < steps; i++)
        {
            _time += deltaTime;

            for(var w = 0; w < warps.Count; w++)
            {
                RhoWarp warp = warps[w];
                if( warp == null || warp.enabled == false) continue;
                warp.UpdateParameters();
                warp.StepKernel( _time, deltaTime, buffer );
            }

            StepKernel(_time, deltaTime);
        }

        // Draw lines.
        UpdateLineShader();

        var matrix = transform.localToWorldMatrix;
        var stride = info.LinesPerDraw;
        var total = info.TotalLineCount;

        var props = new MaterialPropertyBlock();
        var uv = new Vector2(0.5f / info.historyLength, 0);

        for (var i = 0; i < total; i += stride)
        {
            uv.y = (0.5f + i) / total;
            props.SetVector("_BufferOffset", uv);
            Graphics.DrawMesh(
                _mesh, matrix, material, 0, null, 0, props,
                false, false);
        }
    }
Example #15
0
        void Update()
        {
            if (_needsReset) ResetResources();

            if (Application.isPlaying)
            {
                float deltaTime;
                int steps;

                if (_fixTimeStep)
                {
                    // Fixed time step.
                    deltaTime = 1.0f / _stepsPerSecond;
                    steps = Mathf.RoundToInt(Time.deltaTime * _stepsPerSecond);
                }
                else
                {
                    // Variable time step.
                    deltaTime = Time.smoothDeltaTime;
                    steps = 1;
                }

                // Time steps.
                for (var i = 0; i < steps; i++)
                {
                    _time += deltaTime;
                    StepKernel(_time, deltaTime);
                }
            }
            else
            {
                // Reset simulation state.
                Graphics.Blit(null, _positionBuffer2, _kernelMaterial, 0);
                Graphics.Blit(null, _velocityBuffer2, _kernelMaterial, 1);
                _time = 0;

                // Advance for a short period of time.
                for (var i = 0; i < 32; i++)
                {
                    _time += 0.1f;
                    StepKernel(_time, 0.1f);
                }
            }

            // Draw lines.
            UpdateLineShader();

            var matrix = transform.localToWorldMatrix;
            var stride = LinesPerDraw;
            var total = TotalLineCount;

            var props = new MaterialPropertyBlock();
            var uv = new Vector2(0.5f / _historyLength, 0);

            for (var i = 0; i < total; i += stride)
            {
                uv.y = (0.5f + i) / total;
                props.SetVector("_BufferOffset", uv);
                Graphics.DrawMesh(_mesh, matrix, _lineMaterial, 0, null, 0, props);
            }
        }
Example #16
0
    void Update()
    {
        if (_subdivided != _subdivision) RebuildMesh();

        var noiseDir = new Vector3(0.1f, 0.3f, -0.5f).normalized;
        _noiseOffset += noiseDir * (Time.deltaTime * _noiseSpeed);

        var radius = 1.0f + Reaktion.Perlin.Noise(Time.time, 23.5f) * _scaleAnimation;

        var props = new MaterialPropertyBlock();
        props.SetVector("_NoiseOffset", _noiseOffset);
        props.SetFloat("_NoiseFrequency", _noiseFrequency);
        props.SetFloat("_NoiseAmplitude", _noiseAmplitude);
        props.SetFloat("_Opacity", _opacity);
        props.SetFloat("_Radius", radius);

        Graphics.DrawMesh(
            _mesh, transform.localToWorldMatrix,
            _material, 0, null, 0, props,
            _shadowCastingMode, _receiveShadows);
    }
        void SetDestructionProps(MaterialPropertyBlock block,
                                 Transform modelTransform)
        {
            var mv = transform.TransformDirection(_motionVector);
            mv = modelTransform.InverseTransformDirection(mv);

            block.SetVector("_MotionVector", new Vector4(
                mv.x, mv.y, mv.z, mv.magnitude
            ));

            block.SetVector("_MotionParams", new Vector4(
                _directionSpread,
                _speedRandomness,
                _turbulenceFrequency,
                _turbulenceAmplitude
            ));

            block.SetVector("_RotationParams", new Vector2(
                _rotationAngle * Mathf.Deg2Rad,
                _rotationRandomness
            ));
        }
Example #18
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;
        }