Shaders and ints

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.
User avatar
RedHot
Citizen
Posts: 87
Joined: Mon May 27, 2013 2:43 pm
Location: Poland

Re: Shaders and ints

Post by RedHot »

Not really I believe this is the kind of situation when you either know what's wrong or not. But maybe it's just me :).

MassMtx is a [j][2] Matrix that works correctly. Vsync is on.

Very well then. This is the shader code :

Code: Select all

		extern number mapx;
		extern number map_xoffset;
		extern number blocksize;
        extern vec2 mass[512];

        vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords)
        {
			int index = int((pixel_coords.x-map_xoffset)/blocksize);
			//index--;
			
			if(index < mapx+2)
			{
				if(mass[index].y > 0.5)
				{
					if(mass[index].x < 0.005)
					{
						return vec4(mass[index].x*800.0/255.0,(20+mass[index].x*9000)/255.0f,(45.0+mass[index].x*20000)/255.0,1.0f);
					}

					else
					{
						return vec4((167 - 137*mass[index].x)/255.0f, (202-120*mass[index].x)/255.0f, (229-76*mass[index].x)/255.0f , 1.0f);
					}

				}
				else
				{
					return vec4(244/255.0,220.0/255.0,181.0/255.0,1.0f);
				}
			}

			return vec4(1.0,1.0,1.0,1.0);
        }

And this is the drawing function

Code: Select all

function love.draw()

--love.graphics.setCanvas(canvas)
love.graphics.clear()
love.graphics.setColor(255,255,255,255)
love.graphics.print("b1x = " .. b1x, 10, 110)
	effect:send("mapx", map_x)
	effect:send("blocksize",blockSize )
	effect:send("map_xoffset",map_xoffset)


local grid = grid


	love.graphics.setPixelEffect(effect)
    

	time1B = love.timer.getTime()

	for i = 1, map_y+2 do

	effect:send("mass", unpack(massMtx[i], 1, #massMtx[i]))

		love.graphics.rectangle("fill" , map_xoffset, 50+(i)*blockSize , blockSize*(map_x+2) ,blockSize)
	end
	
	love.graphics.setPixelEffect()
		love.graphics.setColor(255,255,255,255)

	
	
	love.graphics.setColor(255,0,255,255)
	time1E = love.timer.getTime()
	love.graphics.print("Drawing time = " .. (time1E - time1B), 10, 900)
	love.graphics.print("Computing time = " .. (time2E - time2B), 10, 950)
	

	
end
Post Reply

Who is online

Users browsing this forum: No registered users and 47 guests