Page 1 of 1

'Simplistic 2D Shadow System'

Posted: Thu Jun 25, 2015 2:34 pm
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?

Re: 'Simplistic 2D Shadow System'

Posted: Thu Jun 25, 2015 6:49 pm
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

Re: 'Simplistic 2D Shadow System'

Posted: Fri Jun 26, 2015 12:41 am
by IceQB
Yes, i know but that nothing changes.

Re: 'Simplistic 2D Shadow System'

Posted: Sun Aug 02, 2015 7:31 pm
by AntonioModer

Re: 'Simplistic 2D Shadow System'

Posted: Sat Aug 15, 2015 9:54 am
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;
}