Git Product home page Git Product logo

Comments (4)

MrBrixican avatar MrBrixican commented on May 23, 2024

Hmm, there's probably not a great solution to this. However, here's my idea:

batch.PushShader(custom)
    .With("Wavy", 10f);
batch.Rect(new Rect(0, 0, 32, 32), Color.Red);
batch.PopShader();

It uses a fluent interface/method chaining. PushShader() should return a struct that can be chained to set the uniforms. The uniform values will be stored/pooled in the Batcher itself through some means. The struct will merely be a reference to the Batcher and maybe some version id/index to ensure that the user is not storing the struct and using it after the initial call (this is just plain user error, though).

It's obviously not a perfect solution since any uniforms set on the shader will not be overwritten if a With() call is not used (unless we use automatic setting like you described in your first solution). Additionally, I'm not really sure what should happen on PopShader() (i.e. should values be reset to what they were).

The main thing I want to avoid is Shader[].Set() since ideally we don't want any graphics calls before Batcher.Render().

from foster.

NoelFB avatar NoelFB commented on May 23, 2024

Yeah I think I like this direction, my only concern (and maybe this is a non-issue?) is programmatically assigning values. Like if you're batching stuff from data, you can't do something like:

foreach (var (key, value) in assignments)
    batch.SetShaderParameter(key, value);

Although I suppose if the struct returned with batch.PushShader is valid until the next call you could do

var it = batch.PushShader(custom);
foreach (var (key, value) in assignments)
    it.With(key, value);

Will think about this a bit! I could even just go with the first example (batch.SetShaderParameter). That might be good enough.

from foster.

NoelFB avatar NoelFB commented on May 23, 2024

Another option is to:

  • Refactor Shader to not upload parameters immediately
  • Add a Material class which holds parameter data
  • Draw calls take a Material class which uploads the parameters on-draw
  • Batcher takes Material and makes a (pooled?) clone on-push.

(this is actually what the old foster did, if I remember correctly)

from foster.

NoelFB avatar NoelFB commented on May 23, 2024

This is now fixed as of b8ea1b5. Opted to add a Material class that is easy to Clone, and the Batcher holds an internal pool of Materials it reuses. Did require a breaking change if you use Shaders though.

from foster.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.