const char * vs = #ifdef EMSCRIPTEN "#version 300 es\n" "precision highp float;" #else "#version 330 core\n" #endif "layout (location = 0) in float aPos_x;" "layout (location = 1) in float aPos_y;" "layout (location = 2) in float aPos_z;" "layout (location = 3) in float aPos_w;" "layout (location = 4) in float aNormal_x;" "layout (location = 5) in float aNormal_y;" "layout (location = 6) in float aNormal_z;" "layout (location = 7) in float aNormal_w;" "uniform uint idx;" "uniform uint i;" "uniform float angle;" "uniform mat4 fix;" "uniform mat4 rot;" "uniform mat4 mdl;" "flat out uint index;" "out vec3 Normal;" "out vec3 FragPos;" "mat2 rotate2d( float angle )" "{" "return mat2( cos(angle), sin(angle), -sin(angle), cos(angle) );" "}" "void main()" "{" " index=idx;" " vec3 aNormal = vec3(aNormal_x,aNormal_y,aNormal_z);" " vec3 aPos = vec3(aPos_x,aPos_y,aPos_z);" " aNormal[i] = (vec2(aNormal_w, aNormal[i]) * rotate2d(angle))[0];" " aPos[i] = (vec2(aPos_w, aPos[i]) * rotate2d(angle))[0];" " Normal = mat3(transpose(inverse(rot*mdl))) * aNormal;" " gl_Position = fix * rot * mdl * vec4( aPos, 1.0 );\n" " FragPos = vec3( rot * mdl * vec4(aPos, 1.0));" "}"; const char * fs_plain = #ifdef EMSCRIPTEN "#version 300 es\n" "precision highp float;" "precision highp sampler2DArray;" #else "#version 330 core\n" #endif "uniform sampler2DArray palette;" "flat in uint index;" "out vec4 FragColor;" "in vec3 Normal;" "in vec3 FragPos;" "void main()" "{" " vec4 color = texture( palette, vec3(0,0,index)).rgba;" " FragColor = vec4(pow(vec3(color),vec3(1.0/2.2)),color.a);" "}"; const char * fs = #ifdef EMSCRIPTEN "#version 300 es\n" "precision highp float;" "precision highp sampler2DArray;" #else "#version 330 core\n" #endif "uniform sampler2DArray palette;" "flat in uint index;" "in vec3 Normal;" "in vec3 FragPos;" "out vec4 FragColor;" "void main()" "{" " vec4 color = texture(palette, vec3(0, 0, index));\n" " vec3 viewPos = vec3(0, 0, -15);\n" " vec3 viewDir = normalize(viewPos - FragPos);\n" " vec3 lightPos = viewPos;\n" " vec3 lightDir = normalize(lightPos - FragPos);\n" " vec3 halfwayDir = normalize(lightDir + viewDir);\n" " float specular = pow(abs(dot(normalize(Normal), halfwayDir)), 32.0);\n" " float diffuse = abs(dot(normalize(Normal), lightDir));\n" " vec3 result = pow((0.5 + 0.5*diffuse + 1.5*specular) * color.rgb, vec3(1.0/2.2));\n" " FragColor = vec4(result, color.a);\n" "}";