Created
June 8, 2019 16:14
-
-
Save QuadStorm/082e557d185f281ec059c14308baf65c to your computer and use it in GitHub Desktop.
Default Blockland Vertex Shader using version 460
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#version 460 | |
// Varying. | |
out vec4 vPos; | |
out vec3 worldNormal; | |
out vec3 worldPos; | |
// 460 | |
uniform mat4 gl_ProjectionMatrix; | |
in vec4 gl_Vertex; | |
in vec4 gl_Normal; | |
in vec4 gl_Color; | |
in vec4 gl_MultiTexCoord0; | |
out vec4 gl_FrontColor; | |
// Misc uniforms. | |
uniform vec3 camPos; | |
uniform mat4 obj2World; | |
uniform mat4 world2Cam; | |
// Surface calculations, including specular power. | |
out vec2 texCoord; | |
vec4 viewDelta; | |
// Fogging. | |
uniform vec4 fogBaseColor; | |
uniform vec4 fogConsts; | |
uniform sampler2D fogTex; | |
out vec2 fogCoords; | |
void main() | |
{ | |
// Bricks always in world space. | |
worldPos = (obj2World * vec4(gl_Vertex.xyz, 1.0f)).xyz; | |
worldNormal = ((obj2World * vec4(gl_Normal.xyz, 0.0f)).xyz); | |
if(length(gl_Normal.xyz) < 1.1f) | |
worldNormal.xyz = normalize(worldNormal.xyz); | |
// Do some camera delta math. | |
viewDelta.xyz = worldPos - camPos; | |
viewDelta.w = length(viewDelta.xyz); | |
viewDelta.xyz = -normalize(viewDelta.xyz); | |
// Fog can be done per-vertex. | |
fogCoords.x = clamp((fogConsts.y - viewDelta.w) * fogConsts.x, 0.0f, 1.0f); | |
fogCoords.y = clamp((worldPos.z - fogConsts.z) * fogConsts.w, 0.0f, 1.0f); | |
// Project the brick pos and normal. | |
vPos = world2Cam * vec4(worldPos, 1.0f); | |
gl_Position = gl_ProjectionMatrix * vPos; | |
// Pass color through. | |
gl_FrontColor = gl_Color; | |
// Pass texcoords through. | |
texCoord = gl_MultiTexCoord0.st; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment