Hi,
I’ve a simple processing sketch which should use a shader to texture a sphere and use peasycam for rotation. if running the sketch the texture is applied quite well, but it doesn’t apply the rotation. Has anyone an idea why this happens, or better any idea how to solve it in such a way the cam rotation would be also applied to the texture ? Thanks in advance for your help !
main sketch
import peasy.*;
PShader shader;
PImage tex;
PeasyCam cam;
void setup() {
size(500,500,P3D);
cam = new PeasyCam(this, 300);
tex = loadImage("UV_checker.jpg");
shader = loadShader("shader.frag", "shader.vert");
shader.set("mytexture", tex);
}
void draw() {
background(0);
shader(shader);
stroke(128);
fill(255);
sphere(100);
}
vertex shader
uniform mat4 transform;
uniform mat4 modelview;
uniform mat3 normalMatrix;
attribute vec4 vertex;
attribute vec3 normal;
varying vec3 texCoords;
void main()
{
gl_Position = transform * vertex;
texCoords = normalize(normalMatrix * normal);
}
fragment shader
uniform sampler2D mytexture;
varying vec3 texCoords;
void main(void) {
vec2 uvcoords = vec2((atan(texCoords.x, texCoords.z) / 3.1415926 + 1.0) * 0.5,
(asin(texCoords.y) / 3.1415926 + 0.5));
gl_FragColor = texture2D(mytexture, uvcoords);
}