Skip to content

Instantly share code, notes, and snippets.

@artillect
Last active March 30, 2022 02:13
Show Gist options
  • Save artillect/8ffee392521642f73ad3f28e9778f9dd to your computer and use it in GitHub Desktop.
Save artillect/8ffee392521642f73ad3f28e9778f9dd to your computer and use it in GitHub Desktop.
#version 120
varying vec2 TexCoords;
varying vec2 LightmapCoords;
//varying vec3 Normal;
varying vec4 Color;
attribute vec3 vaNormal;
attribute vec3 at_tangent;
// The texture atlas
uniform sampler2D texture;
uniform sampler2D normals;
void main(){
// Sample from texture atlas and account for biome color + ambien occlusion
vec4 albedo = texture2D(texture, TexCoords) * Color;
vec4 normal_tex = texture2D(normals, TexCoords);
vec3 Normal;
Normal.xy = normal_tex.xy * 2.0 - 1.0;
Normal.z = sqrt(1.0-dot(Normal.xy, Normal.xy));
// Create TBN matrix
vec3 binormal = cross(at_tangent, vaNormal)
mat3 TBN = mat3(at_tangent, binormal,vaNormal)
Normal = TBN * Normal;
Normal = Normal * 0.5 + 0.5;
/* DRAWBUFFERS:01 */
// Write the values to the color textures
gl_FragData[0] = albedo;
gl_FragData[1] = vec4(Normal, 1.0f);
gl_FragData[2] = vec4(LightmapCoords, 0.0f, 1.0f);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment