Exemple #1
0
        public void Start()
        {
            var meshGenerator = new GrassMeshGenerator();
            var mesh          = meshGenerator.GetGrassBillboardMesh(0, 1);

            var normal    = new Vector3(0.5f, 0.5f, 0).normalized;
            var rotationA = Quaternion.LookRotation(normal);
            var transf    = new MyTransformTriplet(
                new Vector3(0, 0, 0),
                rotationA.eulerAngles * Mathf.Deg2Rad,
                new Vector3(1, 1, 1));

            var matrix = transf.ToLocalToWorldMatrix();

            for (int i = 0; i < 360; i += 30)
            {
                CreateObjectDebug(mesh, matrix, i);
            }

            //var transf2 = new MyTransformTriplet(new Vector3(0,0,0), new Vector3(0, 60*Mathf.Deg2Rad, 0), new Vector3(1,1,1)  );
            //var matrix2 = transf2.ToLocalToWorldMatrix();

            //var finalMatrix = matrix * matrix2;

            //go.transform.localPosition = finalMatrix.ExtractPosition();
            //go.transform.rotation = finalMatrix.ExtractRotation();
            //go.transform.localScale = finalMatrix.ExtractScale();
        }
        private List <Grass2PositionedEntity> PositionEntitiesFromAspect(Grass2Aspect aspect, DesignBodySpotModification modification)
        {
            var flatPos = aspect.FlatPos;

            //var rotation = Quaternion.LookRotation(modification.Normal.normalized).eulerAngles * Mathf.Deg2Rad; //TODO recreate
            if (!WarningWasSaid)
            {
                Debug.Log("W4 WARNING. GRASS ROTATION IS NOT SET. DO STH!!!");
                WarningWasSaid = true;
            }
            var centerTriplet = new MyTransformTriplet(
                new Vector3(flatPos.x, 0, flatPos.y),
                Vector3.zero, //rotation,
                Vector3.one
                );

            if (modification.SpotData != null)
            {
                centerTriplet.Position = new Vector3(centerTriplet.Position.x, modification.SpotData.Height, centerTriplet.Position.z);
            }
            var centerMatrix = centerTriplet.ToLocalToWorldMatrix();

            var additionalUniforms = new UniformsPack();

            if (modification.Uniforms != null)
            {
                additionalUniforms = modification.Uniforms;
            }

            return(aspect.Entities.Select(c => new Grass2PositionedEntity()
            {
                LocalToWorldMatrix = centerMatrix * c.DeltaTransformTriplet.ToLocalToWorldMatrix(),
                Uniforms = UniformsPack.MergeTwo(c.Uniforms, additionalUniforms)
            }).ToList());
        }
Exemple #3
0
        private void CreateObjectDebug(Mesh mesh, Matrix4x4 baseMatrix, float rotation)
        {
            var transf2 = new MyTransformTriplet(new Vector3(0, 0, 0), new Vector3(0, rotation * Mathf.Deg2Rad, 0),
                                                 new Vector3(1, 1, 1));
            var matrix2     = transf2.ToLocalToWorldMatrix();
            var finalMatrix = baseMatrix * matrix2;

            var go = GameObject.CreatePrimitive(PrimitiveType.Capsule);

            go.transform.localPosition          = new Vector3(0, 0, 0);
            go.GetComponent <MeshFilter>().mesh = mesh;
            go.name = rotation.ToString();

            go.transform.localPosition = finalMatrix.ExtractPosition();
            go.transform.rotation      = finalMatrix.ExtractRotation();
            go.transform.localScale    = finalMatrix.ExtractScale();
        }
Exemple #4
0
        public void Start4()
        {
            var normal    = new Vector3(0.5f, 0.5f, 0).normalized;
            var rotationA = Quaternion.LookRotation(normal);
            var a1        = rotationA.eulerAngles;

            var tt1 = new MyTransformTriplet(Vector3.zero, rotationA.eulerAngles * Mathf.Deg2Rad,
                                             new Vector3(1, 14, 7));

            var go = GameObject.CreatePrimitive(PrimitiveType.Capsule);

            var finalMatrix = tt1.ToLocalToWorldMatrix();

            go.transform.localPosition = finalMatrix.ExtractPosition();
            go.transform.rotation      = finalMatrix.ExtractRotation();
            go.transform.localScale    = finalMatrix.ExtractScale();

            var go2 = GameObject.CreatePrimitive(PrimitiveType.Capsule);

            go2.transform.rotation   = rotationA;
            go2.transform.localScale = new Vector3(1, 14, 7);

            Debug.Log("Rot1: " + a1);
        }
Exemple #5
0
        public void Start()
        {
            var meshGenerator = new GrassMeshGenerator();
            var mesh          = meshGenerator.GetGrassBladeMesh(1);

            var material = new Material(Shader.Find("Custom/Vegetation/Grass"));

            material.SetFloat("_BendingStrength", 0.2f);
            material.SetFloat("_InitialBendingValue", 0.4f);
            material.SetFloat("_PlantBendingStiffness", 0.3f);
            material.SetVector("_WindDirection", Vector4.one);
            material.SetVector("_PlantDirection", Vector4.one);
            material.SetColor("_Color", Color.green);
            material.SetFloat("_RandSeed", 44.4f);

            var go = GameObject.CreatePrimitive(PrimitiveType.Capsule);

            go.GetComponent <MeshFilter>().mesh       = mesh;
            go.GetComponent <MeshRenderer>().material = material;

            var instancingMaterial = new Material(Shader.Find("Custom/Vegetation/Grass.Instanced"));

            instancingMaterial.enableInstancing = true;


            _globalGpuInstancingContainer = new GlobalGpuInstancingContainer();

            var commonUniforms = new UniformsPack();

            commonUniforms.SetUniform("_BendingStrength", 0.8f);
            commonUniforms.SetUniform("_WindDirection", Vector4.one);

            var instancingContainer = new GpuInstancingVegetationSubjectContainer(
                new GpuInstancerCommonData(mesh, instancingMaterial, commonUniforms),
                new GpuInstancingUniformsArrayTemplate(new List <GpuInstancingUniformTemplate>()
            {
                new GpuInstancingUniformTemplate("_Color", GpuInstancingUniformType.Vector4),
                new GpuInstancingUniformTemplate("_InitialBendingValue", GpuInstancingUniformType.Float),
                new GpuInstancingUniformTemplate("_PlantBendingStiffness", GpuInstancingUniformType.Float),
                new GpuInstancingUniformTemplate("_PlantDirection", GpuInstancingUniformType.Vector4),
                new GpuInstancingUniformTemplate("_RandSeed", GpuInstancingUniformType.Float),
            })
                );
            var bucketId = _globalGpuInstancingContainer.CreateBucket(instancingContainer);

            var uniforms = new UniformsPack();

            uniforms.SetUniform("_InitialBendingValue", 0.4f);
            uniforms.SetUniform("_PlantBendingStiffness", 0.3f);
            uniforms.SetUniform("_PlantDirection", Vector4.one);
            uniforms.SetUniform("_Color", Color.green);
            uniforms.SetUniform("_RandSeed", 44.4f);

            var msw = new MyStopWatch();

            msw.StartSegment("AddingClassic");
            for (int x = 0; x < 300; x++)
            {
                for (int y = 0; y < 300; y++)
                {
                    var myTriplet = new MyTransformTriplet(new Vector3(x, 0, y), Vector3.zero, Vector3.one);
                    _globalGpuInstancingContainer.AddInstance(bucketId, myTriplet.ToLocalToWorldMatrix(), uniforms);
                }
            }

            _globalGpuInstancingContainer.StartThread();
            _globalGpuInstancingContainer.FinishUpdateBatch();
            Debug.Log("It took: " + msw.CollectResults());
        }