GithubHelp home page GithubHelp logo

tiagosr / ofxshadertoy Goto Github PK

View Code? Open in Web Editor NEW
80.0 9.0 15.0 3.28 MB

Addon for openFrameworks that sets up and loads Shadertoy (http://www.shadertoy.com) shaders

GLSL 31.32% C++ 40.11% Makefile 28.56%
shaders shadertoy glsl openframeworks-addon

ofxshadertoy's Introduction

ofxShadertoy

ofxaddons

openFrameworks addon for loading and displaying shaders from the Shadertoy page.
Shadertoy is (c) iq
This addon is distributed under the terms of the MIT License.

Usage

  1. Set up your project to use the programmable shader. in the int main(...) function, set your window to use OpenGL 3.2 or greater:

    ofGLWindowSettings settings;
    settings.setGLVersion(3, 2);    // <--- ofxShadertoy NEEDS the GL Programmable Renderer
    settings.width = 1024;
    settings.height = 768;
    ofCreateWindow(settings);       // <-------- setup the GL context
  2. Set up the ofxShadertoy to load a file with the shadertoy glsl code

    ofxShadertoy shadertoy;
    ...
    shadertoy.load("shaders/raymarch.frag");
  3. Set up textures if needed by the shader

    shadertoy.setTexture(0, nifty_texture);
  4. In your draw() routine, draw a quad (or use begin() and end() to set up the shaders for a mesh) Effects happen in screen space.

Extensions

I've set up some extensions to the shader parameters, mostly relating to using a camera (for use, non-exclusively, with another one of my addons, ofxFPSControls). The new uniforms are:

uniform mat4 tCameraMatrix; - a camera matrix that can be set up using ofCamera or any child class (e.g. ofxFPSControls)

ofxshadertoy's People

Contributors

tiagosr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ofxshadertoy's Issues

example passing variables

hi.
I love your add-on.

I'm using a shader right now that changes based on the iMouse position.
Do you have an example showing how I can pass in custom variables to effect change?
I have an ofxGui and want it to change things inside the shader.

Thanks for any advice.

textures, iChannel, iMouse

Thanks so much for making the update to OF 0.9.0

Your example and some other shaders work now :)

Do you have more information on how to make it work with an underlying texture and what is the iChannel stuff?
I tried to load in a texture but the shader did not like what i did.

    ofImage img;
    img.load("fondo.jpg");
    nifty_texture.loadData(img.getPixels());
   shadertoy.setTexture(0, nifty_texture);

here are 2 water ripple shaders i am trying to get working:
https://www.shadertoy.com/view/ldB3Wd
https://www.shadertoy.com/view/4djGzz

I am hoping to find shader code that i can change to give me more control over frequency, amplitude and propagation speed of interfering water ripples. Any pointers?

Thanks.

using ofFbo .getTexture()

it's me again.

I was successful loading an image in to my polarGrid example inside setup().

I am now trying to generate an ofFbo and pass it's texture to the shader during update().
But it's always black.
If I do the work around as in the below code things work. But it seems silly to have to pass FBO to pix, to tex.

Ideally I would be able to just call mainFbo.getTexture()

Any ideas what I am doing wrong?

void ofApp::update(){
    
    if(mainFbo.isAllocated() == false){
        img.allocate(1024, 768, OF_IMAGE_COLOR);
        tex.allocate(img.getWidth(), img.getHeight(), GL_RGBA, false); 
        mainFbo.allocate(1024,768, GL_RGBA, false);
    }
    
    mainFbo.begin();
    ofClear(255,255,255,0);
    ofSetColor(255, 0, 0,255);
    ofDrawCircle(mouseX, mouseY, 400);
    mainFbo.end();
    
//    shadertoy.setTexture(0, mainFbo.getTexture());
    
    ofPixels pix;
    mainFbo.readToPixels(pix);
    img.setFromPixels(pix);
    tex.loadData(img.getPixels());
    shadertoy.setTexture(0, tex);
}

OF 0.9.0 compile errors

Hi there.

I am trying to get your addon to run on my MBP with NVIDIA GeForce GT 750M 2048 MB under OS X 10.10

Here is a list of errors i have encountered:

compiling your example gives me this:
Field type 'ofxShadertoy' is an abstract class

so i made these changes changes:
command out
//ofSetCurrentRenderer(ofGLProgrammableRenderer::TYPE);

//ofxShadertoy shader toy; 
ofxShadertoy *shadertoy;

and

//shadertoy.load("shaders/raymarch.frag");
shadertoy->load("shaders/raymarch.frag");
etc

which removed all ofxShaderToy related errors.
But in ofxFPSControls i had to command the following calls since these functions seem not to exist in my version of OF:

//    ofSetCursorPosition(ofGetWindowWidth()/2, ofGetWindowHeight()/2);
//    ofGrabCursor();
//    ofReleaseCursor();
//    ofSetCursorPosition(center.x, center.y);

then the app compiled but crashed and gave me these error messages:

[ error ] ofShader: setupShaderFromSource(): GL_VERTEX_SHADER shader failed to compile
[ error ] ofShader: GL_VERTEX_SHADER shader reports:
ERROR: 0:1: '' :  version '330' is not supported
ERROR: 0:2: 'precision' : syntax error: syntax error

[ error ] ofShader: GL_VERTEX_SHADER, offending line 1 :
        1   #version 330
        2   precision mediump float;uniform mat4 modelViewProjectionMatrix;uniform mat4 tCameraMatrix;in vec4 position;void main(){    gl_Position = modelViewProjectionMatrix * position;}
        3   

[ error ] ofShader: setupShaderFromSource(): GL_FRAGMENT_SHADER shader failed to compile
[ error ] ofShader: GL_FRAGMENT_SHADER shader reports:
ERROR: 0:1: '' :  version '330' is not supported
ERROR: 0:2: 'precision' : syntax error: syntax error

[ error ] ofShader: GL_FRAGMENT_SHADER, offending line 1 :
        1   #version 330
        2   precision mediump float;
        3   uniform vec3      iResolution;

[ error ] shader: error loading shader

not sure if my GPU is not compatible since "version '330' is not supported"

thx

Havent found a way to get multi-buffer textures

Hello,

Would you please help me ?

I still haven't found a way to get in my "ofxShadertoy::Buffer::Image" shader, other buffers result textures.

The shaders are all compilling without issues; If I test evey other buffer's shader in ImageBuffer, they all work.

But it is at the time I try to bind Buffer(A/B/C/D) texture to Image Buffer, when I try to get RGBA texture information, I can't (Result is pure black).

Am I missing something ?

shader :

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    vec2 uv = fragCoord/iResolution.xy;
    vec4 color = texture(iChannel0, uv);
    //color = vec4(1.0, 0.0, 0.0, 1.0);
    fragColor = color;
}

Code :

void ofApp::draw() {

	shaderRaymarching.begin();
	shaderRaymarching.draw(0.0, 0.0, 0.0, width, height);
	shaderRaymarching.end();
}
void ofApp::loadShadersFiles()
{
  shaderRaymarching.load("Photos.frag", ofxShadertoy::Buffer::Image);
  
  shaderRaymarching.load("PixelA.frag", ofxShadertoy::Buffer::BufferA);
  shaderRaymarching.load("PixelB.frag", ofxShadertoy::Buffer::BufferB);
  shaderRaymarching.load("PixelC.frag", ofxShadertoy::Buffer::BufferC);
  shaderRaymarching.load("PixelD.frag", ofxShadertoy::Buffer::BufferD);
  
  shaderRaymarching.begin();
  shaderRaymarching.end();

  shaderRaymarching.setTexture(0, ofxShadertoy::Buffer::BufferA, ofxShadertoy::Buffer::Image);
  shaderRaymarching.setTexture(1, ofxShadertoy::Buffer::BufferB, ofxShadertoy::Buffer::Image);
  shaderRaymarching.setTexture(2, ofxShadertoy::Buffer::BufferC, ofxShadertoy::Buffer::Image);
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.