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

Custom shader support? #57

Open
ozkriff opened this issue Jun 16, 2019 · 3 comments
Open

Custom shader support? #57

ozkriff opened this issue Jun 16, 2019 · 3 comments
Labels
feature New feature or request help wanted Extra attention is needed question Further information is requested

Comments

@ozkriff
Copy link

ozkriff commented Jun 16, 2019

Custom shaders aren't supported atm, right? Are there any plans for it?

@hecrj
Copy link
Owner

hecrj commented Jun 16, 2019

You are right, custom shaders are currently not supported.

Are there any plans for it?

This is a complicated question. Custom shaders are not really a goal, they are a tool used to obtain a specific effect in your game. I think Coffee needs to offer support to achieve these effects.

However, that does not mean Coffee will let you provide your own custom shader in GLSL or SPIR-V freely and talk directly to the GPU. This seems like a hard thing to do well without leaking internal implementation details.

I am by no means an expert in computer graphics, but I think that before deciding on a tool, we should learn about the goals first:

  • What are custom shaders used for normally? Shadows? Lighting? Anything really?
  • Can we find a pattern?
  • How does the data normally flow?
  • Do we need to offer total freedom or can we make some assumptions?
  • How would the solution fit with the current abstractions like Batch, Image, etc.?

Some random ideas:

  • Maybe we can offer an internal subset of built-in shaders to perform the most common techniques with some customization (like Mesh)?
  • A crazy one, maybe we could come up with a high-level, type-safe abstraction to combine different techniques together and combine shaders under the hood?

I think we should focus on a couple of common use cases and try to imagine how they could fit with the current graphics module. That could give us more details about the problem.

Anyway, sorry for the rant! 😅 Does this answer your question, @ozkriff ? Or would you like to know something in particular?

In any case, it may be a bit until I hit this point with my games, so feel free to share your use cases and start a discussion here!

@hecrj hecrj added feature New feature or request help wanted Extra attention is needed question Further information is requested labels Jun 16, 2019
@Zizico2
Copy link

Zizico2 commented Jun 18, 2019

While it is most certainly possible to make a good implementation of custom shaders (read GLSL), without leaking internal implementation details I agree that it is a very hard task whose benefits can mostly be achieved by just putting together and implementing common use cases. As an enthusiast I surely enjoy messing around and creating my own shaders but it is a really niche thing imo.

@Atomotron
Copy link

Atomotron commented May 7, 2020

If you want to get an idea of how the 3D world handles shader modularization, check out what Blender does. On the ground floor, it has a list of shaders whose parameters will allow you to get several common materials. For shaders that lie outside of their set, it has something called a "node editor," which is a visual boxes-and-lines editor for dataflow programming. Virtually everything you would want to do with a shader can be represented as an acyclic directed flowchart depicting what happens to colors as they're read from textures and pushed to the output.

SFML, a fairly opinionated 2D drawing library, has shaders. 0 They don't totally reinvent the concept like node systems do, but they do show how you could put them in to a 2D game engine.

Shaders themselves are an art-form, and I would disagree that totally abstracting them away is a goal. In fact, supporting GLSL might actually be considered a goal in and of itself, because a lot of cool stuff has been written in it, and I want to cut and paste! To get an idea of the existing "shader community," check out Shadertoy 1, which is full of examples of 100% 2D shaders that do amazing things with nothing more than a single quad to draw on.

I found this issue because I wanted shaders, and I am an example of someone who won't be able to use coffee because it doesn't have them. To help you make your plans, here are some use cases I am considering:

  • Lens effects that distort images as if a magnifying glass or something like that was being held over them.
  • Nonlinear color curve adjustment so that I could have the white balance change depending on lighting conditions.
  • Texture blending based on RGB values of a low-resolutuon "master texture" whose components specify the fraction of each high-resolution sub-texture to be blended in at each point. (This is a great trick for terrain in 3D games and would also work in 2D).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants