Problem with a shader

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
molul
Party member
Posts: 264
Joined: Sun Feb 05, 2012 6:51 pm
Location: Valencia, Spain
Contact:

Problem with a shader

Post by molul »

I'm using xXxMoNkEyMaNxXx's textured polygon shader on a project, and while on Windows I get what I want (the perspective effect at top and bottom):
windowsOK.png
windowsOK.png (169.88 KiB) Viewed 1610 times

On a Rockchip RK3066 running Linux I get this:
rockchip.jpg
rockchip.jpg (1.77 MiB) Viewed 1609 times
I checked if LÖVE is using OpenGLES context as explained here: https://love2d.org/wiki/GLES_Shader_Testing_in_Desktop.

love.graphics.getRendererInfo( ) returned "OpenGL" on Windows and "OpenGL ES" on the Rockchip.

I also printed "features = love.graphics.getSupported( )" result:

Code: Select all

FEATURES:
shaderderivatives - yes
instancing - no
clampzero - no
glsl3 - no
fullnpot - yes
pixelshaderhighp - no
lighten - yes
multicanvasformats - no
When I saw "pixelshaderhighp - no" I added this to the shader:

Code: Select all

#ifdef GL_ES
precision mediump float;
#endif
Thus, the full shader code would be this:

Code: Select all

//Made by xXxMoNkEyMaNxXx

#ifdef GL_ES
precision mediump float;
#endif

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

extern vec2 p0;
extern vec2 rep;

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.0-over.a),over.a+base.a*(1.0-over.a));
}
vec4 effect(vec4 colour,Image UNUSED1,vec2 UNUSED2,vec2 inverted)
{
	vec2 p=vec2(inverted.x, inverted.y); 

	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.0-ct*ct);
		uv=vec2(1.0-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.0,p0.y),one)));
}
My guess is that the shader isn't compatible with OpenGLES, seeing that on Windows I get "OpenGL" as render context and on the Rockchip it's "OpenGLES". Could anyone please confirm that? Also, is there anything I could change to make it work?

Thanks a lot in advance.
Attachments
windows.png
windows.png (169.88 KiB) Viewed 1610 times
Post Reply

Who is online

Users browsing this forum: _JM_ and 27 guests