Makogan

10-24-2017, 12:18 AM

This is my current vertex shader:

#version 410

layout(location = 0) in vec3 position; //(x,y,z) coordinates of a vertex

layout(location = 1) in vec3 norm; //a 3D vertex representing the normal to teh vertex

layout(location = 2) in vec2 texture_coordinate;

out vec3 normal;

out vec3 vertexPos; //projected vertex

out vec2 texture_coord;

uniform mat4 model = mat4(1); //Position and orientation of the current object

uniform mat4 view = mat4(1); //Camera orientation and position

uniform mat4 proj = mat4(1); //the projection parameters (FOV, viewport dimensions)

uniform uint face_type[2048];

void main()

{

uint orientation=face_type[gl_InstanceID];

vec2 face_texture = vec2(orientation*(1/6.f),0);

vec2 fml = texture_coordinate + face_texture;

gl_Position = proj*view*model*vec4(position, 1.0);

normal = vec3(model*vec4(norm,1.0));

vertexPos = vec3(model*vec4(position, 1.0)); //calculate the transformed pos

texture_coord = fml;

}

All I am trying to do is pass onto the fragment shader the texture coordinate, texture_coord+vec2(orientation*(1/6.f),0)

The reason for this is that, this is a texture for a cube that is 192*32 pixels long, and each 32x32 area of the texture is a face of the cube. I need to dynamically select which face of the cube is getting drawn, so I need to dynamically calculate the texture coordinates based on the face type. However OpenGL doesn't let me do this.

Any help is appreciated.

#version 410

layout(location = 0) in vec3 position; //(x,y,z) coordinates of a vertex

layout(location = 1) in vec3 norm; //a 3D vertex representing the normal to teh vertex

layout(location = 2) in vec2 texture_coordinate;

out vec3 normal;

out vec3 vertexPos; //projected vertex

out vec2 texture_coord;

uniform mat4 model = mat4(1); //Position and orientation of the current object

uniform mat4 view = mat4(1); //Camera orientation and position

uniform mat4 proj = mat4(1); //the projection parameters (FOV, viewport dimensions)

uniform uint face_type[2048];

void main()

{

uint orientation=face_type[gl_InstanceID];

vec2 face_texture = vec2(orientation*(1/6.f),0);

vec2 fml = texture_coordinate + face_texture;

gl_Position = proj*view*model*vec4(position, 1.0);

normal = vec3(model*vec4(norm,1.0));

vertexPos = vec3(model*vec4(position, 1.0)); //calculate the transformed pos

texture_coord = fml;

}

All I am trying to do is pass onto the fragment shader the texture coordinate, texture_coord+vec2(orientation*(1/6.f),0)

The reason for this is that, this is a texture for a cube that is 192*32 pixels long, and each 32x32 area of the texture is a face of the cube. I need to dynamically select which face of the cube is getting drawn, so I need to dynamically calculate the texture coordinates based on the face type. However OpenGL doesn't let me do this.

Any help is appreciated.