Пример #1
0
            public void Init(Factory factory)
            {
                renderers = new List<IMeshRenderer>();

                canvasRenderer = gameObject.AddComponent<UnityEngine.CanvasRenderer>();
                UpdateSortingLayerAndOrder(factory);
                UpdateLayer(factory);

                if (factory.useAdditionalColor) {
                additionalColor = UnityEngine.Color.clear;
                property = new MaterialPropertyBlock();
                additionalColorId = Shader.PropertyToID("_AdditionalColor");
                }

                buffer = new UIVertexBuffer();
            }
Пример #2
0
            public void Init(Factory factory)
            {
                useLegacyMeshGeneration = false;

                renderers = new List<IMeshRenderer>();

                UpdateSortingLayerAndOrder(factory);
                UpdateLayer(factory);

                if (factory.useAdditionalColor) {
                additionalColor = UnityEngine.Color.clear;
                property = new MaterialPropertyBlock();
                additionalColorId = Shader.PropertyToID("_AdditionalColor");
                }

                buffer = new UIVertexBuffer();
            }
Пример #3
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        // Schedule job to set animation state
        JobHandle animateJob = (new SpriteSheetAnimateJob {
            deltaTime = Time.DeltaTime
        }).Schedule(this, inputDeps);

        animateJob.Complete();

        // Need two MPBs because it will not render team2 sprites if they outnumber team1 sprites. "Property (_MainText_UV) exceeds previous array size (team2size vs team1size). Cap to previous size"
        MaterialPropertyBlock materialPropertyBlock  = new MaterialPropertyBlock();
        MaterialPropertyBlock materialPropertyBlock2 = new MaterialPropertyBlock();

        NativeArray <SpriteSheetData> team1Sprites = new NativeArray <SpriteSheetData>();
        NativeArray <SpriteSheetData> team2Sprites = new NativeArray <SpriteSheetData>();

        // TODO grab renderers from entities/chunks? store in central TeamData location?
        //SpriteRenderer team1Renderer;
        //SpriteRenderer team2Renderer;

        sample1.Begin();
        EntityQuery queryForTeamSprites = GetEntityQuery(new EntityQueryDesc
        {
            All = new[] { ComponentType.ReadOnly <SpriteSheetData>(), ComponentType.ReadOnly <Team>() },
        });

        queryForTeamSprites.SetSharedComponentFilter(new Team {
            Value = 0
        });

        team1Sprites = queryForTeamSprites.ToComponentDataArray <SpriteSheetData>(Allocator.TempJob);

        queryForTeamSprites.SetSharedComponentFilter(new Team {
            Value = 1
        });
        team2Sprites = queryForTeamSprites.ToComponentDataArray <SpriteSheetData>(Allocator.TempJob);
        sample1.End();

        // TODO: cull sprites based on camera frustrum
        // TODO: fix drawing being in wrong order. Entities that have a higher y value should be drawn first so that lower y entities are layered on top (is there some spooky optimization to draw front-back?)
        // TODO: any way to jobify some of this work? can't create MaterialPropertyBlock off main thread

        // Draw
        // Limited to 1023 matrixes per draw call
        int maxMatrixCount = 1023;

        sample2.Begin();
        for (int i = 0; i < team1Sprites.Length; i += maxMatrixCount)
        {
            int matrixCount = Unity.Mathematics.math.min(team1Sprites.Length - i, maxMatrixCount);

            matricies.Clear();
            uvs.Clear();
            for (int j = 0; j < matrixCount; j++)
            {
                matricies.Add(team1Sprites[i + j].matrix);
                uvs.Add(team1Sprites[i + j].uv);
            }
            materialPropertyBlock.SetVectorArray(shaderPropertyID, uvs);
            Graphics.DrawMeshInstanced(SpriteTest.Instance.mesh, 0, SpriteTest.Instance.material, matricies, materialPropertyBlock);
        }
        for (int i = 0; i < team2Sprites.Length; i += maxMatrixCount)
        {
            int matrixCount = Unity.Mathematics.math.min(team2Sprites.Length - i, maxMatrixCount);

            matricies.Clear();
            uvs.Clear();
            for (int j = 0; j < matrixCount; j++)
            {
                matricies.Add(team2Sprites[i + j].matrix);
                uvs.Add(team2Sprites[i + j].uv);
            }
            materialPropertyBlock2.SetVectorArray(shaderPropertyID, uvs);
            Graphics.DrawMeshInstanced(SpriteTest.Instance.mesh, 0, SpriteTest.Instance.material2, matricies, materialPropertyBlock2);
        }
        sample2.End();
        team1Sprites.Dispose();
        team2Sprites.Dispose();
        return(inputDeps);
    }
Пример #4
0
 public BitmapRenderer(LWF lwf, BitmapContext context)
     : base(lwf)
 {
     m_context = context;
     m_property = new MaterialPropertyBlock();
     m_matrix = new Matrix4x4();
     m_renderMatrix = new Matrix4x4();
     m_colorMult = new UnityEngine.Color();
     m_colorAdd = new UnityEngine.Color();
     m_blendMode = (int)Format.Constant.BLEND_MODE_NORMAL;
     m_colorId = Shader.PropertyToID("_Color");
     m_additionalColorId = Shader.PropertyToID("_AdditionalColor");
 }
Пример #5
0
 public void DrawProceduralIndirect(Matrix4x4 matrix, Material material, int shaderPass, MeshTopology topology, ComputeBuffer bufferWithArgs, [DefaultValue("0")] int argsOffset, [DefaultValue("null")] MaterialPropertyBlock properties)
 {
     INTERNAL_CALL_DrawProceduralIndirect(this, ref matrix, material, shaderPass, topology, bufferWithArgs, argsOffset, properties);
 }
Пример #6
0
 private static extern void INTERNAL_CALL_DrawProcedural(CommandBuffer self, ref Matrix4x4 matrix, Material material, int shaderPass, MeshTopology topology, int vertexCount, int instanceCount, MaterialPropertyBlock properties);
Пример #7
0
            public void Init(Factory factory)
            {
                renderers = new List<IMeshRenderer>();

                mesh = new Mesh();
                mesh.name = "LWF/" + factory.data.name;
                mesh.MarkDynamic();

                meshFilter = gameObject.AddComponent<MeshFilter>();
                meshFilter.sharedMesh = mesh;

                meshRenderer = gameObject.AddComponent<UnityEngine.MeshRenderer>();
                #if UNITY_4_6
                meshRenderer.castShadows = false;
                #else
                meshRenderer.shadowCastingMode =
                UnityEngine.Rendering.ShadowCastingMode.Off;
                #endif
                meshRenderer.receiveShadows = false;
                UpdateSortingLayerAndOrder(factory);
                UpdateLayer(factory);

                if (factory.useAdditionalColor) {
                additionalColor = UnityEngine.Color.clear;
                property = new MaterialPropertyBlock();
                additionalColorId = Shader.PropertyToID("_AdditionalColor");
                }

                buffer = new CombinedMeshBuffer();
            }
Пример #8
0
        public void DrawProcedural(Matrix4x4 matrix, Material material, int shaderPass, MeshTopology topology, int vertexCount, int instanceCount)
        {
            MaterialPropertyBlock properties = null;

            INTERNAL_CALL_DrawProcedural(this, ref matrix, material, shaderPass, topology, vertexCount, instanceCount, properties);
        }
Пример #9
0
 private void Awake()
 {
     _meshRenderer  = GetComponent <MeshRenderer>();
     _propertyBlock = new MaterialPropertyBlock();
 }
Пример #10
0
		public static void DrawMesh(Mesh mesh, Matrix4x4 matrix, Material material, int layer, Camera camera, int submeshIndex, MaterialPropertyBlock properties){}
Пример #11
0
 // Use this for initialization
 void Start()
 {
     _render = GetComponent <MeshRenderer> ();
     mb      = new MaterialPropertyBlock();
     _render.SetPropertyBlock(mb);
 }
Пример #12
0
 void Awake()
 {
     _vectorPositions = new List <Vector4>();
     _rend            = GetComponent <Renderer>();
     _mpb             = new MaterialPropertyBlock();
 }
 public static void BindNull(int shapeSlot, MaterialPropertyBlock properties)
 {
     properties.SetTexture(ParamIdSampler(shapeSlot), Texture2D.blackTexture);
 }
Пример #14
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
        }
Пример #15
0
 public abstract void ResetProperties(MaterialPropertyBlock materialProps);
Пример #16
0
 private static extern void INTERNAL_CALL_DrawProceduralIndirect(CommandBuffer self, ref Matrix4x4 matrix, Material material, int shaderPass, MeshTopology topology, ComputeBuffer bufferWithArgs, int argsOffset, MaterialPropertyBlock properties);
Пример #17
0
 void Awake()
 {
     curMesh      = GetComponent <MeshFilter>().mesh;
     curRenderer  = GetComponent <MeshRenderer>();
     curPropBlock = new MaterialPropertyBlock();
 }
Пример #18
0
 public abstract void Render(MaterialPropertyBlock materialProps);
Пример #19
0
        void SetUniforms(BuiltinSkyParameters builtinParams, ProceduralSkySettings param, bool renderForCubemap, ref MaterialPropertyBlock properties)
        {
            properties.SetTexture("_Cubemap", param.skyHDRI);
            properties.SetVector("_SkyParam", new Vector4(param.exposure, param.multiplier, param.rotation, 0.0f));

            properties.SetMatrix("_InvViewProjMatrix", builtinParams.invViewProjMatrix);
            properties.SetVector("_CameraPosWS", builtinParams.cameraPosWS);
            properties.SetVector("_ScreenSize", builtinParams.screenSize);

            m_ProceduralSkyMaterial.SetInt("_AtmosphericsDebugMode", (int)param.debugMode);

            Vector3 sunDirection = (builtinParams.sunLight != null) ? -builtinParams.sunLight.transform.forward : Vector3.zero;

            m_ProceduralSkyMaterial.SetVector("_SunDirection", sunDirection);

            var pixelRect = new Rect(0f, 0f, builtinParams.screenSize.x, builtinParams.screenSize.y);
            var scale     = 1.0f; //(float)(int)occlusionDownscale;
            var depthTextureScaledTexelSize = new Vector4(scale / pixelRect.width,
                                                          scale / pixelRect.height,
                                                          -scale / pixelRect.width,
                                                          -scale / pixelRect.height);

            properties.SetVector("_DepthTextureScaledTexelSize", depthTextureScaledTexelSize);

            /*
             * m_ProceduralSkyMaterial.SetFloat("_ShadowBias", useOcclusion ? occlusionBias : 1f);
             * m_ProceduralSkyMaterial.SetFloat("_ShadowBiasIndirect", useOcclusion ? occlusionBiasIndirect : 1f);
             * m_ProceduralSkyMaterial.SetFloat("_ShadowBiasClouds", useOcclusion ? occlusionBiasClouds : 1f);
             * m_ProceduralSkyMaterial.SetVector("_ShadowBiasSkyRayleighMie", useOcclusion ? new Vector4(occlusionBiasSkyRayleigh, occlusionBiasSkyMie, 0f, 0f) : Vector4.zero);
             * m_ProceduralSkyMaterial.SetFloat("_OcclusionDepthThreshold", occlusionDepthThreshold);
             * m_ProceduralSkyMaterial.SetVector("_OcclusionTexture_TexelSize", ???);
             */

            m_ProceduralSkyMaterial.SetFloat("_WorldScaleExponent", param.worldScaleExponent);
            m_ProceduralSkyMaterial.SetFloat("_WorldNormalDistanceRcp", 1f / param.worldNormalDistance);
            m_ProceduralSkyMaterial.SetFloat("_WorldMieNearScatterPush", -Mathf.Pow(Mathf.Abs(param.worldMieNearScatterPush), param.worldScaleExponent) * Mathf.Sign(param.worldMieNearScatterPush));
            m_ProceduralSkyMaterial.SetFloat("_WorldRayleighNearScatterPush", -Mathf.Pow(Mathf.Abs(param.worldRayleighNearScatterPush), param.worldScaleExponent) * Mathf.Sign(param.worldRayleighNearScatterPush));
            m_ProceduralSkyMaterial.SetFloat("_WorldRayleighDensity", -param.worldRayleighDensity / 100000f);
            m_ProceduralSkyMaterial.SetFloat("_WorldMieDensity", -param.worldMieDensity / 100000f);
            m_ProceduralSkyMaterial.SetFloat("_SkyDepth", 1.0f / param.maxSkyDistance);

            var rayleighColorM20 = param.worldRayleighColorRamp.Evaluate(0.00f);
            var rayleighColorM10 = param.worldRayleighColorRamp.Evaluate(0.25f);
            var rayleighColorO00 = param.worldRayleighColorRamp.Evaluate(0.50f);
            var rayleighColorP10 = param.worldRayleighColorRamp.Evaluate(0.75f);
            var rayleighColorP20 = param.worldRayleighColorRamp.Evaluate(1.00f);

            var mieColorM20 = param.worldMieColorRamp.Evaluate(0.00f);
            var mieColorO00 = param.worldMieColorRamp.Evaluate(0.50f);
            var mieColorP20 = param.worldMieColorRamp.Evaluate(1.00f);

            m_ProceduralSkyMaterial.SetVector("_RayleighColorM20", (Vector4)rayleighColorM20 * param.worldRayleighColorIntensity);
            m_ProceduralSkyMaterial.SetVector("_RayleighColorM10", (Vector4)rayleighColorM10 * param.worldRayleighColorIntensity);
            m_ProceduralSkyMaterial.SetVector("_RayleighColorO00", (Vector4)rayleighColorO00 * param.worldRayleighColorIntensity);
            m_ProceduralSkyMaterial.SetVector("_RayleighColorP10", (Vector4)rayleighColorP10 * param.worldRayleighColorIntensity);
            m_ProceduralSkyMaterial.SetVector("_RayleighColorP20", (Vector4)rayleighColorP20 * param.worldRayleighColorIntensity);

            m_ProceduralSkyMaterial.SetVector("_MieColorM20", (Vector4)mieColorM20 * param.worldMieColorIntensity);
            m_ProceduralSkyMaterial.SetVector("_MieColorO00", (Vector4)mieColorO00 * param.worldMieColorIntensity);
            m_ProceduralSkyMaterial.SetVector("_MieColorP20", (Vector4)mieColorP20 * param.worldMieColorIntensity);

            m_ProceduralSkyMaterial.SetFloat("_HeightNormalDistanceRcp", 1f / param.heightNormalDistance);
            m_ProceduralSkyMaterial.SetFloat("_HeightMieNearScatterPush", -Mathf.Pow(Mathf.Abs(param.heightMieNearScatterPush), param.worldScaleExponent) * Mathf.Sign(param.heightMieNearScatterPush));
            m_ProceduralSkyMaterial.SetFloat("_HeightRayleighNearScatterPush", -Mathf.Pow(Mathf.Abs(param.heightRayleighNearScatterPush), param.worldScaleExponent) * Mathf.Sign(param.heightRayleighNearScatterPush));
            // m_ProceduralSkyMaterial.SetFloat("_HeightRayleighDensity", -param.heightRayleighDensity / 100000f);
            // m_ProceduralSkyMaterial.SetFloat("_HeightMieDensity", -param.heightMieDensity / 100000f);
            m_ProceduralSkyMaterial.SetFloat("_HeightSeaLevel", param.heightSeaLevel);
            m_ProceduralSkyMaterial.SetVector("_HeightPlaneShift", param.heightPlaneShift);
            m_ProceduralSkyMaterial.SetFloat("_HeightDistanceRcp", 1f / param.heightDistance);
            m_ProceduralSkyMaterial.SetVector("_HeightRayleighColor", (Vector4)param.heightRayleighColor * param.heightRayleighIntensity);
            m_ProceduralSkyMaterial.SetFloat("_HeightExtinctionFactor", param.heightExtinctionFactor);

            m_ProceduralSkyMaterial.SetVector("_RayleighInScatterPct", new Vector4(1f - param.worldRayleighIndirectScatter, param.worldRayleighIndirectScatter, 0f, 0f));
            m_ProceduralSkyMaterial.SetFloat("_RayleighExtinctionFactor", param.worldRayleighExtinctionFactor);

            m_ProceduralSkyMaterial.SetFloat("_MiePhaseAnisotropy", param.worldMiePhaseAnisotropy);
            m_ProceduralSkyMaterial.SetFloat("_MieExtinctionFactor", param.worldMieExtinctionFactor);

            // Since we use the material for rendering the sky both into the cubemap, and
            // during the fullscreen pass, setting the 'PERFORM_SKY_OCCLUSION_TEST' keyword has no effect.
            properties.SetFloat("_DisableSkyOcclusionTest", renderForCubemap ? 1.0f : 0.0f);
            // We flip the screens-space Y axis in case we follow the D3D convention.
            properties.SetFloat("_FlipY", renderForCubemap ? 1.0f : 0.0f);
            // We do not render the height fog into the sky IBL cubemap.
            properties.SetFloat("_HeightRayleighDensity", renderForCubemap ? -0.0f : -param.heightRayleighDensity / 100000f);
            properties.SetFloat("_HeightMieDensity", renderForCubemap ? -0.0f : -param.heightMieDensity / 100000f);
        }
Пример #20
0
		public static void DrawMesh(Mesh mesh, Matrix4x4 matrix, Material material, int layer, Camera camera, int submeshIndex, MaterialPropertyBlock properties, bool castShadows, bool receiveShadows){}
Пример #21
0
 private void Start()
 {
     matPropertyBlock = new MaterialPropertyBlock();
 }
Пример #22
0
 private void Awake()
 {
     _materialPropertyBlock = new MaterialPropertyBlock();
 }
Пример #23
0
 private void OnValidate()
 {
     materialPropertyBlock = new MaterialPropertyBlock();
     meshRenderer          = GetComponent <MeshRenderer>();
 }
Пример #24
0
 public void DrawProcedural(Matrix4x4 matrix, Material material, int shaderPass, MeshTopology topology, int vertexCount, [DefaultValue("1")] int instanceCount, [DefaultValue("null")] MaterialPropertyBlock properties)
 {
     INTERNAL_CALL_DrawProcedural(this, ref matrix, material, shaderPass, topology, vertexCount, instanceCount, properties);
 }
Пример #25
0
 void OnResetRender()
 {
     this.sim = this.GetComponent <IFormLayer>().GetSimulation;
     mpb      = new MaterialPropertyBlock();
     SetColor(color);
 }
Пример #26
0
 private static extern void INTERNAL_CALL_DrawMesh(CommandBuffer self, Mesh mesh, ref Matrix4x4 matrix, Material material, int submeshIndex, int shaderPass, MaterialPropertyBlock properties);
Пример #27
0
 public static void SetPreviewProperty(this MaterialPropertyBlock block, PreviewProperty previewProperty)
 {
     previewProperty.SetMaterialPropertyBlockValue(block);
 }
Пример #28
0
 private static extern void INTERNAL_CALL_DrawProceduralIndirect(CommandBuffer self, ref Matrix4x4 matrix, Material material, int shaderPass, MeshTopology topology, ComputeBuffer bufferWithArgs, int argsOffset, MaterialPropertyBlock properties);
Пример #29
0
 private void Start()
 {
     props    = new MaterialPropertyBlock();
     colors   = new List <Vector4>(size * size * size);
     matrices = new Matrix4x4[size * size * size];
 }
Пример #30
0
        // Main Thread
        public void init(Material material)
        {
            alive_table_ = new bool[TRAIL_MAX];
            for (var i = 0; i < TRAIL_MAX; ++i)
            {
                alive_table_[i] = false;
            }
            spawn_index_ = 0;
            positions_   = new Vector3[NODE_NUM * TRAIL_MAX];
            widths_      = new float[TRAIL_MAX];
            types_       = new Type[TRAIL_MAX];
            update_time_ = new float[TRAIL_MAX];

            vertices_ = new Vector3[2][] { new Vector3[NODE_NUM * 2 * TRAIL_MAX], new Vector3[NODE_NUM * 2 * TRAIL_MAX], };
            normals_  = new Vector3[2][] { new Vector3[NODE_NUM * 2 * TRAIL_MAX], new Vector3[NODE_NUM * 2 * TRAIL_MAX], };
            uv2s_     = new Vector2[2][] { new Vector2[NODE_NUM * 2 * TRAIL_MAX], new Vector2[NODE_NUM * 2 * TRAIL_MAX], };
            for (var i = 0; i < TRAIL_MAX; ++i)
            {
                clear(i);
            }

            var triangles = new int[(NODE_NUM - 1) * 6 * TRAIL_MAX];

            for (var l = 0; l < TRAIL_MAX; ++l)
            {
                var lidx = l * (NODE_NUM - 1) * 6;
                var idx  = l * NODE_NUM * 2;
                for (var i = 0; i < (NODE_NUM - 1); ++i)
                {
                    triangles[lidx + i * 6 + 0] = idx + (i + 0) * 2 + 0;
                    triangles[lidx + i * 6 + 1] = idx + (i + 0) * 2 + 1;
                    triangles[lidx + i * 6 + 2] = idx + (i + 1) * 2 + 0;
                    triangles[lidx + i * 6 + 3] = idx + (i + 1) * 2 + 0;
                    triangles[lidx + i * 6 + 4] = idx + (i + 0) * 2 + 1;
                    triangles[lidx + i * 6 + 5] = idx + (i + 1) * 2 + 1;
                }
            }

            var uvs = new Vector2[NODE_NUM * 2 * TRAIL_MAX];

            for (var i = 0; i < TRAIL_MAX; ++i)
            {
                var idx = i * NODE_NUM * 2;
                for (var j = 0; j < NODE_NUM; ++j)
                {
                    uvs[idx + j * 2 + 0] = new Vector2(0f, 0f);
                    uvs[idx + j * 2 + 1] = new Vector2(1f, 0f);
                }
            }

            mesh_ = new Mesh();
            mesh_.MarkDynamic();
            mesh_.name               = "trail";
            mesh_.vertices           = vertices_[0];
            mesh_.normals            = normals_[0];
            mesh_.triangles          = triangles;
            mesh_.uv                 = uvs;
            mesh_.bounds             = new Bounds(Vector3.zero, Vector3.one * 99999999);
            material_                = material;
            material_property_block_ = new MaterialPropertyBlock();
#if UNITY_5_3
            material_.SetColor("_Colors0", new Color(0f, 0f, 0f, 0f));     // None
            material_.SetColor("_Colors1", new Color(0f, 0f, 0f, 0f));     // NoneA
            material_.SetColor("_Colors2", new Color(0.1f, 0.6f, 1f, 1f)); // Player
            material_.SetColor("_Colors3", new Color(0.1f, 0.6f, 1f, 0f)); // PlayerA
            material_.SetColor("_Colors4", new Color(0.1f, 1f, 0.5f, 1f)); // Missile
            material_.SetColor("_Colors5", new Color(0.1f, 1f, 0.5f, 0f)); // MissileA
#else
            var col_list = new Vector4[] {
                new Vector4(0f, 0f, 0f, 0f),         // None
                new Vector4(0f, 0f, 0f, 0f),         // NoneA
                new Vector4(0.1f, 0.6f, 1f, 1f),     // Player
                new Vector4(0.1f, 0.6f, 1f, 0f),     // PlayerA
                new Vector4(0.1f, 1f, 0.5f, 1f),     // Missile
                new Vector4(0.1f, 1f, 0.5f, 0f),     // MissileA
            };
            material_property_block_.SetVectorArray("_Colors", col_list);
#endif
        }
Пример #31
0
		public void SetPropertyBlock(MaterialPropertyBlock properties){}
Пример #32
0
 private static extern void INTERNAL_CALL_DrawProcedural(CommandBuffer self, ref Matrix4x4 matrix, Material material, int shaderPass, MeshTopology topology, int vertexCount, int instanceCount, MaterialPropertyBlock properties);
Пример #33
0
		private static void INTERNAL_CALL_AddColor(MaterialPropertyBlock self, int nameID, ref Color value){}
Пример #34
0
        void LateUpdate()
        {
            //If no MeshRenderer is selected then return.
            if (meshRenderer == null)
            {
                return;
            }

            //If _mpb is null then create a new Material Property Block.
            if (_mpb == null)
            {
                _mpb = new MaterialPropertyBlock();
            }

            //Calculate the velocity. Store the current position calculating the velocity next update.
            Vector3 velocity = (transform.position - _lastPosition) / Time.deltaTime;

            _lastPosition = transform.position;

//        If the sphere is position low enough to be colliding with the ground...
            if (ball.DistanceToPlayer < collisionRadius)
            {
                //Calculate how mush the sphere needs to be squashed to avoid intersecting with the ground.
                var targetSquash = (collisionRadius - ball.DistanceToPlayer) / collisionRadius;

                //Store the squash velocity.
                _squashVelocity = targetSquash - _squash;

                //Store the current squash value.
                _squash = targetSquash;
            }
            else
            {
                //Calculate the desired squash amount based on the current Y axis velocity.
                float targetSquash = -Mathf.Abs(velocity.magnitude) * velocityStretch;

                //Adjust the squash velocity.
                _squashVelocity += (targetSquash - _squash) * strength * Time.deltaTime;

                //Apply dampening to the squash velocity.
                _squashVelocity = ((_squashVelocity / Time.deltaTime) * (1f - dampening)) * Time.deltaTime;

                //Apply the velocity to the squash value.
                _squash += _squashVelocity;
            }

            /*
             *
             * //If testing then...
             * if (Test)
             * {
             *  //Set the squash value to equal the debugging squash value and set the squash velocity to zero.
             *  _squash = Squash;
             *  _squashVelocity = 0f;
             * }
             */

            //Update the material property block with the squash and radius value.
            _mpb.SetFloat(SquashID, _squash);
            _mpb.SetFloat(RadiusID, collisionRadius);

            //Set the material property block on the MeshRenderer.
            meshRenderer.SetPropertyBlock(_mpb);
        }
Пример #35
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(UOffset, 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.right * XOffset;
            position += transform.forward * YOffset;

            // Draw mesh segments.
            for (var i = 0; i < _totalRows; i += _rowsPerSegment)
            {
                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);
                }
            }
        }
Пример #36
0
		private static void INTERNAL_CALL_AddVector(MaterialPropertyBlock self, int nameID, ref Vector4 value){}
Пример #37
0
        public static void SetPropertyBlock(GameObject host, MaterialPropertyBlock block)
        {
            Renderer renderer = host.GetComponent <Renderer>();

            renderer.SetPropertyBlock(block);
        }
Пример #38
0
		private static void INTERNAL_CALL_AddMatrix(MaterialPropertyBlock self, int nameID, ref Matrix4x4 value){}
Пример #39
0
    /// <summary>
    /// Update the image that should be displayed in this slot to display the sprite of the specified item.
    ///
    /// If hidden, effect will not be visible until this slot is unhidden
    ///
    /// </summary>
    /// <param name="item">game object to use to determine what to show in this slot</param>
    /// <param name="color">color tint to apply</param>
    public void UpdateImage(GameObject item = null, Color?color = null)
    {
        bool nullItem   = item == null;
        bool forceColor = color != null;

        if (nullItem && Item != null)
        {         // Case for when we have a hovered image and insert, then stop hovering
            return;
        }

        // If player is cuffed, a special icon appears on his hand slots, exit without changing it.
        if ((namedSlot == NamedSlot.leftHand || namedSlot == NamedSlot.rightHand) &&
            PlayerManager.LocalPlayerScript.playerMove.IsCuffed)
        {
            return;
        }

        if (!nullItem)
        {
            //determine the sprites to display based on the new item
            var spriteRends = item.GetComponentsInChildren <SpriteRenderer>();
            if (image == null)
            {
                image = GetComponent <Image>();
            }

            var colorSync = item.GetComponent <SpriteColorSync>();
            if (colorSync != null)
            {                   //later find a way to remove this listener when no longer needed
                colorSync.OnColorChange.AddListener(TrackColor);

                void TrackColor(Color newColor)
                {
                    if (colorSync.SpriteRenderer != null &&
                        colorSync.SpriteRenderer.sprite == image.sprite)
                    {
                        image.color = newColor;
                    }
                }
            }

            ItemAttributesV2 itemAttrs = item.GetComponent <ItemAttributesV2>();

            spriteRends  = spriteRends.Where(x => x.sprite != null && x != Highlight.instance.spriteRenderer).ToArray();
            sprite       = spriteRends[0].sprite;
            image.sprite = sprite;
            image.color  = spriteRends[0].color;
            MaterialPropertyBlock pb = new MaterialPropertyBlock();
            spriteRends[0].GetPropertyBlock(pb);
            bool isPaletted = pb.GetInt("_IsPaletted") > 0;
            if (itemAttrs.ItemSprites.InventoryIcon != null && itemAttrs.ItemSprites.IsPaletted)
            {
                image.material.SetInt("_IsPaletted", 1);
                image.material.SetColorArray("_ColorPalette", itemAttrs.ItemSprites.Palette.ToArray());
            }
            else
            {
                image.material.SetInt("_IsPaletted", 0);
            }


            if (spriteRends.Length > 1)
            {
                if (spriteRends[1].sprite != null)
                {
                    SetSecondaryImage(spriteRends[1].sprite);
                    secondaryImage.color = spriteRends[1].color;
                }
            }
            else
            {
                // reset from prev secondary image
                SetSecondaryImage(null);
            }

            //determine if we should show an amount
            var stack = item.GetComponent <Stackable>();
            if (stack != null && stack.Amount > 1 && amountText)
            {
                amountText.enabled = true;
                amountText.text    = stack.Amount.ToString();
            }
            else if (stack != null && stack.Amount <= 1 && amountText)
            {
                //remove the stack display
                amountText.enabled = false;
            }
        }
        else
        {
            //no object was passed, so clear out the sprites
            Clear();
        }

        if (forceColor)
        {
            image.color = color.GetValueOrDefault(Color.white);
        }

        image.enabled        = !nullItem && !hidden;
        image.preserveAspect = !nullItem && !hidden;

        if (secondaryImage)
        {
            if (forceColor)
            {
                secondaryImage.color = color.GetValueOrDefault(Color.white);
            }

            secondaryImage.enabled        = secondaryImage.sprite != null && !nullItem && !hidden;
            secondaryImage.preserveAspect = !nullItem && !hidden;
        }
    }
Пример #40
0
		public static void DrawMesh(Mesh mesh, Vector3 position, Quaternion rotation, Material material, int layer, Camera camera, int submeshIndex, MaterialPropertyBlock properties, bool castShadows, bool receiveShadows){}
Пример #41
0
        public VegetationItemModelInfo(VegetationItemInfoPro vegetationItemInfo, EnvironmentSettings environmentSettings, List <GameObject> windSamplerList, int cameraCount)
        {
            EnvironmentSettings = environmentSettings;
            VegetationItemInfo  = vegetationItemInfo;
            VegetationModel     = vegetationItemInfo.VegetationPrefab;

            if (vegetationItemInfo.PrefabType == VegetationPrefabType.Texture)
            {
                VegetationModel = Resources.Load("DefaultGrassPatch") as GameObject;
            }

            if (VegetationModel == null)
            {
                VegetationModel = Resources.Load("MissingVegetationItemCube") as GameObject;
                Debug.LogError("The vegetation prefab of item: " + vegetationItemInfo.Name + " is missing. Please replace or delete VegetationItem.");
            }

            DistanceBand = vegetationItemInfo.GetDistanceBand();

#if UNITY_EDITOR
            MaterialUtility.EnableMaterialInstancing(VegetationModel);
#endif
            SelectedVegetationModelLOD0 = MeshUtils.SelectMeshObject(VegetationModel, LODLevel.LOD0);
            SelectedVegetationModelLOD1 = MeshUtils.SelectMeshObject(VegetationModel, LODLevel.LOD1);
            SelectedVegetationModelLOD2 = MeshUtils.SelectMeshObject(VegetationModel, LODLevel.LOD2);
            SelectedVegetationModelLOD3 = MeshUtils.SelectMeshObject(VegetationModel, LODLevel.LOD3);

            ShaderControler = ShaderSelector.GetShaderControler(vegetationItemInfo.ShaderName);
            if (ShaderControler != null)
            {
                ShaderControler.Settings = vegetationItemInfo.ShaderControllerSettings;
            }
            LODCount = MeshUtils.GetLODCount(VegetationModel, ShaderControler);

            CreateCameraWindSamplerItems(windSamplerList);

            if (ShaderControler != null)
            {
                LODFadePercentage = ShaderControler.Settings.LODFadePercentage;
                LODFadeCrossfade  = ShaderControler.Settings.LODFadeCrossfade;
            }

            VegetationMeshLod0 = GetVegetationMesh(VegetationModel, LODLevel.LOD0);
            VegetationMeshLod1 = GetVegetationMesh(VegetationModel, LODLevel.LOD1);
            VegetationMeshLod2 = GetVegetationMesh(VegetationModel, LODLevel.LOD2);
            VegetationMeshLod3 = GetVegetationMesh(VegetationModel, LODLevel.LOD3);

            VegetationRendererLOD0  = SelectedVegetationModelLOD0.GetComponentInChildren <MeshRenderer>();
            VegetationMaterialsLOD0 = CreateMaterials(VegetationRendererLOD0.sharedMaterials, 0);

            VegetationRendererLOD1  = SelectedVegetationModelLOD1.GetComponentInChildren <MeshRenderer>();
            VegetationMaterialsLOD1 = CreateMaterials(VegetationRendererLOD1.sharedMaterials, 1);

            VegetationRendererLOD2  = SelectedVegetationModelLOD2.GetComponentInChildren <MeshRenderer>();
            VegetationMaterialsLOD2 = CreateMaterials(VegetationRendererLOD2.sharedMaterials, 2);

            VegetationRendererLOD3  = SelectedVegetationModelLOD3.GetComponentInChildren <MeshRenderer>();
            VegetationMaterialsLOD3 = CreateMaterials(VegetationRendererLOD3.sharedMaterials, 3);

            if (vegetationItemInfo.PrefabType == VegetationPrefabType.Texture)
            {
                SetGrassTexture(VegetationMaterialsLOD0, vegetationItemInfo.VegetationTexture);
                SetGrassTexture(VegetationMaterialsLOD1, vegetationItemInfo.VegetationTexture);
                SetGrassTexture(VegetationMaterialsLOD2, vegetationItemInfo.VegetationTexture);
                SetGrassTexture(VegetationMaterialsLOD3, vegetationItemInfo.VegetationTexture);
            }

            VegetationMaterialPropertyBlockLOD0 = new MaterialPropertyBlock();
            VegetationRendererLOD0.GetPropertyBlock(VegetationMaterialPropertyBlockLOD0);
            if (VegetationMaterialPropertyBlockLOD0 == null)
            {
                VegetationMaterialPropertyBlockLOD0 = new MaterialPropertyBlock();
            }

            VegetationMaterialPropertyBlockLOD1 = new MaterialPropertyBlock();
            VegetationRendererLOD1.GetPropertyBlock(VegetationMaterialPropertyBlockLOD1);
            if (VegetationMaterialPropertyBlockLOD1 == null)
            {
                VegetationMaterialPropertyBlockLOD1 = new MaterialPropertyBlock();
            }

            VegetationMaterialPropertyBlockLOD2 = new MaterialPropertyBlock();
            VegetationRendererLOD2.GetPropertyBlock(VegetationMaterialPropertyBlockLOD2);
            if (VegetationMaterialPropertyBlockLOD2 == null)
            {
                VegetationMaterialPropertyBlockLOD2 = new MaterialPropertyBlock();
            }

            VegetationMaterialPropertyBlockLOD3 = new MaterialPropertyBlock();
            VegetationRendererLOD3.GetPropertyBlock(VegetationMaterialPropertyBlockLOD3);
            if (VegetationMaterialPropertyBlockLOD3 == null)
            {
                VegetationMaterialPropertyBlockLOD3 = new MaterialPropertyBlock();
            }

            VegetationMaterialPropertyBlockShadowsLOD0 = new MaterialPropertyBlock();
            VegetationRendererLOD0.GetPropertyBlock(VegetationMaterialPropertyBlockShadowsLOD0);
            if (VegetationMaterialPropertyBlockShadowsLOD0 == null)
            {
                VegetationMaterialPropertyBlockShadowsLOD0 = new MaterialPropertyBlock();
            }

            VegetationMaterialPropertyBlockShadowsLOD1 = new MaterialPropertyBlock();
            VegetationRendererLOD1.GetPropertyBlock(VegetationMaterialPropertyBlockShadowsLOD1);
            if (VegetationMaterialPropertyBlockShadowsLOD1 == null)
            {
                VegetationMaterialPropertyBlockShadowsLOD1 = new MaterialPropertyBlock();
            }

            VegetationMaterialPropertyBlockShadowsLOD2 = new MaterialPropertyBlock();
            VegetationRendererLOD2.GetPropertyBlock(VegetationMaterialPropertyBlockShadowsLOD2);
            if (VegetationMaterialPropertyBlockShadowsLOD2 == null)
            {
                VegetationMaterialPropertyBlockShadowsLOD2 = new MaterialPropertyBlock();
            }

            VegetationMaterialPropertyBlockShadowsLOD3 = new MaterialPropertyBlock();
            VegetationRendererLOD3.GetPropertyBlock(VegetationMaterialPropertyBlockShadowsLOD3);
            if (VegetationMaterialPropertyBlockShadowsLOD3 == null)
            {
                VegetationMaterialPropertyBlockShadowsLOD3 = new MaterialPropertyBlock();
            }

            LOD1Distance = GetLODDistance(VegetationModel, 0);
            LOD2Distance = GetLODDistance(VegetationModel, 1);
            LOD3Distance = GetLODDistance(VegetationModel, 2);

            vegetationItemInfo.Bounds = MeshUtils.CalculateBoundsInstantiate(VegetationModel);

            float maxScaleMultiplier = Mathf.Max(new float[] { vegetationItemInfo.ScaleMultiplier.x, vegetationItemInfo.ScaleMultiplier.y, vegetationItemInfo.ScaleMultiplier.z });
            BoundingSphereRadius = (vegetationItemInfo.Bounds.extents.magnitude * VegetationItemInfo.MaxScale * VegetationItemInfo.YScale * maxScaleMultiplier) + 5;



            CreateCameraBuffers(cameraCount);

            HeightRuleCurveArray = new NativeArray <float>(4096, Allocator.Persistent);
            UpdateHeightRuleCurve();


            SteepnessRuleCurveArray = new NativeArray <float>(4096, Allocator.Persistent);
            UpdateSteepnessRuleCurve();

            //DistanceFalloffCurveArray = new NativeArray<float>(256, Allocator.Persistent);
            //UpdateDistanceFalloutCurve();

            if (vegetationItemInfo.VegetationType == VegetationType.Tree)
            {
                CreateBillboardMaterial();
            }
        }
Пример #42
0
		private static extern void INTERNAL_CALL_DrawMesh(CommandBuffer self, Mesh mesh, ref Matrix4x4 matrix, Material material, int submeshIndex, int shaderPass, MaterialPropertyBlock properties);
Пример #43
0
        public void DrawMesh(Mesh mesh, Matrix4x4 matrix, Material material, int submeshIndex, int shaderPass)
        {
            MaterialPropertyBlock properties = null;

            INTERNAL_CALL_DrawMesh(this, mesh, ref matrix, material, submeshIndex, shaderPass, properties);
        }
Пример #44
0
 public BitmapRenderer(LWF lwf, BitmapContext context)
     : base(lwf)
 {
     m_context = context;
     m_property = new MaterialPropertyBlock();
     m_matrix = new Matrix4x4();
     m_renderMatrix = new Matrix4x4();
     m_colorMult = new UnityEngine.Color();
     #if LWF_USE_ADDITIONALCOLOR
     m_colorAdd = new UnityEngine.Color();
     #endif
 }
Пример #45
0
 public void DrawMesh(Mesh mesh, Matrix4x4 matrix, Material material, [DefaultValue("0")] int submeshIndex, [DefaultValue("-1")] int shaderPass, [DefaultValue("null")] MaterialPropertyBlock properties)
 {
     INTERNAL_CALL_DrawMesh(this, mesh, ref matrix, material, submeshIndex, shaderPass, properties);
 }