To canvas then to screen, why change?. See #5.

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
padicao2010
Prole
Posts: 15
Joined: Wed Jan 15, 2014 8:38 am

To canvas then to screen, why change?. See #5.

Post by padicao2010 »

I use shader to implement an animation, by changing shader parameters.
When the animation ends, the shader is set to

Code: Select all

vec4 effect(vec4 color, Image texture, vec2 tc, vec2 _)
{
	return Texel(texture, tc) * color;
}
And then I remove the shader, it change a lot.

I'm so new at shader.

My question is how can i keep the screen the same when i remove a shader.

What the shader should be like?
Last edited by padicao2010 on Wed Oct 14, 2015 3:35 pm, edited 1 time in total.
User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: What the shader is like when it does nothing?

Post by arampl »

You can bake any effects to canvas, then draw this canvas like simple image.
User avatar
Alexar
Party member
Posts: 174
Joined: Thu Feb 05, 2015 1:57 am
Location: Chengdu,China

Re: What the shader is like when it does nothing?

Post by Alexar »

i am not quite follow you, but draw things to a canvas with shader, you can deal with canvas more easily.
oh, your code

Code: Select all

vec4 effect(vec4 color, Image texture, vec2 tc, vec2 _)  
{
   return Texel(texture, tc) * color;
//just return the "color" is what you want...
//  Texel(texture, tc)==color if you draw a texture
}
padicao2010
Prole
Posts: 15
Joined: Wed Jan 15, 2014 8:38 am

Re: What the shader is like when it does nothing?

Post by padicao2010 »

Alexar wrote:i am not quite follow you, but draw things to a canvas with shader, you can deal with canvas more easily.
oh, your code

Code: Select all

vec4 effect(vec4 color, Image texture, vec2 tc, vec2 _)  
{
   return Texel(texture, tc) * color;
//just return the "color" is what you want...
//  Texel(texture, tc)==color if you draw a texture
}
Sorry, following the detail.

I use https://github.com/vrld/shine, and add a new shader, imitating colorgradesimple, as follow

Code: Select all

		extern number grade;
		vec4 effect(vec4 color, Image texture, vec2 tc, vec2 _)
		{
			return vec4(grade, grade, grade, grade) * Texel(texture, tc) * color;
		}

Code: Select all

if shader then
    shader:draw(function()
        DRAW SOMETHING
    end)
else
    DRAW SOMETHING
end
Grade is change from 0.0 to 1.0 smoothly.
When Grade is equal to or larger than 1.0f, the shader is removed.
I want to keep 'DRAW SOMTHING' looks almost the same after the shader is removed.
However, it changes a lot.

Also i change BlendMode from 'premultiplied' (colorgradesimple, vrld/shine) to 'alpha'.
Does it matter?
padicao2010
Prole
Posts: 15
Joined: Wed Jan 15, 2014 8:38 am

Re: What the shader is like when it does nothing?

Post by padicao2010 »

I do a test, remove the shader.

It seems that CASE 1:

Code: Select all

local raw = love.graphics.newCanvas()
local r, g, b, a = love.graphics.getColor()
love.graphics.setCanvas(raw)

DRAW SOMETHING

love.graphics.setColor(r, g, b, a)
love.graphics.setCanvas(nil)
love.graphics.draw(raw, 0, 0)
is not the the same with CASE 2

Code: Select all

DRAW SOMETHING
The color in CASE 2 is a little more bright then in CASE 1.

Is that right? But why?
And how to make them the same?
Attachments
test.love
A test case.
(47.99 KiB) Downloaded 181 times
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], pgimeno and 66 guests