-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Request: backbuffer sample #172
Comments
I Agree, it would be great if we could save one pixel data in memory and modify it when needed. backbuffer works great until you need to sample the last frame but in my case i want to sample how much time has passed since the last touch was performed and if i could store the time data in a pixel value and reference it in next frame it would work. :) I hope we get something like that soon. |
I think what you really want would be the ability to also write scripts for the CPU as well. This would require the addition of an actual filesystem and a scripting language like Custom variablesCustom variables could be passed using a Script Examples for Lua/JavaScriptLua Custom Variableslocal engine = require("ShaderEngine")
-- Create a shader object
local shader = engine:createShader("./main.glsl")
-- Initialize sensors
local accelerometer = engine:initProvider("accelerometer")
local myCustomData = vec2.new(0, 0)
-- Function to update uniforms
local function updateUniforms(shader)
-- Pass sensor data to the shader as uniforms
shader:setUniform("accelerometer", accelerometer:getData())
shader:setUniform("myCustomData", myCustomData)
shader:setUniform("backbuffer", engine:getBackBufferTexture())
local time = engine:getTime()
shader:setUniform("time", time)
myCustomData:add(1, 0)
end
-- Start the engine loop
while engine:running() do
-- Clear the screen
engine:clear()
-- Update sensors
accelerometer:update()
-- Update shader uniforms
updateUniforms(shader)
-- Render the full-screen shader
engine:render{ shader = shader }
-- Swap buffers to display the rendered frame
engine:swapBuffers()
end JavaScript Custom Variablesimport engine from "shader-engine";
// Create a shader object
const shader = engine.createShader("./main.glsl");
// Initialize sensors
const accelerometer = engine.initProvider("accelerometer");
const myCustomData = new Vec2(0, 0);
// Function to update uniforms
function updateUniforms(shader) {
// Pass sensor data to the shader as uniforms
shader.setUniform("accelerometer", accelerometer.data);
shader.setUniform("myCustomData", myCustomData);
shader.setUniform("backbuffer", engine.backBufferTexture);
const time = engine.time;
shader.setUniform("time", time);
myCustomData.add(1, 0);
}
// Start the engine loop
while (engine.running) {
// Clear the screen
engine.clear();
// Update sensors
accelerometer.update();
// Update shader uniforms
updateUniforms(shader);
// Render the full-screen shader
engine.render({shader});
// Swap buffers to display the rendered frame
engine.swapBuffers();
} Default ScriptTo not break backwards compatibility, a default script could be used and all shaders get converted into a Script Examples for Lua/JavaScriptLua Default Scriptlocal engine = require("ShaderEngine")
local shader = engine:createShader("./main.glsl")
local sensors = engine:initProviders(shader:getUniformNames())
while engine:running() do
engine:clear()
for k, v in pairs(sensors) do
v:update()
shader:setUniform(k, v:getData())
end
engine:render{ shader = shader }
engine:swapBuffers()
end JavaScript Default Scriptimport engine from "shader-engine";
const shader = engine.createShader("./main.glsl");
const sensors = engine.initProviders(shader.uniformNames);
while (engine.running) {
engine.clear();
for (const [key, value] of Object.entries(sensors)) {
value.update();
shader:setUniform(key, value.data);
}
engine.render({shader});
engine.swapBuffers();
} |
Could you add a basic sample about backbuffer to store and load data to use later? May be store data on only one pixel?
I have seen game of life sample, I thing that you could add a sample like using mouse to change color.
It will be very useful for beginners.
Thank you.
The text was updated successfully, but these errors were encountered: