How to make shaders Android-friendly?

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
Iori Branford
Prole
Posts: 36
Joined: Wed Apr 13, 2016 3:53 pm

How to make shaders Android-friendly?

Post by Iori Branford »

In my stealth side scroller prototype I'm trying a spotlight shader for a simple darkness effect.

On PCs it has the desired effect.
On PC
On PC
2883059318-screenshot04.png (64.51 KiB) Viewed 2000 times
On Android devices it varies. For example, on Samsung Galaxy Note 5 the effect is much reduced. Enabling gamma-correct mode and/or high-DPI mode don't help.
On Galaxy Note 5
On Galaxy Note 5
Screenshot_2016-04-13-12-26-39.png (57.93 KiB) Viewed 2000 times
And my old Moto X (XT1060) did something in between: almost completely dark but not quite, as I could still make out brightly-colored objects. (It also couldn't reach 60fps, but that's a separate issue.) I don't have a screenshot at the moment.

Does anyone have an idea what's going on? What part of my shader code varies by Android device? Color format? Texel format? smoothstep?

Code: Select all

StealthMap.DarknessRadius = 480
StealthMap.DarknessShader = love.graphics.newShader([[
	extern number radius;
	extern vec2 center;
	vec4 effect(vec4 color, Image texture, vec2 tc, vec2 sc)
	{
		number d = length(center - sc) / radius;
		number v = smoothstep(0.0, 1.0, 1.0 - d);
		return color * Texel(texture, tc) * v;
	}
]])

function StealthMap:endMove()
	local player = self.map.objects[
		tonumber(self.map.properties.playerid)]
	if player and player.body then
		local x, y = player.body:getWorldCenter()
		x = x - levity.camera.x
		y = y - levity.camera.y
		x = x * levity.camera.scale
		y = y * levity.camera.scale
		self.shader:send("radius",
			self.DarknessRadius * levity.camera.scale)
		self.shader:send("center", { x, y })
	end
end

function StealthMap:beginDraw()
	love.graphics.setShader(self.DarknessShader)
end

function StealthMap:endDraw()
	love.graphics.setShader()
end
levity.love
LOVE file
(1.41 MiB) Downloaded 91 times
Thanks.
Iori Branford
Prole
Posts: 36
Joined: Wed Apr 13, 2016 3:53 pm

Re: How to make shaders Android-friendly?

Post by Iori Branford »

I fixed it. I need to specify float precision on mobile.

Code: Select all

#ifdef GL_ES 
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif
#endif
Post Reply

Who is online

Users browsing this forum: No registered users and 25 guests