Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize palette lookup #43

Closed
MaxGraey opened this issue Aug 31, 2021 · 4 comments · Fixed by #44
Closed

Optimize palette lookup #43

MaxGraey opened this issue Aug 31, 2021 · 4 comments · Fixed by #44
Labels
enhancement New feature or request

Comments

@MaxGraey
Copy link
Contributor

MaxGraey commented Aug 31, 2021

I see palette uses texture2D texture now. What about change it to texture1D? While wasm4 support only 4 palette slots (2-bit palette) I guess it could be even simpler approach and pass this four colours via 4 uniforms and use something like this:

// palette
uniform vec2 p0;
uniform vec2 p1;
uniform vec2 p2;
uniform vec2 p3;

uniform sampler2D framebuffer;
varying vec2 framebufferCoord;

vec4 lookup(float img, vec4 p0, vec4 p1, vec4 p2, vec4 p3) {
   // not sure about implementation. Just basic idea
   // instead "mix" it could be "step"
   vec4 p;
   p = mix(p0, p1, mix(0.0,       1.0 / 3.0, img));
   p = mix(p,  p2, mix(1.0 / 3.0, 2.0 / 3.0, img));
   p = mix(p,  p3, mix(2.0 / 3.0,       1.0, img));
   return p;
}

void main() {
  gl_FragColor = lookup(texture2D(framebuffer, framebufferCoord).r, p0, p1, p2, p3);
}
@aduros
Copy link
Owner

aduros commented Aug 31, 2021

That's an interesting idea! Do you think this would be faster than doing the palette texture lookup? I'm guessing yes but I'm not sure.

About texture1D, I don't think it's supported in WebGL.

@aduros aduros added the enhancement New feature or request label Aug 31, 2021
@MaxGraey
Copy link
Contributor Author

MaxGraey commented Aug 31, 2021

That's an interesting idea! Do you think this would be faster than doing the palette texture lookup

Yes, definitely. Dependent random texture reads pretty expensive, especially on mobile phones

About texture1D, I don't think it's supported in WebGL.

Yeah, totally forget about that.

@aduros
Copy link
Owner

aduros commented Aug 31, 2021

Sounds great, a PR would be very welcome 😄

@MaxGraey MaxGraey changed the title Optimize Palette Optimize palette lookup Aug 31, 2021
@MaxGraey
Copy link
Contributor Author

If anyone has a desire to do PR, feel free to do so =)

@aduros aduros linked a pull request Sep 1, 2021 that will close this issue
@aduros aduros closed this as completed in #44 Sep 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants