How to make the same shader as Love2d default one

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Sasha264
Party member
Posts: 131
Joined: Mon Sep 08, 2014 7:57 am

How to make the same shader as Love2d default one

Post by Sasha264 »

Good day! :awesome:

I've noticed that when the default shader is set up using

Code: Select all

love.graphics.setShader()
it's possible to draw both a simple Image love.graphics.newImage and an ArrayImage love.graphics.newArrayImage without any additional code changes.

However, I'm struggling to create the same behavior with my custom shader. I have no problem creating a shader that works with either ArrayImage or a simple Image, but not with both. By "both," I mean not simultaneously, but with one (random) of them at a time, like in my example:

Code: Select all

-- This works just fine
love.graphics.setShader()
love.graphics.draw(image, 100, 100)
love.graphics.draw(arrayImage, 300, 100)

-- But this gives an error!
-- love.graphics.setShader(shader)
-- love.graphics.draw(image, 100, 100)
-- love.graphics.draw(arrayImage, 300, 100)
Is it even possible?

Here's the full code attached to illustrate my problem:
main.lua
(1.25 KiB) Downloaded 75 times
User avatar
Sasha264
Party member
Posts: 131
Joined: Mon Sep 08, 2014 7:57 am

Re: How to make the same shader as Love2d default one

Post by Sasha264 »

Small comment, why do I even need that:
It happened that in some of my code, I have a collection of one-layered ArrayImage-s, and I was hoping that I could draw them with all of my shaders that are designed to work with simple images. Unfortunately, I had no luck. I even tried using love.graphics.drawLayer, but it still requires an ArrayImage as the image type inside the pixel shader. And I don't want to maintain two versions of all my shaders — one for simple Images and one for one-layered ArrayImage-s.
User avatar
zorg
Party member
Posts: 3470
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: How to make the same shader as Love2d default one

Post by zorg »

Unless i misremember, löve's default behavior is to check whether the image is an array image or not, then load the appropriate "default" shader to handle it... so it's still two shaders.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
Sasha264
Party member
Posts: 131
Joined: Mon Sep 08, 2014 7:57 am

Re: How to make the same shader as Love2d default one

Post by Sasha264 »

@zorg, well... that make sense. Thank you)
User avatar
slime
Solid Snayke
Posts: 3172
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: How to make the same shader as Love2d default one

Post by slime »

Yep, there are a small number of different default shaders love uses internally depending on what's being drawn: https://github.com/love2d/love/blob/78e ... r.lua#L449
User avatar
Sasha264
Party member
Posts: 131
Joined: Mon Sep 08, 2014 7:57 am

Re: How to make the same shader as Love2d default one

Post by Sasha264 »

slime wrote: Sun Apr 16, 2023 1:30 pm Yep, there are a small number of different default shaders love uses internally depending on what's being drawn: https://github.com/love2d/love/blob/78e ... r.lua#L449
Thank you! That's good to know :)
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 7 guests