/
/
/ "BRO TIGER"2017-09-03 10:15:35
C++ / C#
/ "BRO TIGER", 2017-09-03 10:15:35

Unity3D quirks or GFX.WaitForPresent?

Good day Toaster! I wondered about optimizing my project and checking scripts, everything was tested on Stump (Pentium CPU B970 2.30 GHz) at a resolution of 800x450 (Not the best hardware for testing) And while checking, I noticed an interesting thing gfx.waitforpersent related to Rendering ... I still don’t I made a script for waves a long time ago (You will understand further why I told about this script), but because of gfx 45 FPS and a drawdown of up to 30 FPS...
I turned off VSync, I thought that everything would be lost... gfx disappeared, but my script came to replace it because of which the same drawdowns began, but I didn’t understand why it takes so many percent in the Update if the recalculation of verticals is 2.8%... Screenshot
:
c4034cf75e7040368aeb413192f0405b.png
Disabled the script and gfx.waitforpresent again, but the optimization appeared 70 FPS with VSync and Script turned off.. .
Screen;
32ac89231738473c8a9236c7008aed32.png
Script:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using ArchimedsLab;

public class Waves : MonoBehaviour
{

    public float waveHeight = 10.0f;
    public float speed = 1.0f;
    public float waveLength = 1.0f;
    public float noiseStrength = 4.0f;
    public float noiseWalk = 1.0f;
    public float randomHeight = 0.2f;
    public float randomSpeed = 5.0f;
    public float noiseOffset = 20.0f;


    private Vector3[] baseHeight;
    private Vector3[] vertices;
    private List<float> perVertexRandoms = new List<float>();
    private Mesh mesh;


    void Awake()
    {
        mesh = GetComponent<MeshFilter>().mesh;
        if (baseHeight == null)
        {
            baseHeight = mesh.vertices;
        }

        for (int i = 0; i < baseHeight.Length; i++)
        {
            perVertexRandoms.Add(Random.value * randomHeight);
        }
    }

    void Update()
    {
        if (vertices == null)
        {
            vertices = new Vector3[baseHeight.Length];
        }

        for (int i = 0; i < vertices.Length; i++)
        {
            Vector3 vertex = baseHeight[i];
            Random.seed = (int)((vertex.x + noiseOffset) * (vertex.x + noiseOffset) + (vertex.y + noiseOffset) * (vertex.y + noiseOffset));
            vertex.z += Mathf.Sin(Time.time * speed + baseHeight[i].x * waveLength + baseHeight[i].z * waveLength) * waveHeight;
            vertex.z += Mathf.Sin(Mathf.Cos(Random.value * 1.0f) * randomHeight * Mathf.Cos(Time.time * randomSpeed * Mathf.Sin(Random.value * 1.0f)));
            vertex.z += Mathf.PerlinNoise(baseHeight[i].x + Mathf.Cos(Time.time * 0.1f) + noiseWalk, baseHeight[i].z + Mathf.Sin(Time.time * 0.1f)) * noiseStrength;
            vertices[i] = vertex;
        }
        mesh.vertices = vertices;
        mesh.RecalculateNormals();
    }
}

Bug or Feature? I don’t know what to do, for the first time I encounter optimization)
Thank you in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Gaydak, 2017-09-03
@BRO_TIGER

gfx.waitforpersent - and similar calls in the profiler just indicate that a pc or video is waiting for a video or a pc (respectively).
That is, something is a bottleneck and does not allow to work at full capacity.
In your case, apparently, the video card would have time to draw faster, but the percent is busy with something and does not give data so often for rendering. Turning off the script with the waves - they removed the calculations from the processor apparently .. and there were more frames.
Well, here, as it were, it is obvious that you have too many calculations in Updeite. so many multiplications .. and every frame. and on each vertex of the mesh, probably not the simplest one ..

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question