'Simplistic 2D Shadow System'

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
IceQB
Citizen
Posts: 67
Joined: Sat Nov 03, 2012 1:11 pm

'Simplistic 2D Shadow System'

Post by IceQB »

Hi guys!

I trying rewrite (port to Love2D) simple shadow shaders from tutorials but none of them work.
My last try is with this tutorial https://ostindiegames.wordpress.com/201 ... ow-system/ and too not work. I do not know what is wrong. My experience is poor with shaders but i can write little stuff.

So my code looks that:

Code: Select all

uniform sampler2D TextureSampler;
uniform sampler2D StencilSampler;

vec4 effect( vec4 color, Image texture, vec2 texCoord, vec2 scrCoord)
{  
	vec4 oldColor = Texel(StencilSampler, texCoord);

	vec2 newCoords = vec2(texCoord.x + (.5 - texCoord.x)*.5, texCoord.y + (.5 - texCoord.y)*.5);
	vec4 newColor = Texel(StencilSampler, newCoords);
	
	if (newColor.r == 0)
	{
		oldColor = newColor;
	}
 
	newCoords = vec2(texCoord.x + (.5 - texCoord.x)*.85, texCoord.y + (.5 - texCoord.y)*.85);
	newColor = Texel(StencilSampler, newCoords);
	
	if (newColor.r == 0)
	{
		oldColor = newColor;
	}
	
	return  color*oldColor;
}
Someone can explain me how it works?
User avatar
DeltaF1
Citizen
Posts: 64
Joined: Mon Apr 27, 2015 4:12 pm
Location: The Bottom of the Stack
Contact:

Re: 'Simplistic 2D Shadow System'

Post by DeltaF1 »

One problem with that code is that in LOVE 'uniform' is replaced by 'extern' and 'sampler2d' is replaced by 'Image'

Here's a heplful tutorial
User avatar
IceQB
Citizen
Posts: 67
Joined: Sat Nov 03, 2012 1:11 pm

Re: 'Simplistic 2D Shadow System'

Post by IceQB »

Yes, i know but that nothing changes.
User avatar
AntonioModer
Party member
Posts: 202
Joined: Fri Jun 15, 2012 5:31 pm
Location: Belarus
Contact:

Re: 'Simplistic 2D Shadow System'

Post by AntonioModer »

I worked on this too, and i have this shader (very slow), worked correct and draw shadows:

Code: Select all

vec4 effect(vec4 color, Image texture, vec2 texCoord, vec2 screenCoord) {
	vec4 pixel = Texel(texture, texCoord);								// This is the current pixel color

	for(number i = texCoord.y; i < 1000; i++) {
		vec2 newCoords = vec2(texCoord.x + (0.5 - texCoord.x)*0.001*i, texCoord.y + (0.5 - texCoord.y)*0.001*i);
		vec4 newColor = Texel(texture, newCoords);
		if (newColor.r == 0) {
		   pixel = newColor;
		}	
	}
	
	return pixel;
}
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest