Пример #1
0
 public void ApplyFast(Renderer target, int blendIndex)
 {
     // Binds IBL data, exposure, and a skybox texture globally or to a specific game object
                 #if USE_PROPERTY_BLOCKS
     if (propBlock == null)
     {
         propBlock = new MaterialPropertyBlock();
     }
     if (blendIndex == 0)
     {
         propBlock.Clear();
     }
     else
     {
         target.GetPropertyBlock(propBlock);
     }
     ApplyToBlock(ref propBlock, this.blendIDs[blendIndex]);
     target.SetPropertyBlock(propBlock);
                 #else
     //SharedMaterials are now used everywhere except through SkyAnchor
     foreach (Material mat in target.sharedMaterials)
     {
         Apply(mat, blendIndex);
     }
                 #endif
 }
Пример #2
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);
        }
    }
Пример #3
0
        public void OnDisable()
        {
            GCommon.UnregisterBeginRender(OnBeginCameraRender);
            GCommon.UnregisterBeginRenderSRP(OnBeginCameraRenderSRP);
            GTerrainData.GlobalDirty -= OnTerrainDataDirty;

            livePreviewMaterialProperties.Clear();
        }
Пример #4
0
        public static void DrawGeometryLivePreview(GStylizedTerrain t, Camera cam, Texture newHeightMap, Rect dirtyRect)
        {
            if (t.transform.rotation != Quaternion.identity ||
                t.transform.lossyScale != Vector3.one)
            {
                return;
            }

            Mesh previewMesh = GEditorSettings.Instance.livePreview.GetTriangleMesh(t.TerrainData.Geometry.MeshResolution);

            Vector3 terrainSize = new Vector3(
                t.TerrainData.Geometry.Width,
                t.TerrainData.Geometry.Height,
                t.TerrainData.Geometry.Length);

            previewPropertyBlock.Clear();
            previewPropertyBlock.SetTexture("_OldHeightMap", t.TerrainData.Geometry.HeightMap);
            previewPropertyBlock.SetTexture("_NewHeightMap", newHeightMap);
            previewPropertyBlock.SetTexture("_MainTex", newHeightMap);
            previewPropertyBlock.SetFloat("_Height", t.TerrainData.Geometry.Height);
            previewPropertyBlock.SetVector("_BoundMin", t.transform.position);
            previewPropertyBlock.SetVector("_BoundMax", t.transform.TransformPoint(terrainSize));
            Material mat = GInternalMaterials.GeometryLivePreviewMaterial;

            mat.renderQueue = 4000;

            int gridSize = t.TerrainData.Geometry.ChunkGridSize;

            for (int x = 0; x < gridSize; ++x)
            {
                for (int z = 0; z < gridSize; ++z)
                {
                    Rect uvRect = GCommon.GetUvRange(gridSize, x, z);
                    if (!uvRect.Overlaps(dirtyRect))
                    {
                        continue;
                    }
                    Vector3 localPos = new Vector3(
                        terrainSize.x * uvRect.x,
                        0f,
                        terrainSize.z * uvRect.y);
                    Vector3    worldPos = t.transform.TransformPoint(localPos);
                    Quaternion rotation = Quaternion.identity;
                    Vector3    scale    = new Vector3(terrainSize.x * uvRect.width, 1, terrainSize.z * uvRect.height);

                    Graphics.DrawMesh(
                        previewMesh,
                        Matrix4x4.TRS(worldPos, rotation, scale),
                        mat,
                        LayerMask.NameToLayer("Default"),
                        cam,
                        0,
                        previewPropertyBlock);
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Evaluates the tween and, consequently, all the shader properties at "t" [0, 1].
        /// </summary>
        /// <param name="t"></param>
        public void SampleAt(float t)
        {
            propertyBlock.Clear();

            foreach (TweenShaderProperty p in shaderProperties)
            {
                p.Evaluate(propertyBlock, t);
            }

            targetRenderer.SetPropertyBlock(propertyBlock);
        }
Пример #6
0
 public void UpdateTextureSize()
 {
     m_maskTex.Resize(
         resolutionMultiplier * Mathf.RoundToInt(transform.localScale.x * spriteRenderer.sprite.bounds.size.x),
         resolutionMultiplier * Mathf.RoundToInt(transform.localScale.y * spriteRenderer.sprite.bounds.size.y));
     m_maskTex.Apply();
     ClearMasks();
     m_propBlock.Clear();
     m_propBlock.SetTexture("_BlendMask", m_maskTex);
     m_renderer.SetPropertyBlock(m_propBlock);
 }
Пример #7
0
 public virtual void Render(Matrix4x4 matrix,
                            Color multColor, int layer = 0, Camera camera = null)
 {
     if (mEmpty)
     {
         return;
     }
     mProperty.Clear();
     mProperty.AddColor("_Color", multColor);
     Graphics.DrawMesh(
         mMesh, matrix, mMaterial, layer, camera, 0, mProperty);
 }
Пример #8
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);
        }
    }
Пример #9
0
    /// <summary>
    /// Updates the shape fill appearance.
    /// </summary>
    public void UpdateFillAppearance()
    {
        if (fill_)
        {
            if (fillType_ != FillType.Custom)
            {
                if (fillTexture_ != null)
                {
                    mpb_fill.SetTexture("_MainTex", fillTexture_);
                    mpb_fill.SetVector("_TileOff", new Vector4(fillTextrueTiling_.x, fillTextrueTiling_.y, fillTextureOffset_.x, fillTextureOffset_.y));
                }
                else
                {
                    mpb_fill.Clear();
                }

                if (fillType_ == FillType.Solid)
                {
                    fillMaterial = Resources.Load("SR_FillLinearGradient") as Material;
                    mpb_fill.SetColor("_Color1", fillColor1_);
                    mpb_fill.SetColor("_Color2", fillColor1_);
                }
                else if (fillType_ == FillType.LinearGradient)
                {
                    fillMaterial = Resources.Load("SR_FillLinearGradient") as Material;
                    mpb_fill.SetColor("_Color1", fillColor1_);
                    mpb_fill.SetColor("_Color2", fillColor2_);
                }
                else if (fillType_ == FillType.RadialGradient)
                {
                    fillMaterial = Resources.Load("SR_FillRadialGradient") as Material;
                    mpb_fill.SetColor("_Color1", fillColor1_);
                    mpb_fill.SetColor("_Color2", fillColor2_);
                }
                mpb_fill.SetFloat("_Angle", fillAngle_);
                mpb_fill.SetFloat("_Slider1", fillOffset1_);
                mpb_fill.SetFloat("_Slider2", fillOffset2_);
                mr.SetPropertyBlock(mpb_fill);
                mr.sharedMaterial = fillMaterial;
            }
            else
            {
                mpb_fill.Clear();
                mr.SetPropertyBlock(null);
                mr.sharedMaterial = customFillMaterial_;
            }
        }
        else
        {
            mr.sharedMaterial = null;
        }
    }
Пример #10
0
        public static void SetEmission(GameObject go, Color emissionColor)
        {
            emissionPropertyBlock.Clear();
            emissionPropertyBlock.SetColor("_EmissionColor", emissionColor);

            var renderers = go.GetComponentsInChildren <SkinnedMeshRenderer>(true);

            for (int i = 0; i < renderers.Length; ++i)
            {
                var r = renderers[i];
                r.SetPropertyBlock(emissionPropertyBlock);
            }
        }
Пример #11
0
    void Update()
    {
        foreach (var blink in _blinks)
        {
            if (!blink.Key)
            {
                toRemove.Add(blink.Key);
                continue;
            }
            var state = blink.Value;
            if (Time.unscaledTime > state.EndTime)
            {
                toRemove.Add(blink.Key);
                continue;
            }
            float duration = state.EndTime - state.StartTime;


            float t     = (state.EndTime - Time.unscaledTime) / duration;
            var   color = state.Color;
            color.a *= state.Curve.Evaluate(t);
            for (int i = 0; i < state.Renderers.Length; i++)
            {
                var renderer = state.Renderers[i];
                renderer.GetPropertyBlock(_block);
                _block.SetColor("_BlinkColor", color);
                renderer.SetPropertyBlock(_block);
            }
        }
        _block.Clear();
        for (int i = 0; i < toRemove.Count; i++)
        {
            var state = _blinks[toRemove[i]];

            for (int j = 0; j < state.Renderers.Length; j++)
            {
                var renderer = state.Renderers[j];
                if (!renderer)
                {
                    continue;
                }
                renderer.GetPropertyBlock(_block);
                _block.SetColor("_BlinkColor", new Color(0, 0, 0, 0));
                renderer.SetPropertyBlock(_block);
            }

            _blinks.Remove(toRemove[i]);
        }
        toRemove.Clear();
    }
Пример #12
0
    /// <summary>
    /// Updates the shape stroke appearance.
    /// </summary>
    public void UpdateStrokeAppearance()
    {
        if (stroke_)
        {
            if (strokeType_ != StrokeType.Custom)
            {
                if (strokeTexture_ != null)
                {
                    mpb_stroke.SetTexture("_MainTex", strokeTexture_);
                }
                else
                {
                    mpb_stroke.Clear();
                }

                if (strokeType_ == StrokeType.Solid)
                {
                    GradientColorKey[] gck = new GradientColorKey[2];
                    GradientAlphaKey[] gak = new GradientAlphaKey[2];

                    gck[0].color = strokeSolid_; gck[0].time = 0.0f;
                    gck[1].color = strokeSolid_; gck[1].time = 1.0f;
                    gak[0].alpha = strokeSolid_.a; gak[0].time = 0.0f;
                    gak[1].alpha = strokeSolid_.a; gak[1].time = 1.0f;

                    Gradient g = new Gradient();
                    g.SetKeys(gck, gak);

                    lr.colorGradient = g;
                }
                else if (strokeType_ == StrokeType.MultiGradient)
                {
                    lr.colorGradient = strokeGradient_;
                }
                lr.SetPropertyBlock(mpb_stroke);
                strokeMaterial    = Resources.Load("SR_Stroke") as Material;
                lr.sharedMaterial = strokeMaterial;
            }
            else
            {
                mpb_stroke.Clear();
                lr.SetPropertyBlock(null);
                lr.sharedMaterial = customStrokeMaterial_;
            }
            lr.startWidth = strokeWidth_;
            lr.endWidth   = strokeWidth_;
        }
    }
Пример #13
0
        private void SetupSplatPreview(GStylizedTerrain t)
        {
            Material mat = t.TerrainData.Shading.MaterialToRender;

            if (mat == null)
            {
                return;
            }
            int controlMapResolution = t.TerrainData.Shading.SplatControlResolution;
            int controlMapCount      = t.TerrainData.Shading.SplatControlMapCount;

            if (controlMapCount == 0)
            {
                return;
            }
            RenderTexture[] rtControls = new RenderTexture[controlMapCount];
            for (int i = 0; i < controlMapCount; ++i)
            {
                Texture2D splatControl = t.TerrainData.Shading.GetSplatControl(i);
                rtControls[i] = GetPreviewTexture(t, "splatControl" + i, controlMapResolution, splatControl.filterMode);
                GCommon.ClearRT(rtControls[i]);
            }
            instance.Internal_ApplySplat(t, rtControls);
            previewPropertyBlock.Clear();
            //for (int i = 0; i < controlMapCount; ++i)
            //{
            //    if (!string.IsNullOrEmpty(t.TerrainData.Shading.SplatControlMapPropertyName))
            //    {
            //        previewPropertyBlock.SetTexture(t.TerrainData.Shading.SplatControlMapPropertyName + i, rtControls[i]);
            //    }
            //}
        }
Пример #14
0
        internal void UpdateMaterialProperties(Renderer r, int index)
        {
            if (m_AnimatableProperties.Length == 0 || canvasRenderer.materialCount <= index)
            {
                return;
            }

            r.GetPropertyBlock(s_Mpb ?? (s_Mpb = new MaterialPropertyBlock()));
            if (s_Mpb.isEmpty)
            {
                return;
            }

            // #41: Copy the value from MaterialPropertyBlock to CanvasRenderer
            var mat = canvasRenderer.GetMaterial(index);

            if (!mat)
            {
                return;
            }

            foreach (var ap in m_AnimatableProperties)
            {
                ap.UpdateMaterialProperties(mat, s_Mpb);
            }

            s_Mpb.Clear();
        }
Пример #15
0
        /// <summary>
        /// This function is called when the behaviour becomes disabled.
        /// </summary>
        protected override void OnDisable()
        {
            // Unregister.
            s_ActiveSoftMasks.Remove(this);
            if (s_ActiveSoftMasks.Count == 0)
            {
                Canvas.willRenderCanvases -= UpdateMaskTextures;
            }

            // Reset the parent-child relation.
            for (int i = _children.Count - 1; 0 <= i; i--)
            {
                _children[i].SetParent(_parent);
            }

            _children.Clear();
            SetParent(null);

            // Destroy objects.
            _mpb.Clear();
            _mpb = null;
            _cb.Release();
            _cb = null;

            ReleaseObject(_mesh);
            _mesh = null;
            ReleaseObject(_material);
            _material = null;
            ReleaseRt(ref _softMaskBuffer);

            base.OnDisable();
            _hasStencilStateChanged = false;
        }
Пример #16
0
 public void Update()
 {
     if (block == null)
     {
         block = new MaterialPropertyBlock();
     }
     block.Clear();
     if (lightTexture != null)
     {
         block.SetVector("_Tiling", new Vector4(transform.lossyScale.x, transform.lossyScale.y,
                                                xOffset, yOffset));
         block.SetVector("_Light", new Vector4(directionShading, backWallOpacity, obscureWall ? 1 : 0,
                                               0));
         block.SetTexture("_MainTex", lightTexture);
         renderer.enabled = true;
     }
     else if (spriteTexture != null)
     {
         block.SetVector("_Light", new Vector4(directionShading, backWallOpacity, obscureWall ? 1 : 0,
                                               0));
         block.SetTexture("_MainTex", spriteTexture.texture);
         Vector2 size = spriteTexture.texture.texelSize;
         Rect    part = spriteTexture.rect;
         block.SetVector("_Tiling", new Vector4(size.x * part.width, size.y * part.height,
                                                (size.x * part.x) + xOffset, (size.y * part.y) + yOffset));
         renderer.enabled = true;
     }
     else
     {
         renderer.enabled = false;
     }
     renderer.SetPropertyBlock(block);
 }
Пример #17
0
    void LateUpdate()
    {
        float t  = 0.0f;
        float dt = Time.deltaTime;

        if (ignoreTimescale == true)
        {
            t = Time.realtimeSinceStartup;
        }
        else
        {
            t = BulletTime.time;
        }

        t = t / 20.0f;          //	To match with Time.x in the shader.

        softDirection = Vector3.Lerp(softDirection, Vector3.Normalize(lastPos - transform.position), Responsiveness * 30f * dt);
        lastPos       = transform.position;

        var wind = softDirection * Strength + transform.TransformDirection(ObjectSpaceWind);

        if (properties == null)
        {
            return;
        }

        properties.Clear();
        properties.AddVector("_Wind", wind.normalized);
        properties.AddFloat("_T", t);
        GetComponent <Renderer>().SetPropertyBlock(properties);
    }
Пример #18
0
 // Token: 0x0600017E RID: 382 RVA: 0x00008827 File Offset: 0x00006A27
 private void SetWind(MaterialPropertyBlock block, Vector4 input)
 {
     this.rend.GetPropertyBlock(block);
     block.Clear();
     block.SetVector("_Wind", input);
     this.rend.SetPropertyBlock(block);
 }
Пример #19
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);
    }
Пример #20
0
        public override void RenderExtraStuff(ushort vehicleID, ref Vehicle vehicleData, RenderManager.CameraInfo cameraInfo, InstanceID id, Vector3 position, Quaternion rotation, Vector4 tyrePosition, Vector4 lightState, Vector3 scale, Vector3 swayPosition, bool underground, bool overground)
        {
            VehicleManager instance = Singleton <VehicleManager> .instance;

            Vehicle.Flags flags = instance.m_vehicles.m_buffer[vehicleID].m_flags;
            if (m_info != null && m_info.m_vehicleAI != null && m_info.m_subMeshes != null)
            {
                Matrix4x4 bodyMatrix = m_info.m_vehicleAI.CalculateBodyMatrix(flags, ref position, ref rotation, ref scale, ref swayPosition);
                Matrix4x4 value      = m_info.m_vehicleAI.CalculateTyreMatrix(flags, ref position, ref rotation, ref scale, ref bodyMatrix);
                if ((flags & Vehicle.Flags.Inverted) != 0)
                {
                    tyrePosition.x = 0f - tyrePosition.x;
                    tyrePosition.y = 0f - tyrePosition.y;
                }
                MaterialPropertyBlock materialBlock = instance.m_materialBlock;
                materialBlock.Clear();
                materialBlock.SetMatrix(instance.ID_TyreMatrix, value);
                materialBlock.SetVector(instance.ID_TyrePosition, tyrePosition);
                materialBlock.SetVector(instance.ID_LightState, lightState);
                for (int i = 0; i < m_info.m_subMeshes.Length; i++)
                {
                    VehicleInfo.MeshInfo meshInfo = m_info.m_subMeshes[i];
                    RenderPoleMesh(vehicleID, ref vehicleData, position, rotation, swayPosition, underground, overground, instance, meshInfo, materialBlock);
                }
            }
            base.RenderExtraStuff(vehicleID, ref vehicleData, cameraInfo, id, position, rotation, tyrePosition, lightState, scale, swayPosition, underground, overground);
        }
Пример #21
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);
        }
Пример #22
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);
    }
Пример #23
0
    void LateUpdate()
    {
        if (!Application.isPlaying)
        {
            return;
        }
        if (paletteTexture == null)
        {
            return;
        }

        if (_lastpaletteTexture != paletteTexture)
        {
            CalcPixelSize();
            _lastpaletteTexture = paletteTexture;
        }

        //if(!dirtyFlag) return;
        block.Clear();
        sp.GetPropertyBlock(block);
        block.SetTexture("_PaletteTex", paletteTexture);
        block.SetVector("_PaletteTextureSize", _texturePixelSize);
        sp.SetPropertyBlock(block);

        float index = (_currentIndex + 0.5f) / paletteTexture.width;

        sp.color = new Color(color.r, map(color.g, color.b), index, color.a);


        //dirtyFlag = false;
    }
Пример #24
0
    protected virtual void OnWillRenderObject()
    {
        if (spriteRenderer == null)
        {
            spriteRenderer = GetComponent <SpriteRenderer>();
        }

        var sprite = spriteRenderer.sprite;

        if (sprite != null)
        {
            if (propertyBlock == null)
            {
                propertyBlock = new MaterialPropertyBlock();
            }

            propertyBlock.Clear();

            propertyBlock.SetTexture("_MainTex", sprite.texture);
            propertyBlock.SetTexture("_AlphaTex", AlphaTex);
            propertyBlock.SetVector("_AlphaScale", CalculateAlphaScale(sprite));
            propertyBlock.SetVector("_AlphaOffset", CalculateAlphaOffset(sprite));
            propertyBlock.SetFloat("_Sharpness", Sharpness);

            spriteRenderer.SetPropertyBlock(propertyBlock);
        }
    }
Пример #25
0
        private void CreateIndirectDrawResources()
        {
            _indirectDrawMaterial = new Material(_resources.FilledVoxelInstanceMaterial);
            _indirectDrawMaterial.enableInstancing = true;

            var volumeSize = _voxelsData.VolumeSize;

            _indirectDrawMaterial.SetVector(VoxelizationResources.VOLUME_SIZE,
                                            new Vector4(volumeSize.x, volumeSize.y, volumeSize.z, _voxelsData.VoxelSize));

            _materialPropertyBlock = new MaterialPropertyBlock();
            _materialPropertyBlock.Clear();
            _materialPropertyBlock.SetBuffer(VoxelizationResources.FILLED_VOXELS_INSTANCES,
                                             _voxelsData.FilledVoxelInstances);

            var instancedMesh = _resources.FilledVoxelInstanceMesh;
            var args          = new uint[5];

            args[0] = instancedMesh.GetIndexCount(0);
            args[1] = 0; // instance count
            args[2] = instancedMesh.GetIndexStart(0);
            args[3] = instancedMesh.GetBaseVertex(0);
            args[4] = 0; // start instance location

            _indirectDrawArgs = new ComputeBuffer(1, args.Length * sizeof(uint), ComputeBufferType.IndirectArguments);
            _indirectDrawArgs.SetData(args);
        }
 public void Clear()
 {
     MatrixList.Clear();
     UvList.Clear();
     Colors.Clear();
     MaterialPropertyBlock.Clear();
 }
Пример #27
0
    public void OnWillRenderObject()
    {
        if (m_MatProps == null)
        {
            m_MatProps = new MaterialPropertyBlock();
        }

        Camera cam = Camera.current;

        cam.depthTextureMode |= DepthTextureMode.Depth;

        m_MatProps.Clear();
        m_MatProps.AddVector("_CameraLocalPos", transform.InverseTransformPoint(cam.transform.position));
        m_MatProps.AddMatrix("_CameraToLocal", transform.worldToLocalMatrix * cam.transform.localToWorldMatrix);
        m_MatProps.AddVector("_Scale", transform.localScale);
        m_MatProps.AddFloat("_Brightness", m_Brightness);

        if (Application.isPlaying)
        {
            float time = Time.time;
            m_TimeElapsed  += m_Speed * (time - m_LastFrameTime);
            m_LastFrameTime = time;
            Shader.SetGlobalFloat("_FireTime", m_StartTime + m_TimeElapsed);
        }
        else
        {
            Shader.SetGlobalFloat("_FireTime", m_StartTime);
        }

        renderer.SetPropertyBlock(m_MatProps);
    }
        private void DrawLivePreview(GStylizedTerrain t, Camera cam)
        {
            if (t.transform.rotation != Quaternion.identity ||
                t.transform.lossyScale != Vector3.one)
            {
                return;
            }

            List <Rect> dirtyRects = new List <Rect>(instance.SplineCreator.SweepDirtyRect(t));
            Rect        r          = new Rect(0, 0, 0, 0);

            for (int i = 0; i < dirtyRects.Count; ++i)
            {
                r.xMin = Mathf.Min(r.xMin, dirtyRects[i].xMin);
                r.xMax = Mathf.Max(r.xMax, dirtyRects[i].xMax);
                r.yMin = Mathf.Min(r.yMin, dirtyRects[i].yMin);
                r.yMax = Mathf.Max(r.yMax, dirtyRects[i].yMax);
            }

            RenderTexture rt = GetPreviewTexture(t);

            instance.Internal_Apply(t, rt, instance.SplineCreator.Editor_Vertices);
            previewPropertyBlock.Clear();

            GLivePreviewDrawer.DrawMasksLivePreview(
                t, cam,
                new Texture[] { rt },
                new Color[] { GEditorSettings.Instance.splineTools.negativeHighlightColor },
                r);
        }
        private void Update()
        {
            executeCommandBuffer = false;

            if (Source.enabled)
            {
                if (meshTransforms == null || meshTransforms.Length != NumLineSteps)
                {
                    meshTransforms = new Matrix4x4[NumLineSteps];
                }

                if (colorValues == null || colorValues.Length != NumLineSteps)
                {
                    colorValues = new Vector4[NumLineSteps];
                    linePropertyBlock.Clear();
                }

                for (int i = 0; i < NumLineSteps; i++)
                {
                    float normalizedDistance = (1f / (NumLineSteps - 1)) * i;
                    colorValues[i]    = GetColor(normalizedDistance);
                    meshTransforms[i] = Matrix4x4.TRS(Source.GetPoint(normalizedDistance), Source.GetRotation(normalizedDistance), Vector3.one * GetWidth(normalizedDistance));
                }

                linePropertyBlock.SetVectorArray(colorID, colorValues);

                executeCommandBuffer = true;
            }
        }
        public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data)
        {
            if (SunLight.current == null)
            {
                return;
            }
            CommandBuffer buffer = data.buffer;
            int           pass;

            lightBlock.Clear();
            if (SunLight.current.enableShadow)
            {
                PipelineFunctions.UpdateShadowMapState(ref SunLight.shadMap, lightBlock, ref SunLight.current.settings, buffer);
                PipelineFunctions.DrawShadow(cam.cam, data.resources.gpuFrustumCulling, buffer, ref data.baseBuffer, ref SunLight.current.settings, ref SunLight.shadMap, cascadeShadowMapVP, shadowFrustumVP);
                PipelineFunctions.UpdateShadowMaskState(lightBlock, ref SunLight.shadMap, cascadeShadowMapVP);
                pass = 0;
            }
            else
            {
                pass = 1;
            }
            lightBlock.SetVector(ShaderIDs._LightFinalColor, SunLight.shadMap.light.color * SunLight.shadMap.light.intensity);
            buffer.SetRenderTarget(cam.targets.renderTargetIdentifier, cam.targets.depthIdentifier);
            lightBlock.SetVector(ShaderIDs._LightPos, -SunLight.shadMap.shadCam.forward);
            buffer.DrawMesh(GraphicsUtility.mesh, Matrix4x4.identity, shadMaskMaterial, 0, pass, lightBlock);
        }