Example #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);
 }
Example #2
0
        public void init(Material water_input_material, bool distortion, bool line_render)
        {
            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, distortion);
            }
            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 = "WaterSurface";
            mesh_.vertices = vertices_list_;
            mesh_.uv = uvs_list;
            mesh_.triangles = triangles;

            // line mesh rendering for debug.
            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();

            water_input_drawer_ = new WaterInputDrawer();
            water_input_drawer_.init(water_input_material, SCALE);
        }