help with float number output from 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
Alexar
Party member
Posts: 174
Joined: Thu Feb 05, 2015 1:57 am
Location: Chengdu,China

help with float number output from a shader

Post by Alexar »

hi all, i wanted to use shader to create a data sheet for a sample of a audio source. well, during input and output the data, there are some difficulties.

Code: Select all

self.audio = love.graphics.newCanvas(self.rate,1,"r32f",0)
to create float datasheet with a single channel.

Code: Select all

vec4 effect( vec4 color, sampler2D tex, vec2 tc,vec2 sc) {
    float t = sc.x;
    float y = sin(6000*t)*exp(-2*t);
    return vec4(y,0,0,0);
}

in shader we output the r channel for the datasheet. draw thing with the shader to the canvas, so that we get a canvas filled the proper data.

Code: Select all

local data = self.audio:newImageData()
    for i ,d in ipairs(self.data) do
        print(data:getPixel(i-1,0))
    end
and for output the data. all the data in imagedata generated are converted to r,g,b,a int8[4]. but how to receive the data that we need?
thank you fot the help.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: help with float number output from a shader

Post by grump »

Canvas:newImageData() always creates an RGBA image with 8 bit integer channels. That makes it impossible to read back raw float values through an ImageData object, and as far as I know LÖVE does not provide any other way to retrieve the values.
User avatar
Alexar
Party member
Posts: 174
Joined: Thu Feb 05, 2015 1:57 am
Location: Chengdu,China

Re: help with float number output from a shader

Post by Alexar »

solved by using love0.11 which uses normalized floats as color data.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 74 guests