AddVector() private method

private AddVector ( int nameID, Vector4 value ) : void
nameID int
value Vector4
return void
コード例 #1
0
    public virtual void LateUpdate()
    {
        if(m_id==0)
        {
            m_id = ++s_idgen;
        }
        m_local_time += Time.deltaTime;

        if (m_mpb == null)
        {
            m_renderer = GetComponent<Renderer>();
            m_trans = GetComponent<Transform>();
            m_mpb = new MaterialPropertyBlock();
            m_mpb.AddVector("_Position", Vector4.zero);
            m_mpb.AddVector("_Rotation", Vector4.zero);
            m_mpb.AddVector("_Scale", Vector4.one);
            m_mpb.AddFloat("_LocalTime", m_local_time);
            m_mpb.AddFloat("_ID", m_id);
        }

        var rot = m_trans.rotation;
        m_mpb.SetVector("_Position", m_trans.position);
        m_mpb.SetVector("_Rotation", new Vector4(rot.x, rot.y, rot.z, rot.w));
        m_mpb.SetVector("_Scale", m_trans.localScale);
        m_mpb.SetFloat("_LocalTime", m_local_time);
        for (int i = 0; i < m_params.Length; ++i)
        {
            m_mpb.SetFloat(m_params[i].key, m_params[i].value);
        }
        m_renderer.SetPropertyBlock(m_mpb);
    }
コード例 #2
0
 static public int AddVector(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.AddVector(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.AddVector(a1, a2);
             pushValue(l, true);
             return(1);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
コード例 #3
0
 public void SetOffset(Vector4 offset)
 {
     MaterialPropertyBlock props = new MaterialPropertyBlock();
     GetComponent<Renderer>().GetPropertyBlock(props);
     props.AddVector(offsetID, offset);
     GetComponent<Renderer>().SetPropertyBlock(props);
 }
コード例 #4
0
 static public int AddVector(IntPtr l)
 {
     try{
         if (matchType(l, 2, typeof(System.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.AddVector(a1, a2);
             return(0);
         }
         else if (matchType(l, 2, typeof(System.Int32), 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.AddVector(a1, a2);
             return(0);
         }
         LuaDLL.luaL_error(l, "No matched override function to call");
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
コード例 #5
0
    public virtual void OnWillRenderObject()
    {
        if(m_mpb == null) {
            m_mpb = new MaterialPropertyBlock();
            m_mpb.AddVector("_Position", Vector4.zero);
            m_mpb.AddVector("_Rotation", Vector4.zero);
            m_mpb.AddVector("_Scale", Vector4.one);
            m_renderer = GetComponent<Renderer>();
            m_trans = GetComponent<Transform>();
        }

        var rot = m_trans.rotation;
        m_mpb.SetVector("_Position", m_trans.position);
        m_mpb.SetVector("_Rotation", new Vector4(rot.x, rot.y, rot.z, rot.w));
        m_mpb.SetVector("_Scale", m_trans.localScale);
        m_renderer.SetPropertyBlock(m_mpb);
    }
コード例 #6
0
ファイル: Scene2.cs プロジェクト: Juli3nnicolas/TempOcean
    // Use this for initialization
    void Start()
    {
        // We use the default fractal color set in the Mandelbrot shader
        m_propBlock = new MaterialPropertyBlock();
        m_propBlock.AddVector("_ColorRatio", new Vector4(1.0f,1.0f,1.0f,1.0f));
        Viewport.GetComponent<Renderer>().SetPropertyBlock(m_propBlock);

        StartMusic();
    }
コード例 #7
0
 public void AddToMaterialPropertyBlock(MaterialPropertyBlock block)
 {
     UIPanelMaterialPropertyBlock.Node node = this.first;
     int num = this.count;
     while (true)
     {
         int num1 = num;
         num = num1 - 1;
         if (num1 <= 0)
         {
             break;
         }
         switch (node.type)
         {
             case UIPanelMaterialPropertyBlock.PropType.Float:
             {
                 block.AddFloat(node.property, [email protected]);
                 break;
             }
             case UIPanelMaterialPropertyBlock.PropType.Vector:
             {
                 block.AddVector(node.property, [email protected]);
                 break;
             }
             case UIPanelMaterialPropertyBlock.PropType.Color:
             {
                 block.AddColor(node.property, [email protected]);
                 break;
             }
             case UIPanelMaterialPropertyBlock.PropType.Matrix:
             {
                 block.AddMatrix(node.property, [email protected]);
                 break;
             }
         }
         node = node.next;
     }
 }
コード例 #8
0
ファイル: Sky.cs プロジェクト: elephantatwork/Secret-Game
		private void ApplyToBlock(ref MaterialPropertyBlock block, ShaderIDs bids) {
			#if USE_PROPERTY_BLOCKS
			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
		}
コード例 #9
0
ファイル: Wall.cs プロジェクト: Nabetse990/KvantWall
        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);
            }
        }
コード例 #10
0
        // Update is called once per frame
        void Update()
        {
            m_playCenter = UserProfile.SafeAreaCenter;
            m_playRadius = UserProfile.SafeAreaRadius;

            for (int i = 0; i < m_warning.Length; i++)
            {
                var w = m_warning[i];
                float wdist = m_warnDistance;

                Vector3 center = transform.position + transform.rotation * m_playCenter;

                Vector3 track;
                Quaternion r;

                if (i == 0)
                {
                    m_solver.GetTrackerTransform(Tracker.LEFT, out track, out r);
                    var con = m_avatar.GetInput(Tracker.LEFT);
                    if (con == null)
                    {
                        w.enabled = false;
                        continue;
                    }
                    w.transform.localScale = Vector3.one * 0.5f;
                    wdist *= 0.5f;
                }
                else if (i == 1)
                {
                    m_solver.GetTrackerTransform(Tracker.RIGHT, out track, out r);
                    var con = m_avatar.GetInput(Tracker.RIGHT);
                    if (con == null)
                    {
                        w.enabled = false;
                        continue;
                    }
                    w.transform.localScale = Vector3.one * 0.5f;
                    wdist *= 0.5f;
                }
                else
                {
                    var con = m_avatar.GetInput(Tracker.HEAD);
                    if (con == null)
                    {
                        w.enabled = false;
                        continue;
                    }
                    m_solver.GetEyeTransform(out track, out r);
                    w.transform.localScale = Vector3.one * 1f;
                }

                Vector3 delta = track - center;

                delta.y = 0;

                float dist = m_playRadius * m_playRadius - delta.sqrMagnitude;
                float t = 1f - dist / (m_playRadius * m_playRadius);

                if (t > 0.1f && m_playRadius != 0)
                {
                    w.enabled = true;

                    delta.Normalize();

                    Vector3 pos = delta * m_playRadius + center;
                    pos.y = track.y;

                    w.transform.position = pos;
                    w.transform.LookAt(track);

                    float heading = Mathf.Atan(delta.z / delta.x);
                    if (delta.x < 0)
                        heading += Mathf.PI;

                    float arc = heading * m_playRadius;
                    float height = pos.y;

                    if (t > 1)
                    {
                        arc *= -1;
                    }

                    float bright = wdist - dist;
                    MaterialPropertyBlock block = new MaterialPropertyBlock();

                    if (t > 1 && i == 2)
                        block.AddColor("_TintColor", new Color(0, 1, 0, 0.1f));
                    else
                        block.AddColor("_TintColor", new Color(1, 0, 0, Mathf.Clamp01(bright) * 0.75f));

                    block.AddVector("_GridOffset", new Vector4(arc, height, w.transform.lossyScale.x, w.transform.lossyScale.y));

                    w.SetPropertyBlock(block);
                }
                else
                    w.enabled = false;
            }
        }
コード例 #11
0
ファイル: Spray.cs プロジェクト: Zero-Ax/Mouse-position-Drag
        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);
            }
        }
コード例 #12
0
ファイル: Deformation.cs プロジェクト: Climberfx/Scatterer
        /**
        * Sets the shader uniforms that are necessary to project on screen the
        * given TerrainQuad. This method can set the uniforms that are specific to
        * the given quad.
        */
        public virtual void SetUniforms(TerrainNode node, TerrainQuad quad, MaterialPropertyBlock matPropertyBlock)
        {
            if(matPropertyBlock == null || node == null || quad == null) return;

            double ox = quad.GetOX();
            double oy = quad.GetOY();
            double l = quad.GetLength();
            double distFactor = (double)node.GetDistFactor();
            int level = quad.GetLevel();

            matPropertyBlock.AddVector(m_uniforms.offset, new Vector4((float)ox, (float)oy, (float)l, (float)level));

            Vector3d2 camera = node.GetLocalCameraPos();

            matPropertyBlock.AddVector(m_uniforms.camera, new Vector4(	(float)((camera.x - ox) / l), (float)((camera.y - oy) / l),
                                                                      (float)((camera.z - node.GetView().GetGroundHeight()) / (l * distFactor)),
                                                                      (float)camera.z));

            Vector3d2 c = node.GetLocalCameraPos();

            Matrix3x3d m = m_localToTangent * (new Matrix3x3d(l, 0.0, ox - c.x, 0.0, l, oy - c.y, 0.0, 0.0, 1.0));

            matPropertyBlock.AddMatrix(m_uniforms.tileToTangent, m.ToMatrix4x4());

            SetScreenUniforms(node, quad, matPropertyBlock);
        }
コード例 #13
0
        protected override void SetScreenUniforms(TerrainNode node, TerrainQuad quad, MaterialPropertyBlock matPropertyBlock)
        {
            double ox = quad.GetOX();
            double oy = quad.GetOY();
            double l = quad.GetLength();

            Vector3d2 p0 = new Vector3d2(ox, oy, R);
            Vector3d2 p1 = new Vector3d2(ox + l, oy, R);
            Vector3d2 p2 = new Vector3d2(ox, oy + l, R);
            Vector3d2 p3 = new Vector3d2(ox + l, oy + l, R);
            Vector3d2 pc = (p0 + p3) * 0.5;

            double l0 = 0.0, l1 = 0.0, l2 = 0.0, l3 = 0.0;
            Vector3d2 v0 = p0.Normalized(ref l0);
            Vector3d2 v1 = p1.Normalized(ref l1);
            Vector3d2 v2 = p2.Normalized(ref l2);
            Vector3d2 v3 = p3.Normalized(ref l3);

            Matrix4x4d deformedCorners = new Matrix4x4d(v0.x * R, v1.x * R, v2.x * R, v3.x * R,
                                                        v0.y * R, v1.y * R, v2.y * R, v3.y * R,
                                                        v0.z * R, v1.z * R, v2.z * R, v3.z * R,
                                                        1.0, 1.0, 1.0, 1.0);

            matPropertyBlock.AddMatrix(m_uniforms.screenQuadCorners, (m_localToScreen * deformedCorners).ToMatrix4x4());

            Matrix4x4d deformedVerticals = new Matrix4x4d(	v0.x, v1.x, v2.x, v3.x,
                                                          v0.y, v1.y, v2.y, v3.y,
                                                          v0.z, v1.z, v2.z, v3.z,
                                                          0.0, 0.0, 0.0, 0.0);

            matPropertyBlock.AddMatrix(m_uniforms.screenQuadVerticals, (m_localToScreen * deformedVerticals).ToMatrix4x4());
            matPropertyBlock.AddVector(m_uniforms.screenQuadCornerNorms, new Vector4((float)l0, (float)l1, (float)l2, (float)l3));

            Vector3d2 uz = pc.Normalized();
            Vector3d2 ux = (new Vector3d2(0,1,0)).Cross(uz).Normalized();
            Vector3d2 uy = uz.Cross(ux);

            Matrix4x4d ltow = node.GetLocalToWorld();

            Matrix3x3d tangentFrameToWorld = new Matrix3x3d(ltow.m[0,0], ltow.m[0,1], ltow.m[0,2],
                                                            ltow.m[1,0], ltow.m[1,1], ltow.m[1,2],
                                                            ltow.m[2,0], ltow.m[2,1], ltow.m[2,2]);

            Matrix3x3d m = new Matrix3x3d(	ux.x, uy.x, uz.x,
                                          ux.y, uy.y, uz.y,
                                          ux.z, uy.z, uz.z);

            matPropertyBlock.AddMatrix(m_uniforms.tangentFrameToWorld, (tangentFrameToWorld * m).ToMatrix4x4());
        }
コード例 #14
0
ファイル: Grass.cs プロジェクト: cupsster/KvantGrass
        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.AddTexture("_PositionTex", _positionBuffer);
            props.AddTexture("_RotationTex", _rotationBuffer);
            props.AddTexture("_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.AddVector("_BufferOffset", uv);
                Graphics.DrawMesh(
                    mesh, position, rotation,
                    material, 0, null, 0, props,
                    _castShadows, _receiveShadows);
            }

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