implement basic shader
This commit is contained in:
parent
563f235b2f
commit
cf0239c76e
6 changed files with 114 additions and 104 deletions
|
@ -826,6 +826,7 @@ public class Client implements IThreadListener {
|
||||||
Font.unloadFonts();
|
Font.unloadFonts();
|
||||||
Font.loadFonts();
|
Font.loadFonts();
|
||||||
Font.select(this.font);
|
Font.select(this.font);
|
||||||
|
Shader.loadShaders();
|
||||||
this.textureManager.onReload();
|
this.textureManager.onReload();
|
||||||
this.modelManager.onReload();
|
this.modelManager.onReload();
|
||||||
this.renderItem.onReload();
|
this.renderItem.onReload();
|
||||||
|
|
|
@ -19,6 +19,7 @@ import java.util.function.Predicate;
|
||||||
import org.lwjgl.opengl.GL46;
|
import org.lwjgl.opengl.GL46;
|
||||||
|
|
||||||
import client.Client;
|
import client.Client;
|
||||||
|
import client.renderer.Shader.ShaderContext;
|
||||||
import client.renderer.blockmodel.BakedModel;
|
import client.renderer.blockmodel.BakedModel;
|
||||||
import client.renderer.blockmodel.BakedQuad;
|
import client.renderer.blockmodel.BakedQuad;
|
||||||
import client.renderer.blockmodel.IBakedModel;
|
import client.renderer.blockmodel.IBakedModel;
|
||||||
|
@ -1219,7 +1220,7 @@ public class Renderer {
|
||||||
this.updateChunks(finishTimeNano);
|
this.updateChunks(finishTimeNano);
|
||||||
GL46.glMatrixMode(GL46.GL_MODELVIEW);
|
GL46.glMatrixMode(GL46.GL_MODELVIEW);
|
||||||
GL46.glPushMatrix();
|
GL46.glPushMatrix();
|
||||||
this.renderBlockLayer((double)partialTicks, entity);
|
this.renderChunks();
|
||||||
GlState.shadeModel(GL46.GL_FLAT);
|
GlState.shadeModel(GL46.GL_FLAT);
|
||||||
GlState.alphaFunc(GL46.GL_GREATER, 0.1F);
|
GlState.alphaFunc(GL46.GL_GREATER, 0.1F);
|
||||||
|
|
||||||
|
@ -2561,72 +2562,112 @@ public class Renderer {
|
||||||
return new Vector3f(f3 * f4, f5, f2 * f4);
|
return new Vector3f(f3 * f4, f5, f2 * f4);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int renderBlockLayer(double partialTicks, Entity entityIn)
|
private int renderChunks()
|
||||||
{
|
{
|
||||||
ItemRenderer.disableStandardItemLighting();
|
ItemRenderer.disableStandardItemLighting();
|
||||||
|
|
||||||
int l = 0;
|
int l = 0;
|
||||||
int i = this.renderInfos.size();
|
int i = this.renderInfos.size();
|
||||||
|
|
||||||
for (int j = 0; j < i; j++)
|
for (int j = 0; j < i; j++)
|
||||||
{
|
{
|
||||||
RenderChunk renderchunk = ((RenderInfo)this.renderInfos.get(j)).chunk;
|
RenderChunk renderchunk = this.renderInfos.get(j).chunk;
|
||||||
|
|
||||||
if (!renderchunk.getCompiledChunk().isLayerEmpty())
|
if (!renderchunk.getCompiledChunk().isLayerEmpty())
|
||||||
{
|
{
|
||||||
++l;
|
++l;
|
||||||
this.addRenderChunk(renderchunk);
|
this.renderChunks.add(renderchunk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.renderBlockLayer();
|
// this.gm.renderer.enableLightmap();
|
||||||
return l;
|
GlState.setActiveTexture(GL46.GL_TEXTURE1);
|
||||||
}
|
GL46.glMatrixMode(GL46.GL_TEXTURE);
|
||||||
|
GL46.glLoadIdentity();
|
||||||
|
// float f = 0.00390625F;
|
||||||
|
// GL46.glScalef(f, f, f);
|
||||||
|
// GL46.glTranslatef(8.0F, 8.0F, 8.0F);
|
||||||
|
GL46.glMatrixMode(GL46.GL_MODELVIEW);
|
||||||
|
this.gm.getTextureManager().bindTexture(TEX_LIGHTMAP);
|
||||||
|
GL46.glTexParameteri(GL46.GL_TEXTURE_2D, GL46.GL_TEXTURE_MIN_FILTER, GL46.GL_LINEAR);
|
||||||
|
GL46.glTexParameteri(GL46.GL_TEXTURE_2D, GL46.GL_TEXTURE_MAG_FILTER, GL46.GL_LINEAR);
|
||||||
|
GL46.glTexParameteri(GL46.GL_TEXTURE_2D, GL46.GL_TEXTURE_WRAP_S, GL46.GL_CLAMP);
|
||||||
|
GL46.glTexParameteri(GL46.GL_TEXTURE_2D, GL46.GL_TEXTURE_WRAP_T, GL46.GL_CLAMP);
|
||||||
|
GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||||
|
GlState.enableTexture2D();
|
||||||
|
GlState.setActiveTexture(GL46.GL_TEXTURE0);
|
||||||
|
|
||||||
|
// GL46.glEnableClientState(GL46.GL_VERTEX_ARRAY);
|
||||||
|
// GL46.glClientActiveTexture(GL46.GL_TEXTURE0);
|
||||||
|
// GL46.glEnableClientState(GL46.GL_TEXTURE_COORD_ARRAY);
|
||||||
|
// GL46.glClientActiveTexture(GL46.GL_TEXTURE1);
|
||||||
|
// GL46.glEnableClientState(GL46.GL_TEXTURE_COORD_ARRAY);
|
||||||
|
// GL46.glClientActiveTexture(GL46.GL_TEXTURE0);
|
||||||
|
// GL46.glEnableClientState(GL46.GL_COLOR_ARRAY);
|
||||||
|
|
||||||
private void renderBlockLayer()
|
if (this.initialized)
|
||||||
{
|
{
|
||||||
this.gm.renderer.enableLightmap();
|
ShaderContext context = Shader.WORLD.use();
|
||||||
|
for (RenderChunk renderchunk : this.renderChunks)
|
||||||
// if (OpenGl.useVbo())
|
|
||||||
// {
|
|
||||||
GL46.glEnableClientState(GL46.GL_VERTEX_ARRAY);
|
|
||||||
GL46.glClientActiveTexture(GL46.GL_TEXTURE0);
|
|
||||||
GL46.glEnableClientState(GL46.GL_TEXTURE_COORD_ARRAY);
|
|
||||||
GL46.glClientActiveTexture(GL46.GL_TEXTURE1);
|
|
||||||
GL46.glEnableClientState(GL46.GL_TEXTURE_COORD_ARRAY);
|
|
||||||
GL46.glClientActiveTexture(GL46.GL_TEXTURE0);
|
|
||||||
GL46.glEnableClientState(GL46.GL_COLOR_ARRAY);
|
|
||||||
// }
|
|
||||||
|
|
||||||
this.renderChunkLayer();
|
|
||||||
|
|
||||||
// if (OpenGl.useVbo())
|
|
||||||
// {
|
|
||||||
for (VertexFormatElement vertexformatelement : DefaultVertexFormats.BLOCK.getElements())
|
|
||||||
{
|
{
|
||||||
VertexFormatElement.EnumUsage vertexformatelement$enumusage = vertexformatelement.usage();
|
VertexBuffer vertexbuffer = renderchunk.getVertexBuffer();
|
||||||
int i = vertexformatelement.index();
|
|
||||||
|
|
||||||
switch (vertexformatelement$enumusage)
|
BlockPos blockpos = renderchunk.getPosition();
|
||||||
{
|
context.vec("offset", (float)((double)blockpos.getX() - this.viewEntityX), (float)((double)blockpos.getY() - this.viewEntityY), (float)((double)blockpos.getZ() - this.viewEntityZ));
|
||||||
case POSITION:
|
context.matrix("model", renderchunk.getModelviewMatrix());
|
||||||
GL46.glDisableClientState(GL46.GL_VERTEX_ARRAY);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case UV:
|
vertexbuffer.bindBuffer();
|
||||||
GL46.glClientActiveTexture(GL46.GL_TEXTURE0 + i);
|
|
||||||
GL46.glDisableClientState(GL46.GL_TEXTURE_COORD_ARRAY);
|
|
||||||
GL46.glClientActiveTexture(GL46.GL_TEXTURE0);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case COLOR:
|
GL46.glVertexAttribPointer(0, 3, GL46.GL_FLOAT, false, 28, 0L);
|
||||||
GL46.glDisableClientState(GL46.GL_COLOR_ARRAY);
|
GL46.glEnableVertexAttribArray(0);
|
||||||
GlState.resetColor();
|
GL46.glVertexAttribPointer(1, 4, GL46.GL_UNSIGNED_BYTE, true, 28, 12L);
|
||||||
}
|
GL46.glEnableVertexAttribArray(1);
|
||||||
|
GL46.glVertexAttribPointer(2, 2, GL46.GL_FLOAT, false, 28, 16L);
|
||||||
|
GL46.glEnableVertexAttribArray(2);
|
||||||
|
GL46.glVertexAttribPointer(3, 2, GL46.GL_UNSIGNED_SHORT, true, 28, 24L);
|
||||||
|
GL46.glEnableVertexAttribArray(3);
|
||||||
|
|
||||||
|
// GL46.nglVertexPointer(3, GL46.GL_FLOAT, 28, 0L);
|
||||||
|
// GL46.nglColorPointer(4, GL46.GL_UNSIGNED_BYTE, 28, 12L);
|
||||||
|
// GL46.glTexCoordPointer(2, GL46.GL_FLOAT, 28, 16L);
|
||||||
|
// GL46.glClientActiveTexture(GL46.GL_TEXTURE1);
|
||||||
|
// GL46.glTexCoordPointer(2, GL46.GL_SHORT, 28, 24L);
|
||||||
|
// GL46.glClientActiveTexture(GL46.GL_TEXTURE0);
|
||||||
|
|
||||||
|
vertexbuffer.drawArrays(GL46.GL_QUADS);
|
||||||
|
|
||||||
|
GL46.glDisableVertexAttribArray(0);
|
||||||
|
GL46.glDisableVertexAttribArray(1);
|
||||||
|
GL46.glDisableVertexAttribArray(2);
|
||||||
|
GL46.glDisableVertexAttribArray(3);
|
||||||
}
|
}
|
||||||
// }
|
context.finish();
|
||||||
|
|
||||||
|
GL46.glBindBuffer(GL46.GL_ARRAY_BUFFER, 0);
|
||||||
|
GlState.resetColor();
|
||||||
|
this.renderChunks.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
// for (VertexFormatElement vertexformatelement : DefaultVertexFormats.BLOCK.getElements())
|
||||||
|
// {
|
||||||
|
// VertexFormatElement.EnumUsage vertexformatelement$enumusage = vertexformatelement.usage();
|
||||||
|
// int s = vertexformatelement.index();
|
||||||
|
//
|
||||||
|
// switch (vertexformatelement$enumusage)
|
||||||
|
// {
|
||||||
|
// case POSITION:
|
||||||
|
// GL46.glDisableClientState(GL46.GL_VERTEX_ARRAY);
|
||||||
|
// break;
|
||||||
|
//
|
||||||
|
// case UV:
|
||||||
|
// GL46.glClientActiveTexture(GL46.GL_TEXTURE0 + s);
|
||||||
|
// GL46.glDisableClientState(GL46.GL_TEXTURE_COORD_ARRAY);
|
||||||
|
// GL46.glClientActiveTexture(GL46.GL_TEXTURE0);
|
||||||
|
// break;
|
||||||
|
//
|
||||||
|
// case COLOR:
|
||||||
|
// GL46.glDisableClientState(GL46.GL_COLOR_ARRAY);
|
||||||
|
// GlState.resetColor();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
this.gm.renderer.disableLightmap();
|
this.gm.renderer.disableLightmap();
|
||||||
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cleanupDamagedBlocks(Iterator<DestroyProgress> iteratorIn)
|
private void cleanupDamagedBlocks(Iterator<DestroyProgress> iteratorIn)
|
||||||
|
@ -3303,49 +3344,6 @@ public class Renderer {
|
||||||
this.viewEntityZ = viewEntityZIn;
|
this.viewEntityZ = viewEntityZIn;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void preRenderChunk(RenderChunk renderChunkIn)
|
|
||||||
{
|
|
||||||
BlockPos blockpos = renderChunkIn.getPosition();
|
|
||||||
GL46.glTranslatef((float)((double)blockpos.getX() - this.viewEntityX), (float)((double)blockpos.getY() - this.viewEntityY), (float)((double)blockpos.getZ() - this.viewEntityZ));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addRenderChunk(RenderChunk renderChunkIn)
|
|
||||||
{
|
|
||||||
this.renderChunks.add(renderChunkIn);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void renderChunkLayer()
|
|
||||||
{
|
|
||||||
if (this.initialized)
|
|
||||||
{
|
|
||||||
for (RenderChunk renderchunk : this.renderChunks)
|
|
||||||
{
|
|
||||||
VertexBuffer vertexbuffer = renderchunk.getVertexBuffer();
|
|
||||||
GL46.glPushMatrix();
|
|
||||||
this.preRenderChunk(renderchunk);
|
|
||||||
renderchunk.multModelviewMatrix();
|
|
||||||
vertexbuffer.bindBuffer();
|
|
||||||
this.setupArrayPointers();
|
|
||||||
vertexbuffer.drawArrays(GL46.GL_QUADS);
|
|
||||||
GL46.glPopMatrix();
|
|
||||||
}
|
|
||||||
|
|
||||||
GL46.glBindBuffer(GL46.GL_ARRAY_BUFFER, 0);
|
|
||||||
GlState.resetColor();
|
|
||||||
this.renderChunks.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setupArrayPointers()
|
|
||||||
{
|
|
||||||
GL46.nglVertexPointer(3, GL46.GL_FLOAT, 28, 0L);
|
|
||||||
GL46.nglColorPointer(4, GL46.GL_UNSIGNED_BYTE, 28, 12L);
|
|
||||||
GL46.glTexCoordPointer(2, GL46.GL_FLOAT, 28, 16L);
|
|
||||||
GL46.glClientActiveTexture(GL46.GL_TEXTURE1);
|
|
||||||
GL46.glTexCoordPointer(2, GL46.GL_SHORT, 28, 24L);
|
|
||||||
GL46.glClientActiveTexture(GL46.GL_TEXTURE0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void renderStarField(int w, int h, int bg, int color, float ticks, Random rand) {
|
public void renderStarField(int w, int h, int bg, int color, float ticks, Random rand) {
|
||||||
long seed = rand.getSeed();
|
long seed = rand.getSeed();
|
||||||
Vec3 stars = new Vec3(color);
|
Vec3 stars = new Vec3(color);
|
||||||
|
|
|
@ -22,7 +22,7 @@ import common.util.Vector3f;
|
||||||
import common.util.Vector4f;
|
import common.util.Vector4f;
|
||||||
|
|
||||||
public enum Shader {
|
public enum Shader {
|
||||||
WORLD("world", "world", context -> {context.integer("tex", 0); GL46.glUniformBlockBinding(context.getProgram(), GL46.glGetUniformBlockIndex(context.getProgram(), "light_block"), 0);}, context -> {
|
WORLD("world", "world", context -> {context.integer("tex", 0); context.integer("lightmap", 1); /* GL46.glUniformBlockBinding(context.getProgram(), GL46.glGetUniformBlockIndex(context.getProgram(), "light_block"), 0); */}, context -> {
|
||||||
context.vec("clip_near", Client.CLIENT.renderer.getNearPlane());
|
context.vec("clip_near", Client.CLIENT.renderer.getNearPlane());
|
||||||
context.vec("clip_far", Client.CLIENT.renderer.getFarPlane());
|
context.vec("clip_far", Client.CLIENT.renderer.getFarPlane());
|
||||||
context.vec("screen", (float)Client.CLIENT.fbRawX, (float)Client.CLIENT.fbRawY);
|
context.vec("screen", (float)Client.CLIENT.fbRawX, (float)Client.CLIENT.fbRawY);
|
||||||
|
|
|
@ -257,9 +257,9 @@ public class RenderChunk
|
||||||
GL46.glPopMatrix();
|
GL46.glPopMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void multModelviewMatrix()
|
public FloatBuffer getModelviewMatrix()
|
||||||
{
|
{
|
||||||
GL46.glMultMatrixf(this.modelviewMatrix);
|
return this.modelviewMatrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompiledChunk getCompiledChunk()
|
public CompiledChunk getCompiledChunk()
|
||||||
|
|
|
@ -10,10 +10,13 @@ struct light_t {
|
||||||
|
|
||||||
in vec3 vertex;
|
in vec3 vertex;
|
||||||
in vec3 normal;
|
in vec3 normal;
|
||||||
|
in vec4 brightness;
|
||||||
in vec2 tex_coord;
|
in vec2 tex_coord;
|
||||||
|
in vec2 lm_coord;
|
||||||
|
|
||||||
uniform vec3 cam_pos;
|
uniform vec3 cam_pos;
|
||||||
uniform sampler2D tex;
|
uniform sampler2D tex;
|
||||||
|
uniform sampler2D lightmap;
|
||||||
uniform vec3 specular;
|
uniform vec3 specular;
|
||||||
uniform float shine;
|
uniform float shine;
|
||||||
uniform float max_vert_dist;
|
uniform float max_vert_dist;
|
||||||
|
@ -72,8 +75,9 @@ vec3 calc_point_light(light_t light, vec3 norm, vec3 dir, vec3 rgb) {
|
||||||
void main() {
|
void main() {
|
||||||
vec3 norm = normalize(normal);
|
vec3 norm = normalize(normal);
|
||||||
vec3 dir = normalize(cam_pos - vertex);
|
vec3 dir = normalize(cam_pos - vertex);
|
||||||
vec4 texel = texture(tex, tex_coord);
|
vec4 texel = texture(tex, tex_coord) * brightness;
|
||||||
vec3 rgb = texel.rgb * texel.a;
|
vec3 light_v = texture(lightmap, vec2(0.03125 + lm_coord.x * 256, 0.03125 + lm_coord.y * 256)).rgb;
|
||||||
|
vec3 rgb = texel.rgb;
|
||||||
vec3 result = calc_dir_light(norm, dir, rgb);
|
vec3 result = calc_dir_light(norm, dir, rgb);
|
||||||
// int l = 0;
|
// int l = 0;
|
||||||
for(int z = 0; z < n_lights; z++) {
|
for(int z = 0; z < n_lights; z++) {
|
||||||
|
@ -83,5 +87,5 @@ void main() {
|
||||||
// l++;
|
// l++;
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
FragColor = vec4(result, 1.0);
|
FragColor = texel * vec4(light_v, 1.0); // vec4(result, texel.a);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,27 @@
|
||||||
layout (location = 0) in vec3 pos;
|
layout (location = 0) in vec3 pos;
|
||||||
layout (location = 1) in vec3 norm;
|
// layout (location = 1) in vec3 norm;
|
||||||
|
layout (location = 1) in vec4 color;
|
||||||
layout (location = 2) in vec2 coord;
|
layout (location = 2) in vec2 coord;
|
||||||
|
layout (location = 3) in vec2 light;
|
||||||
|
|
||||||
out vec3 vertex;
|
out vec3 vertex;
|
||||||
out vec3 normal;
|
out vec3 normal;
|
||||||
|
out vec4 brightness;
|
||||||
out vec2 tex_coord;
|
out vec2 tex_coord;
|
||||||
|
out vec2 lm_coord;
|
||||||
|
|
||||||
uniform mat4 model;
|
uniform mat4 model;
|
||||||
uniform mat4 view;
|
uniform mat4 view;
|
||||||
uniform mat4 projection;
|
uniform mat4 projection;
|
||||||
uniform sampler2D tex;
|
uniform sampler2D tex;
|
||||||
uniform float density;
|
uniform vec3 offset;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
vec3 norm = vec3(0.0, 1.0, 0.0);
|
||||||
vertex = vec3(model * vec4(pos, 1.0));
|
vertex = vec3(model * vec4(pos, 1.0));
|
||||||
normal = mat3(transpose(inverse(model))) * norm;
|
normal = mat3(transpose(inverse(model))) * norm;
|
||||||
tex_coord = coord * density / textureSize(tex, 0);
|
brightness = color;
|
||||||
gl_Position = projection * view * vec4(vertex, 1.0);
|
tex_coord = coord;
|
||||||
|
lm_coord = light;
|
||||||
|
gl_Position = projection * view * vec4(offset + vertex, 1.0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue