Shader Code not working !
in
Programming Questions
•
10 months ago
Im trying to port some processing code to shader code to generate a "magic eye" image out of a pattern and a depthmap. The working source code of the processing sketch can be found here:
http://kobe.bplaced.net/processing/projekte/magischesAuge/Hai/.
This is the processing source code of the ported shader example:
This is the processing source code of the ported shader example:
- PShader basic;
- PImage hai, pattern;
- PGraphics haiGraph, patternGraph;
- boolean enabled = true;
- void setup() {
- size(1260, 600, P2D);
- hai = loadImage("hai_grey.png");
- pattern = loadImage("hai_pattern.png");
- haiGraph = createGraphics(hai.width, hai.height, P2D);
- patternGraph = createGraphics(pattern.width, pattern.height, P2D);
- basic = loadShader("fragment.glsl");
- basic.set("patternSampler", patternGraph);
- basic.set("haiSampler", haiGraph);
- }
- void draw() {
- background(40);
- haiGraph.beginDraw();
- haiGraph.image(hai, 0, 0);
- haiGraph.endDraw();
- patternGraph.beginDraw();
- ;
- patternGraph.image(pattern, 0, 0);
- patternGraph.endDraw();
- //int fr=frameCount;
- //basic.set("frame", fr);
- fill(100);
- if (enabled == true) {
- shader(basic);
- println("shader");
- }
- image(haiGraph, 0, 0);
- println(frameRate);
- }
- void mousePressed() {
- enabled = !enabled;
- if (!enabled == true) {
- resetShader();
- }
- }
And here is the Shader:
The pixelshift to generate the impression of depth does not work properly!
Thanks for any suggestions!
- #ifdef GL_ES
- precision mediump float;
- precision mediump int;
- #endif
- uniform sampler2D patternSampler;
- uniform sampler2D haiSampler;
- varying vec4 vertTexcoord;
- void main() {
- float sum=0.0;
- for (float x = 0.0; x < vertTexcoord.x; x+=0.001) {
- vec2 depthCoord = vec2(vertTexcoord.x, vertTexcoord.y);
- vec4 depth = texture2D(haiSampler, depthCoord.st).rgba;
- sum+=abs(depth.g/2000.0);
- }
- float vertTexs = mod((vertTexcoord.s)*1200.0,140)/140.0+sum;
- vec2 patternCoord = vec2(vertTexs, vertTexcoord.t);
- vec4 patternColor = texture2D(patternSampler, patternCoord.st).rgba;
- gl_FragColor = patternColor;
- }
The pixelshift to generate the impression of depth does not work properly!
Thanks for any suggestions!
1