Skip to content

Commit

Permalink
Rendering optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
uis246 committed Nov 28, 2020
1 parent b1270a8 commit 745f7ba
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 30 deletions.
5 changes: 2 additions & 3 deletions cwd/assets/altcraft/shaders/entity.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"frag": "/altcraft/shaders/frag/entity",
"uniforms": [
"color",
"view",
"projection",
"projView",
"model"
]
}
}
5 changes: 2 additions & 3 deletions cwd/assets/altcraft/shaders/sky.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"vert": "/altcraft/shaders/vert/sky",
"frag": "/altcraft/shaders/frag/sky",
"uniforms": [
"view",
"projection",
"projView",
"model",
"textureAtlas",
"DayTime",
Expand All @@ -12,4 +11,4 @@
"moonTexture",
"moonTextureLayer"
]
}
}
13 changes: 8 additions & 5 deletions cwd/assets/altcraft/shaders/vert/entity.vs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#version 330 core

uniform mat4 view;
uniform mat4 projection;
uniform mat4 model;
uniform mat4 projView;
uniform mat4 model;
layout (location = 0) in vec3 position;
layout (location = 1) in vec2 uvPosition;
out vec2 uvPos;

//Intel SNB
//VS vec4 shader: 23 instructions. 0 loops. 176 cycles. 0:0 spills:fills, 1 sends. Compacted 368 to 320 bytes (13%)
//Opt: VS vec4 shader: 16 instructions. 0 loops. 116 cycles. 0:0 spills:fills, 1 sends. Compacted 256 to 224 bytes (12%)

void main(){
uvPos = uvPosition;
gl_Position = projection*view*model*vec4(position,1);
}
gl_Position = projView*model*vec4(position,1);
}
19 changes: 10 additions & 9 deletions cwd/assets/altcraft/shaders/vert/face.vs
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,25 @@ out VS_OUT {
flat vec3 Color;
} vs_out;

//Intel SNB: VS vec4 shader: 55 instructions. 0 loops. 196 cycles. 0:0 spills:fills, 1 sends. Compacted 880 to 864 bytes (2%)
//Intel SNB: VS vec4 shader: 54 instructions. 0 loops. 194 cycles. 0:0 spills:fills, 1 sends. Compacted 864 to 848 bytes (2%)

void main() {
gl_Position = projView * vec4(positions[gl_VertexID], 1.0);

vec4 subUV = vec4(
uvec4(qinfo, qinfo >> uint(5)) & uint(0x1F)
) / 16.0;

vec4 tex = vec4(utex) / 1024.0;
vec4 tex = vec4(utex) * 0.0009765625 /* /1024.0 */;
float frames = float(phlf.w);
tex.w /= frames;
tex.y += trunc(mod(GlobalTime * 4.0f, frames)) * tex.w;

tex.xy += subUV.xy * tex.zw;
tex.zw = (subUV.zw-subUV.xy) * tex.zw;
vec4 subUV = vec4(
uvec4(qinfo, qinfo >> uint(5)) & uint(0x1F)
) * 0.0625 /* /16.0 */;

// tex.xy += subUV.xy * tex.zw;
// tex.zw = subUV.zw * tex.zw * uv;
// UvPosition = tex.xy + tex.zw;

UvPosition = tex.xy + tex.zw*uv;
UvPosition = tex.xy + subUV.xy*tex.zw + subUV.zw*tex.zw*uv;
Layer = phlf.z;

vec2 light = vec2((qinfo >> uint(10)) & uint(0xF)) / 15.0;
Expand Down
5 changes: 4 additions & 1 deletion cwd/assets/altcraft/shaders/vert/fbo.vs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ layout (location = 1) in vec2 TextureCoords;

out vec2 TexCoords;

//Intel SNB
//VS vec4 shader: 6 instructions. 0 loops. 22 cycles. 0:0 spills:fills, 1 sends. Compacted 96 to 96 bytes (0%)

void main()
{
gl_Position = vec4(Pos.x, Pos.y, 0.0, 1.0);
TexCoords = TextureCoords;
}
}
13 changes: 8 additions & 5 deletions cwd/assets/altcraft/shaders/vert/sky.vs
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
#version 330 core

uniform mat4 view;
uniform mat4 projection;
uniform mat4 model;
uniform mat4 projView;
uniform mat4 model;

layout (location = 0) in vec3 position;
layout (location = 1) in vec2 uvPosition;

out vec2 uvPos;
out vec3 pos;

//Intel SNB
//VS vec4 shader: 24 instructions. 0 loops. 178 cycles. 0:0 spills:fills, 1 sends. Compacted 384 to 336 bytes (12%)
//Opt: VS vec4 shader: 17 instructions. 0 loops. 116 cycles. 0:0 spills:fills, 1 sends. Compacted 272 to 240 bytes (12%)

void main(){
uvPos = uvPosition;
pos = position;
gl_Position = projection*view*model*vec4(position,1);
}
gl_Position = projView*model*vec4(position,1);
}
6 changes: 2 additions & 4 deletions src/RendererWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,7 @@ void RendererWorld::Render(RenderState & renderState) {
if (entityNode->type==AssetTreeNode::ASSET_SHADER)
entityShader = reinterpret_cast<AssetShader*>(entityNode->asset.get())->shader.get();
entityShader->Activate();
entityShader->SetUniform("projection", projection);
entityShader->SetUniform("view", view);
entityShader->SetUniform("projView", projView);
glCheckError();

renderState.SetActiveVao(RendererEntity::GetVao());
Expand Down Expand Up @@ -410,8 +409,7 @@ void RendererWorld::Render(RenderState & renderState) {
if (skyNode->type==AssetTreeNode::ASSET_SHADER)
skyShader = reinterpret_cast<AssetShader*>(skyNode->asset.get())->shader.get();
skyShader->Activate();
skyShader->SetUniform("projection", projection);
skyShader->SetUniform("view", view);
skyShader->SetUniform("projView", projection);
glm::mat4 model = glm::mat4(1.0);
model = glm::translate(model, GetGameState()->GetPlayer()->pos.glm());
const float scale = 1000000.0f;
Expand Down

0 comments on commit 745f7ba

Please sign in to comment.