What's everyone working on? (tigsource inspired)

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
Jasoco
Inner party member
Posts: 3727
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: What's everyone working on? (tigsource inspired)

Post by Jasoco »

Nixola wrote:The lib you're talking about does pretty much what Geometries do, but requires shaders
Yeah. I just don't know how to use the quad replacement. The shader in place right now works fine, but since I haven't done enough research to replace the love.graphics.quad() function, it doesn't have anything to draw onto right now. Maybe someone could help me figure out how to use them.

Edit: In case anyone wants to look at it, this is Monkeyman's library:

Code: Select all

--By xXxMoNkEyMaNxXx
--[[Complete API----  This was made to be a module, PLEASE USE IT AS A MODULE

	.cw=false
	-Counter clockwise vertex order starting at top left.

	.cw=true
	-Clockwise vertex order starting at top left.


	.preload(loadup):

	-loadup==true sets pixel effect to polygon texturer,
	-loadup==false clears any pixel effect.
	*NOTE: preload(false) must be done to draw blank polygons after textured ones.


	.setRepeat(origin,size):
	-Makes the image repeat every 'size' starting at 'origin'.
	-The default is origin={0,0},size={1,1}.


	.quad(image,v1,v2,v3,v4) - Draws a polygon.

	-if 'image' is nil, the function will prepare to make it blank.


	.quad(v1,v2,v3,v4) - draws a polygon with no image.


	.fast(image,v1,v2,v3,v4) - draws a polygon with 'image' on it.
	-slightly(!!!) faster than quad.
	-Must include an image.
	-Must call .preload(true) beforehand.


	Info:
	Vertices are in the form {x,y}.
	Vertices go clockwise from the top left.

	v1---v2
	| img |
	v4---v3
--]]
local glsl=love.graphics.newPixelEffect[[
//Made by xXxMoNkEyMaNxXx

extern Image img;
extern vec2 v1;
extern vec2 v2;
extern vec2 v3;
extern vec2 v4;

extern vec2 p0;
extern vec2 rep;

extern number SIZEY;//So annoying

vec2 one=vec2(1.0,1.0);

number c(vec2 v1,vec2 v2)
{
	return v1.x*v2.y-v2.x*v1.y;
}
number intersect(vec2 v1,vec2 d1,vec2 v2,vec2 d2)
{
	//v1+d1*
	return c(v2-v1,d2)/c(d1,d2);
}
vec4 mask(vec4 base,vec4 over)
{
	return vec4(over.rgb*over.a+base.rgb*(1-over.a),over.a+base.a*(1-over.a));
}
vec4 effect(vec4 colour,Image UNUSED1,vec2 UNUSED2,vec2 inverted)
{
	vec2 p=vec2(inverted.x,SIZEY-inverted.y);//SO ANNOYING

	vec2 A1=normalize(v2-v1);
	vec2 A2=normalize(v3-v4);

	vec2 B1=normalize(v2-v3);
	vec2 B2=normalize(v1-v4);

	number Adiv=c(A1,A2);
	number Bdiv=c(B1,B2);

	vec2 uv;

	bvec2 eq0=bvec2(abs(Adiv)<=0.0001,abs(Bdiv)<=0.0001);
	if(eq0.x && eq0.y){
		//Both edges are parallel, therefore the shape is a parallelogram (Isometric)
		number dis=dot(p-v1,A1);

		//cos theta
		number ct=dot(A1,B1);

		//Closest point on v1->A1 to p
		vec2 pA=v1+A1*dis;

		//uv
		number r=length(p-pA)/sqrt(1-ct*ct);
		uv=vec2(1-r/length(v2-v3),(dis+r*ct)/length(v2-v1));
	}else if(eq0.x){
		//One Vanishing point occurs in numerically set scenarios in 3D, and is a feature of 2.5D

		//Horizon is A1 (=A2) from B
		vec2 Vp=v3+B1*c(v4-v3,B2)/Bdiv;

		//Some point in the distance that diagonals go to
		vec2 D=Vp+A1*intersect(Vp,A1,v4,normalize(v2-v4));

		//uv
		number u=intersect(v1,A1,Vp,normalize(p-Vp));
		number v=intersect(v1,A1,D,normalize(p-D))-u;

		number len=length(v2-v1);
		uv=vec2(len-v,u)/len;//Reversed components to match up with other one
	}else if(eq0.y){
		//If the other edge is the parallel one
		vec2 Vp=v1+A1*c(v4-v1,A2)/Adiv;
		vec2 D=Vp+B1*intersect(Vp,B1,v4,normalize(v2-v4));
		number u=intersect(v3,B1,Vp,normalize(p-Vp));
		number len=length(v2-v3);
		uv=vec2(u,len-intersect(v3,B1,D,normalize(p-D))+u)/len;
	}else{
		//Else, two vanishing points

		//*intersect(v1,A1,v4,A2)
		//*intersect(v3,B1,v4,B2)

		//Vanishing points
		vec2 A=v1+A1*c(v4-v1,A2)/Adiv;
		vec2 B=v3+B1*c(v4-v3,B2)/Bdiv;

		//Horizon
		vec2 H=normalize(A-B);

		//Pixel
		uv=vec2(intersect(v4,-H,A,normalize(p-A))/intersect(v4,-H,v2,-A1),intersect(v4,H,B,normalize(p-B))/intersect(v4,H,v2,-B1));
	}
	return mask(colour,Texel(img,mod(uv*rep+vec2(p0.x-1,p0.y),one)));
}
]]
local gl_send=glsl.send
local q=love.graphics.quad
-- local lgr = love.graphics
local setEffect=love.graphics.setPixelEffect
gl_send(glsl,"SIZEY",love.graphics.getHeight())--So annoying
gl_send(glsl,"p0",{0,0})
gl_send(glsl,"rep",{1,1})

module(...)
cw=true--clockwise
function preload(loadup)
	if loadup then
		setEffect(glsl)
	else
		setEffect()
	end
end
function setRepeat(origin,size)
	gl_send(glsl,"p0",origin)
	gl_send(glsl,"rep",size)
end
function fast(img,v1,v2,v3,v4)
	gl_send(glsl,"img",img)
	gl_send(glsl,"v1",v2)
	gl_send(glsl,"v2",v3)
	gl_send(glsl,"v3",v4)
	gl_send(glsl,"v4",v1)
	q("fill",v1[1],v1[2],v2[1],v2[2],v3[1],v3[2],v4[1],v4[2])
end
function quad(img,v1,v2,v3,v4,h)
	if h then gl_send(glsl,"SIZEY",h) end
	if img and v4 then
		setEffect(glsl)
		gl_send(glsl,"img",img)
		if cw then
			gl_send(glsl,"v1",v2)
			gl_send(glsl,"v2",v3)
			gl_send(glsl,"v3",v4)
			gl_send(glsl,"v4",v1)
		else
			gl_send(glsl,"v1",v2)
			gl_send(glsl,"v2",v1)
			gl_send(glsl,"v3",v4)
			gl_send(glsl,"v4",v3)
		end
	else
		setEffect()
	end
	-- lgr.setBlendMode("premultiplied")
	if v4 then
		q("fill",v1[1],v1[2],v2[1],v2[2],v3[1],v3[2],v4[1],v4[2])
	else--img acts as a vertex
		q("fill",img[1],img[2],v1[1],v1[2],v2[1],v2[2],v3[1],v3[2])
	end
	-- lgr.setBlendMode("alpha")
	setEffect()
end
Slightly modified by me however. I don't remember what I changed at this point.

Something tells me it'll have to be rewritten for 0.9.0 though in some way or another. But if the outcome is the same I don't care.
User avatar
slime
Solid Snayke
Posts: 3166
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: What's everyone working on? (tigsource inspired)

Post by slime »

Jasoco wrote:Or if I can somehow use geometries themselves alone to do my 3D texture perspective warping. In time it'll fall into place.
You can, but you'll either need to to do real perspective projection in the vertex shader (ncarlson has an example of that, and it's probably the preferred method) or else you'll have to do some more shader magic to get the texture coordinates to be interpolated the way you want without actually having a perspective projection.

I recommend learning about and experimenting with view and projection matrices in vertex shaders. You'll be able to do a lot with high performance in LÖVE, and vertex shaders are a practical tool used everywhere in modern rendering, rather than just a fun learning exercise.
User avatar
Jasoco
Inner party member
Posts: 3727
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: What's everyone working on? (tigsource inspired)

Post by Jasoco »

You're speaking Greek to me right now. :rofl:
User avatar
master both
Party member
Posts: 262
Joined: Tue Nov 08, 2011 12:39 am
Location: Chile

Re: What's everyone working on? (tigsource inspired)

Post by master both »

Is love.graphics.quad going to be replaced? geometry is so confusing, specially for beginners. from what I heard it was going to be kept, but it will return a geometry, is that true?
User avatar
slime
Solid Snayke
Posts: 3166
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: What's everyone working on? (tigsource inspired)

Post by slime »

master both wrote:Is love.graphics.quad going to be replaced? geometry is so confusing, specially for beginners. from what I heard it was going to be kept, but it will return a geometry, is that true?
Perhaps this discussion shouldn't be in this thread, but...

love.graphics.quad is a function which draws a polygon with 4 points. If you switch any love.graphics.quad calls with love.graphics.polygon it should behave identically. It was removed from 0.9.0 because it's both redundant and very easy to mix up with Quad objects.

Quad objects are sort of like rectangle viewports into images. Geometry objects are sort of like viewports into images that can be pretty much any shape, including a rectangle.
In 0.9.0, Quad objects have been removed completely because Geometry objects exist now, but love.graphics.newQuad is still around and will return a Geometry object which has the same vertices as a Quad object would have.
User avatar
master both
Party member
Posts: 262
Joined: Tue Nov 08, 2011 12:39 am
Location: Chile

Re: What's everyone working on? (tigsource inspired)

Post by master both »

Oh... I see now, thanks!
So... Jasoco anything new you're working on? or anything new on your 3D engine? can't wait to play with it. ^^
Last edited by master both on Fri Sep 06, 2013 11:27 am, edited 1 time in total.
User avatar
Jasoco
Inner party member
Posts: 3727
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: What's everyone working on? (tigsource inspired)

Post by Jasoco »

slime wrote:Perhaps this discussion shouldn't be in this thread, but...

love.graphics.quad is a function which draws a polygon with 4 points. If you switch any love.graphics.quad calls with love.graphics.polygon it should behave identically. It was removed from 0.9.0 because it's both redundant and very easy to mix up with Quad objects.
Well. That was easier than I thought!

I see you also removed love.graphics.triangle for the same reason. Personally I never used either of them because polygon always seemed to make more sense anyway. I also didn't even know quad existed and thought it had something to do with quads. Thanks. And now we go back on topic.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: What's everyone working on? (tigsource inspired)

Post by raidho36 »

Well-ballanced level generator is hard as T-Rex's shit.
MwfglEQ.png
MwfglEQ.png (279.19 KiB) Viewed 632 times
User avatar
Ragzouken
Citizen
Posts: 84
Joined: Fri Aug 10, 2012 7:59 am
Contact:

Re: What's everyone working on? (tigsource inspired)

Post by Ragzouken »

044.png
044.png (104.22 KiB) Viewed 3261 times
right-click + drag to connect things as inputs to others. connect the input variables at the top to the outputs at the bottom (x, y, time -> r, g, b)
Attachments
channel-designer.love
(56.78 KiB) Downloaded 155 times
Germanunkol
Party member
Posts: 712
Joined: Fri Jun 22, 2012 4:54 pm
Contact:

Re: What's everyone working on? (tigsource inspired)

Post by Germanunkol »

Very cool. What are your plans with this?
trAInsported - Write AI to control your trains
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 8 guests