Textured Polygons for All!

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
zorg
Party member
Posts: 1898
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Textured Polygons for All!

Post by zorg » Wed Jun 28, 2017 9:58 pm

Also please use [ code ] [ /code ] blocks, otherwise the posted code is a bit unreadable.
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.

ghurk
Prole
Posts: 15
Joined: Tue Apr 25, 2017 11:05 pm

Re: Textured Polygons for All!

Post by ghurk » Wed Jul 12, 2017 2:29 pm

Anyone know how are data stored in TransformMatrix?
modified the shader so that i am able to draw like this:

Code: Select all

	texture.setVertices( v[1],v[2],v[3],v[4] ) --same as mesh vertices now
	
	texture.preload(true)
		love.graphics.translate(120, 100)
		love.graphics.draw( mesh, 0, 200, 0, 1, 1)
	texture.preload(false)
but still need to find out how to pull out rotation and scale data from matrix. thanks. (still need to scale and rotate)
*achieved with:

Code: Select all

vec2 positionData = vec2( TransformMatrix[3][0], TransformMatrix[3][1] );
vec2 screen = screen_coords-positionData;
where "screen_coords" is "inverted" then renamed to "p" in original shader, but thats it yea.
and then basically anything that is "p" in original shader is now "screen" in my shader.

when it comes to scaling, when i set scale (both x and y) to "3" on mesh, i know i need to do this:

Code: Select all

vec2 screen = (screen_coords-positionData)/3;
but none of matrix pairs match this result so am in slump here

**solved:

//TransformMatrix[0][0] = vec2 containing both data

Code: Select all

vec2 scaleData = vec2( TransformMatrix[0][0] );
vec2 screen = (screen_coords-positionData)/scaleData;
this enables mesh scale and also love.graphics.scale()

User avatar
Davidobot
Party member
Posts: 1126
Joined: Sat Mar 31, 2012 5:18 am
Location: Game-Dev. Land
Contact:

Re: Textured Polygons for All!

Post by Davidobot » Wed Jul 12, 2017 6:31 pm

ghurk wrote:
Wed Jul 12, 2017 2:29 pm
Anyone know how are data stored in...
I'm not sure what you're saying here, but did you manage to improve the library or speed it up? If so, it would be greatly appreciated by a number of us here if you posted your changed library. :3
My library:
LovelyMoon

Check out my current project:
Raycaster

Oh hey, I have a website now!

ghurk
Prole
Posts: 15
Joined: Tue Apr 25, 2017 11:05 pm

Re: Textured Polygons for All!

Post by ghurk » Thu Jul 13, 2017 11:20 pm

actually i still have 3 steps left so not ready to post here yet.
1. decipher the data and extract+apply both rotation and skew in pixel shader.
2. use mesh vertex data instead sending them as extras for pixel shader.
at this point it will be able to save at least the amount u need to perform additional computations on final positions coming from the scaling, rotating and buddies.
also sending the data as draw(mesh) means all color settings available for mesh apply properly here.
3rd step would be sending custom vertex format with z and performing perspective calculations in shader, which will save hell lot, but to be useable by other people would need proper explanation of how to operate or modify the shader, so im saving it as last.

also yea, even if it is going to be more cpu expensive with the 1s and 2nd step at least possibility to draw "like normally" without having to reset changes to colors and draw coordinate modifications between batches when u use and dont use shader will surely help, at least me (combined 2d and fake 3d drawing).

by if i mean not rly sure if drawing as mesh ramps up cpu usage that much it would eat more than it would save.
also when it comes to mesh, currently shader generates vertices anyway, just without colors.
///////////
currently solved rotation, position and scale. transformations in shader below:

Code: Select all

    	//position
   	 vec2 positionData = vec2( TransformMatrix[3][0], TransformMatrix[3][1] );
	vec2 screenA = (screen_coords-positionData);

	//rotation
	float rotX = -TransformMatrix[1][0];
	float rotY = TransformMatrix[1][1];
	float dir = atan( rotX, rotY );

	float sin_factor = -sin( dir );
    	float cos_factor = cos( dir );

	vec2 screenB = vec2( screenA.x*cos_factor, screenA.y*cos_factor ) * mat2(cos_factor, -sin_factor, sin_factor, cos_factor);

	//scale
	vec2 scaleData = vec2( TransformMatrix[0][0], TransformMatrix[1][1] );
	vec2 screen = screenB / scaleData;
still need testing under various conditions, but separately and on basic tests all worked. complete modified shader after i link coordinates to mesh properly.
("screen" = "inverted" or later used as "p" in original shader)

ghurk
Prole
Posts: 15
Joined: Tue Apr 25, 2017 11:05 pm

Re: Textured Polygons for All!

Post by ghurk » Fri Jul 14, 2017 6:55 pm

Ok. so i tried to implement only the transformations support now.
I will try to post new file, able to be drawn through draw() later when/if it is completed.
Please try out and comment if transformations work properly in all cases. also excuse the simplified functions.
Not sure if its going to be more cpu expensive to send vertices to shader through array like i did, reason for it being present is that id like you to test it against original shader which has different approach.
also note that it doesnt support skew. thanks.
Attachments
Perspective.lua
modified file for love2d 0.10.2 to support scale, translate and rotate functions. currently for testing.
(4.27 KiB) Downloaded 52 times

User avatar
Popolon
Prole
Posts: 9
Joined: Mon Nov 07, 2016 11:03 am
Location: France/Paris

Re: Textured Polygons for All!

Post by Popolon » Mon Sep 04, 2017 7:11 pm

Really nice library :). There is a problem with the zoom. it uses 0,0 map coordinates as centre of the zoom instead of the current view central position.

cupz
Prole
Posts: 2
Joined: Tue Nov 14, 2017 5:17 pm

Re: Textured Polygons for All!

Post by cupz » Tue Nov 14, 2017 5:24 pm

Love the lib, but calling love.window.setMode() seems to break it. Can anyone please help out with this? <3

Without setMode()
Image

With setMode()
Image

cupz
Prole
Posts: 2
Joined: Tue Nov 14, 2017 5:17 pm

Re: Textured Polygons for All!

Post by cupz » Wed Nov 15, 2017 5:48 pm

Fixed it! Was using an older version by accident.

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests