示例#1
0
文件: shader_sun.go 项目: num5/steven
func init() {
	glsl.Register("sun_vertex", `
in vec3 aPosition;
in vec4 aTextureInfo;
in ivec3 aTextureOffset;
in vec4 aColor;
in int id;

uniform mat4 perspectiveMatrix;
uniform mat4 cameraMatrix;
uniform mat4 modelMatrix[10];
uniform float lightLevel;
uniform float skyOffset;
uniform vec2 lighting;

out vec4 vTextureInfo;
out vec2 vTextureOffset;
out float vAtlas;
out float vID;

void main() {
	vec3 pos = vec3(aPosition.x, -aPosition.y, aPosition.z);
	gl_Position = perspectiveMatrix * cameraMatrix * modelMatrix[id] * vec4(pos, 1.0);

	vTextureInfo = aTextureInfo;
	vTextureOffset = aTextureOffset.xy / 16.0;
	vAtlas = aTextureOffset.z;
	vID = float(id);
}
`)
	glsl.Register("sun_frag", `

uniform sampler2DArray textures;
uniform vec4 colorMul[10];

in vec4 vTextureInfo;
in vec2 vTextureOffset;
in float vAtlas;
in float vID;

out vec4 fragColor;

#include lookup_texture

void main() {
	vec4 col = atlasTexture();
	if (col.a <= 0.05) discard;
	fragColor = col * colorMul[int(vID)];
}
`)
}
示例#2
0
文件: uishader.go 项目: num5/steven
func init() {
	glsl.Register("ui_vertex", `
in ivec3 aPosition;
in vec4 aTextureInfo;
in ivec3 aTextureOffset;
in vec4 aColor;

out vec4 vColor;
out vec4 vTextureInfo;
out vec2 vTextureOffset;
out float vAtlas;

uniform vec2 screenSize;

void main() {
	vec2 pos = aPosition.xy / screenSize;
	gl_Position = vec4((pos.x-0.5)*2.0, -(pos.y-0.5)*2.0, float(-aPosition.z) / float(0xFFFF-1), 1.0);
	vColor = aColor;
	vTextureInfo = aTextureInfo;
	vTextureOffset = aTextureOffset.xy / 16.0;
	vAtlas = aTextureOffset.z;
}
`)
	glsl.Register("ui_frag", `
uniform sampler2DArray textures;

in vec4 vColor;
in vec4 vTextureInfo;
in vec2 vTextureOffset;
in float vAtlas;

out vec4 fragColor;

#include lookup_texture

void main() {
	vec4 col = atlasTexture();
	col *= vColor;
	if (col.a == 0.0) discard;
	fragColor = col;
}
`)
}
示例#3
0
func init() {
	glsl.Register("lookup_texture", `
const float invAtlasSize = 1.0 / `+atlasSizeStr+`;
vec4 atlasTexture() {
	vec2 tPos = vTextureOffset;
	tPos = mod(tPos, vTextureInfo.zw);
	tPos += vTextureInfo.xy;
	tPos *= invAtlasSize;
	return texture(textures, vec3(tPos, vAtlas));
}	
`)
	glsl.Register("get_light", `
vec3 getLight(vec2 light) {
	vec2 li = pow(vec2(lightLevel), 15.0 - light);
	float skyTint = skyOffset * 0.95 + 0.05;
	float bl = li.x;
	float sk = li.y * skyTint;

	float skyRed = sk * (skyOffset * 0.65 + 0.35);
	float skyGreen = sk * (skyOffset * 0.65 + 0.35);
	float blockGreen = bl * ((bl * 0.6 + 0.4) * 0.6 + 0.4);
	float blockBlue = bl * (bl * bl * 0.6 + 0.4);

	vec3 col = vec3(
		skyRed + bl,
		skyGreen + blockGreen,
		sk + blockBlue
	);

	col = col * 0.96 + 0.03;

	float gamma = 0.0;
	vec3 invCol = 1.0 - col;
	invCol = 1.0 - invCol * invCol * invCol * invCol;
	col = col * (1.0 - gamma) + invCol * gamma;
	col = col * 0.96 + 0.03;

	return clamp(col, 0.0, 1.0);
}	
`)
}
示例#4
0
func init() {
	glsl.Register("chunk_vertex", `
in vec3 aPosition;
in vec4 aTextureInfo;
in vec3 aTextureOffset;
in vec3 aColor;
in vec2 aLighting;

uniform mat4 perspectiveMatrix;
uniform mat4 cameraMatrix;
uniform ivec3 offset;
uniform float lightLevel;
uniform float skyOffset;

out vec3 vColor;
out vec4 vTextureInfo;
out vec2 vTextureOffset;
out float vAtlas;
out vec3 vLighting;

#include get_light

void main() {
	vec3 pos = vec3(aPosition.x, -aPosition.y, aPosition.z);
	vec3 o = vec3(offset.x, -offset.y, offset.z);
	gl_Position = perspectiveMatrix * cameraMatrix * vec4(pos + o * 16.0, 1.0);

	vColor = aColor;
	vTextureInfo = aTextureInfo;
	vTextureOffset = aTextureOffset.xy / 16.0;
	vAtlas = aTextureOffset.z;

	vLighting = getLight(aLighting / (4000.0));
}
`)
	glsl.Register("chunk_frag", `
uniform sampler2DArray textures;

in vec3 vColor;
in vec4 vTextureInfo;
in vec2 vTextureOffset;
in float vAtlas;
in vec3 vLighting;

#ifndef alpha
out vec4 fragColor;
#else
out vec4 accum;
out float revealage;
#endif

#include lookup_texture

void main() {
	vec4 col = atlasTexture();
	#ifndef alpha
	if (col.a < 0.5) discard;
	#endif
	col *= vec4(vColor, 1.0);
	col.rgb *= vLighting;

	#ifndef alpha
	fragColor = col;
	#else
	float z = gl_FragCoord.z;
	float al = col.a;
	float weight = pow(al + 0.01f, 4.0f) +
			  	   max(0.01f, min(3000.0f, 0.3f / (0.00001f + pow(abs(z) / 800.0f, 4.0f))));
	accum = vec4(col.rgb * al * weight, al);
	revealage = weight * al;
	#endif
}
`)
}
示例#5
0
文件: clouds.go 项目: num5/steven
func init() {
	glsl.Register("cloud_vertex", `
in vec3 aPosition;

uniform float lightLevel;
uniform float skyOffset;

out vec3 vLighting;

#include get_light

void main() {
	vec3 pos = vec3(aPosition.x, -aPosition.y, aPosition.z);
	gl_Position = vec4(pos, 1.0);

	vLighting = getLight(vec2(0.0, 15.0));
}
`)
	glsl.Register("cloud_geo", `
layout(points) in;
layout(triangle_strip, max_vertices = 24) out;

uniform mat4 perspectiveMatrix;
uniform mat4 cameraMatrix;
uniform vec3 offset;
uniform float cloudOffset;

uniform vec4 textureInfo;
uniform float atlas;
uniform sampler2DArray textures;
uniform sampler2D cloudMap;

in vec3 vLighting[];

out vec3 fLighting;
out vec4 fColor;

void setVertex(vec3 base, vec3 off, float color) {
	gl_Position = perspectiveMatrix * cameraMatrix * vec4(base + off*vec3(1.0,-1.0,1.0), 1.0);
	fColor = vec4(color, color, color, 1.0);
	fLighting = vLighting[0];
	EmitVertex();
}

float coffset = cloudOffset;
const float invAtlasSize = 1.0 / `+atlasSizeStr+`;
vec4 atlasTexture(vec2 tPos) {
	tPos.y += floor(coffset);
	tPos = mod(tPos, textureInfo.zw);
	tPos += textureInfo.xy;
	tPos *= invAtlasSize;
	return texture(textures, vec3(tPos, atlas));
}

ivec2 texP, heightP;

bool isSolid(ivec2 pos) {
	float height = texelFetch(cloudMap, ivec2(mod(heightP + pos, 512)), 0).r;
	if (height >= 127.0/255.0) return false;
	return atlasTexture(vec2(texP + pos)).r + height > (250.0 / 255.0);
}

bool isFutureSolid(ivec2 pos) {
	// Sneak a peak into the future
	coffset += 1.0;
	bool ret = isSolid(pos);
	coffset -= 1.0;
	return ret;
}

void main() {
	vec3 base = floor(offset) + gl_in[0].gl_Position.xyz;
	texP = ivec2(gl_in[0].gl_Position.xz + 160.0 + offset.xz);
	heightP = ivec2(mod(base.xz, 512));
	if (!isSolid(ivec2(0))) return;

	float backOffset = 1.0 - fract(cloudOffset);
	float frontOffset = -fract(cloudOffset);
	if (!isFutureSolid(ivec2(0, -1))) {
		frontOffset = 0.0;
	}

	// Top
	setVertex(base, vec3(0.0, 1.0, frontOffset), 1.0);
	setVertex(base, vec3(1.0, 1.0, frontOffset), 1.0);
	setVertex(base, vec3(0.0, 1.0, backOffset), 1.0);
	setVertex(base, vec3(1.0, 1.0, backOffset), 1.0);
	EndPrimitive();

	// Bottom
	setVertex(base, vec3(0.0, 0.0, frontOffset), 0.7);
	setVertex(base, vec3(0.0, 0.0, backOffset), 0.7);
	setVertex(base, vec3(1.0, 0.0, frontOffset), 0.7);
	setVertex(base, vec3(1.0, 0.0, backOffset), 0.7);
	EndPrimitive();

	if (!isSolid(ivec2(-1, 0)) || !isFutureSolid(ivec2(-1, -1))) {
		float sideOffset = backOffset;
		if (isSolid(ivec2(-1, 1)) && !isFutureSolid(ivec2(-1, 0))) {
			sideOffset = 1.0;
		}
		// -X
		setVertex(base, vec3(0.0, 0.0, frontOffset), 0.8);
		setVertex(base, vec3(0.0, 1.0, frontOffset), 0.8);
		setVertex(base, vec3(0.0, 0.0, sideOffset), 0.8);
		setVertex(base, vec3(0.0, 1.0, sideOffset), 0.8);
		EndPrimitive();
	}

	if (!isSolid(ivec2(1, 0)) || !isFutureSolid(ivec2(1, -1))) {
		float sideOffset = backOffset;
		if (isSolid(ivec2(1, 1)) && !isFutureSolid(ivec2(1, 0))) {
			sideOffset = 1.0;
		}
		// +X
		setVertex(base, vec3(1.0, 0.0, frontOffset), 0.8);
		setVertex(base, vec3(1.0, 0.0, sideOffset), 0.8);
		setVertex(base, vec3(1.0, 1.0, frontOffset), 0.8);
		setVertex(base, vec3(1.0, 1.0, sideOffset), 0.8);
		EndPrimitive();
	}

	if (!isSolid(ivec2(0, 1)) || !isFutureSolid(ivec2(0, 0))) {
		// -Z
		setVertex(base, vec3(0.0, 0.0, backOffset), 0.8);
		setVertex(base, vec3(0.0, 1.0, backOffset), 0.8);
		setVertex(base, vec3(1.0, 0.0, backOffset), 0.8);
		setVertex(base, vec3(1.0, 1.0, backOffset), 0.8);
		EndPrimitive();
	}

	if (!isSolid(ivec2(0, -1)) || !isFutureSolid(ivec2(0, -2))) {
		// +Z
		setVertex(base, vec3(0.0, 0.0, frontOffset), 0.8);
		setVertex(base, vec3(1.0, 0.0, frontOffset), 0.8);
		setVertex(base, vec3(0.0, 1.0, frontOffset), 0.8);
		setVertex(base, vec3(1.0, 1.0, frontOffset), 0.8);
		EndPrimitive();
	}
}
`)
	glsl.Register("cloud_fragment", `
in vec4 fColor;
in vec3 fLighting;

out vec4 fragColor;

void main() {
	vec4 col = fColor;
	col.rgb *= fLighting;
	fragColor = col;
}
	`)
}