Пример #1
0
 void Start()
 {
     wave_equation_ = new WaveEquation();
     wave_equation_.init(256 /* width */, RenderTextureFormat.ARGB32, false /* clamp */);
     water_input_drawer_ = new WaterInputDrawer();
     water_input_drawer_.init(water_input_material_, SCALE);
 }
Пример #2
0
 void Start()
 {
     wave_equation_ = new WaveEquation();
     // wave_equation_.init(128, RenderTextureFormat.ARGB2101010, true /* clamp */);
     wave_equation_.init(128, RenderTextureFormat.ARGB32, true /* clamp */);
     color_       = new Color(0.5f, 0.4f, 0.1f, 1f);
     AuraColorId  = Shader.PropertyToID("_AuraColor");
     value_       = 0f;
     render_time_ = 0;
 }
Пример #3
0
        public void init(Transform centered_transform)
        {
            centered_transform_ = centered_transform;
            mf_            = GetComponent <MeshFilter>();
            mf_.sharedMesh = WaterSurface.Instance.getMesh();
            scale_         = WaterSurface.Instance.getScale();
            wave_equation_ = new WaveEquation();
            wave_equation_.init(256 /* width */, RenderTextureFormat.ARGB32, false /* clamp */);
            // wave_equation_.init(512 /* width */, RenderTextureFormat.R8, false /* clamp */);
            var mr = GetComponent <MeshRenderer>();

            mr.sharedMaterial = surface_material_;
        }
Пример #4
0
    void Start()
    {
        vertices_list_ = new Vector3[VERTICES_NUM];
        float prev_y = 0f;

        for (var y = 0; y < Y_NUM; y++)
        {
            float last_y = 0f;
            for (var x = 0; x < X_NUM; x++)
            {
                last_y = create_vertex(x, y, ref vertices_list_[x + y * X_NUM], prev_y, true);
            }
            prev_y = last_y;
        }
        var triangles = new int[TRIS_NUM];
        {
            var i = 0;
            for (var y = 0; y < Y_NUM - 1; y++)
            {
                for (var x = 0; x < X_NUM - 1; x++)
                {
                    triangles[i] = (y + 0) * (X_NUM) + x + 0; i++;
                    triangles[i] = (y + 1) * (X_NUM) + x + 0; i++;
                    triangles[i] = (y + 0) * (X_NUM) + x + 1; i++;
                    triangles[i] = (y + 1) * (X_NUM) + x + 0; i++;
                    triangles[i] = (y + 1) * (X_NUM) + x + 1; i++;
                    triangles[i] = (y + 0) * (X_NUM) + x + 1; i++;
                }
            }
        }
        var uvs_list = new Vector2[VERTICES_NUM];

        for (var y = 0; y < Y_NUM; y++)
        {
            for (var x = 0; x < X_NUM; x++)
            {
                uvs_list[x + y * X_NUM].x = 1.0f / (X_NUM - 1) * x;
                uvs_list[x + y * X_NUM].y = 1.0f / (Y_NUM - 1) * y;
            }
        }

        mesh_           = new Mesh();
        mesh_.name      = "WaveSurface";
        mesh_.vertices  = vertices_list_;
        mesh_.uv        = uvs_list;
        mesh_.triangles = triangles;

        if (line_render_)
        {
            int[] indices = new int[2 * triangles.Length];
            int   i       = 0;
            for (int t = 0; t < triangles.Length; t += 3)
            {
                indices[i++] = triangles[t + 0];
                indices[i++] = triangles[t + 1];
                indices[i++] = triangles[t + 1];
                indices[i++] = triangles[t + 2];
                indices[i++] = triangles[t + 2];
                indices[i++] = triangles[t + 0];
            }
            mesh_.SetIndices(indices, MeshTopology.Lines, 0);
        }
        mesh_.RecalculateBounds();

        mf_            = GetComponent <MeshFilter>();
        mf_.sharedMesh = mesh_;
        var mr = GetComponent <MeshRenderer>();

        mr.sharedMaterial = wave_surface_material_;

        var mc = GetComponent <MeshCollider>();

        mc.sharedMesh = mesh_;

        wave_equation_ = new WaveEquation();
        wave_equation_.init(512, RenderTextureFormat.R8, false);
        wave_input_drawer_ = GameObject.Find("WaveInput").GetComponent <WaveInputDrawer>();
    }