Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Shader Question

Discussion in 'Shaders' started by Sobrtonog, Jul 7, 2023.

  1. Sobrtonog

    Sobrtonog

    Joined:
    Sep 28, 2019
    Posts:
    15
    Hello :]

    Is it possible to limit how many times the vert/frag function in a shader gets called per second?

    Or is it possible to manually call the vert/frag function from a script? (like
    material.calculateRender()
    and
    material.pauseRender()
    ) or something

    I'm asking because I think it would be nice to be able to control complex shader calculations via script.

    Thanks.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,221
    Shader Answer

    Hello :]

    No. Vertex fragment shaders run as many times as they are needed for the vertices in the mesh being rendered and pixels the geometry is visible in.

    If you want to limit the calculations, use lower vertex meshes, or render to a lower resolution.

    This is actually something that is done for some effects. Render a mesh to a lower resolution render texture and do expensive calculations there. And then read the texture when rendering the mesh normally. There are also compute shaders which you can control with more granularity.
     
  3. Rukhanka

    Rukhanka

    Joined:
    Dec 14, 2022
    Posts:
    177
    No.

    No for frag function. Yes for compute shader function.

    Don't want to be rude, but seems that you don't fully understand how fragment (pixel) shaders work.
     
  4. Sobrtonog

    Sobrtonog

    Joined:
    Sep 28, 2019
    Posts:
    15
    Thanks for the responses.

    I might be overthinking some details, the poly is 2 tris - the shader does most of the calculations in the frag portion - comparing pixel's world position to some positions I pass it.

    Now that I think about it,.. I guess it wouldn't make sense for frag functions to not update each frame since the shaders would just look glitchy.

    Of course I don't :p.
     
    Last edited: Jul 7, 2023
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,221
    Of course not. That’s why people ask questions.
     
    CodePoKE and eggsamurai like this.