Skip to content

Commit

Permalink
Remove the vertical fog
Browse files Browse the repository at this point in the history
Improves the AoS 0.75 compatibility.
  • Loading branch information
yvt committed Nov 6, 2016
1 parent f649749 commit 4047b61
Show file tree
Hide file tree
Showing 29 changed files with 380 additions and 312 deletions.
28 changes: 15 additions & 13 deletions Resources/Shaders/BasicBlock.vs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/*
Copyright (c) 2013 yvt
This file is part of OpenSpades.
OpenSpades is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenSpades is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenSpades. If not, see <http://www.gnu.org/licenses/>.
*/


Expand All @@ -24,6 +24,7 @@ uniform mat4 projectionViewMatrix;
uniform mat4 viewMatrix;
uniform vec3 chunkPosition;
uniform float fogDistance;
uniform vec3 viewOriginVector;

// --- Vertex attribute ---
// [x, y, z]
Expand All @@ -50,23 +51,24 @@ void PrepareForShadowForMap(vec3 vertexCoord, vec3 fixedVertexCoord, vec3 normal
vec4 FogDensity(float poweredLength);

void main() {

vec4 vertexPos = vec4(chunkPosition, 1.);

vertexPos.xyz += positionAttribute.xyz;

gl_Position = projectionViewMatrix * vertexPos;

color = colorAttribute;
color.xyz *= color.xyz; // linearize

// ambient occlusion
ambientOcclusionCoord = (ambientOcclusionCoordAttribute + .5) * (1. / 256.);

vec4 viewPos = viewMatrix * vertexPos;
float distance = dot(viewPos.xyz, viewPos.xyz);
fogDensity = FogDensity(distance).xyz;

vec2 horzRelativePos = vertexPos.xy - viewOriginVector.xy;
float horzDistance = dot(horzRelativePos, horzRelativePos);
fogDensity = FogDensity(horzDistance).xyz;

vec3 fixedPosition = chunkPosition;
fixedPosition += fixedPositionAttribute * 0.5;
fixedPosition += normalAttribute * 0.1;
Expand Down
30 changes: 16 additions & 14 deletions Resources/Shaders/BasicBlockDynamicLit.vs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/*
Copyright (c) 2013 yvt
This file is part of OpenSpades.
OpenSpades is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenSpades is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenSpades. If not, see <http://www.gnu.org/licenses/>.
*/


Expand All @@ -24,6 +24,7 @@ uniform mat4 projectionViewMatrix;
uniform mat4 viewMatrix;
uniform vec3 chunkPosition;
uniform float fogDistance;
uniform vec3 viewOriginVector;

// --- Vertex attribute ---
// [x, y, z]
Expand All @@ -43,23 +44,24 @@ void PrepareForDynamicLightNoBump(vec3 vertexCoord, vec3 normal);
vec4 FogDensity(float poweredLength);

void main() {

vec4 vertexPos = vec4(chunkPosition, 1.);

vertexPos.xyz += positionAttribute.xyz;

gl_Position = projectionViewMatrix * vertexPos;

color = colorAttribute;
color.xyz *= color.xyz; // linearize

vec4 viewPos = viewMatrix * vertexPos;
float distance = dot(viewPos.xyz, viewPos.xyz);
fogDensity = FogDensity(distance).xyz;

vec2 horzRelativePos = vertexPos.xy - viewOriginVector.xy;
float horzDistance = dot(horzRelativePos, horzRelativePos);
fogDensity = FogDensity(horzDistance).xyz;

vec3 normal = normalAttribute;
vec3 shadowVertexPos = vertexPos.xyz;

PrepareForDynamicLightNoBump(shadowVertexPos, normal);
}

34 changes: 18 additions & 16 deletions Resources/Shaders/BasicBlockPhys.vs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/*
Copyright (c) 2013 yvt
This file is part of OpenSpades.
OpenSpades is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenSpades is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenSpades. If not, see <http://www.gnu.org/licenses/>.
*/


Expand All @@ -24,6 +24,7 @@ uniform mat4 projectionViewMatrix;
uniform mat4 viewMatrix;
uniform vec3 chunkPosition;
uniform float fogDistance;
uniform vec3 viewOriginVector;

// --- Vertex attribute ---
// [x, y, z]
Expand Down Expand Up @@ -52,36 +53,37 @@ void PrepareForShadowForMap(vec3 vertexCoord, vec3 fixedVertexCoord, vec3 normal
vec4 FogDensity(float poweredLength);

void main() {

vec4 vertexPos = vec4(chunkPosition, 1.);

vertexPos.xyz += positionAttribute.xyz;

gl_Position = projectionViewMatrix * vertexPos;

color = colorAttribute;
color.xyz *= color.xyz; // linearize

// lambert reflection
vec3 sunDir = normalize(vec3(0, -1., -1.));
color.w = dot(sunDir, normalAttribute);


// ambient occlusion
ambientOcclusionCoord = (ambientOcclusionCoordAttribute + .5) * (1. / 256.);

vec4 viewPos = viewMatrix * vertexPos;
float distance = dot(viewPos.xyz, viewPos.xyz);
fogDensity = FogDensity(distance).xyz;

vec2 horzRelativePos = vertexPos.xy - viewOriginVector.xy;
float horzDistance = dot(horzRelativePos, horzRelativePos);
fogDensity = FogDensity(horzDistance).xyz;

vec3 fixedPosition = chunkPosition;
fixedPosition += fixedPositionAttribute * 0.5;
fixedPosition += normalAttribute * 0.1;

vec3 normal = normalAttribute;
vec3 shadowVertexPos = vertexPos.xyz;
PrepareForShadowForMap(shadowVertexPos, fixedPosition, normal);

// used for diffuse lighting
viewSpaceCoord = viewPos.xyz;
viewSpaceNormal = (viewMatrix * vec4(normal, 0.)).xyz;
Expand Down
24 changes: 13 additions & 11 deletions Resources/Shaders/LongSprite.vs
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
/*
Copyright (c) 2013 yvt
This file is part of OpenSpades.
OpenSpades is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenSpades is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenSpades. If not, see <http://www.gnu.org/licenses/>.
*/


uniform mat4 projectionViewMatrix;
uniform mat4 viewMatrix;
uniform vec3 rightVector;
uniform vec3 upVector;
uniform vec3 viewOriginVector;

uniform float fogDistance;

Expand All @@ -38,18 +39,19 @@ vec4 FogDensity(float poweredLength);

void main() {
vec3 pos = positionAttribute.xyz;

gl_Position = projectionViewMatrix * vec4(pos,1.);

color = colorAttribute;

texCoord = texCoordAttribute;

// fog.
// FIXME: cannot gamma correct because sprite may be
// alpha-blended.
vec4 viewPos = viewMatrix * vec4(pos,1.);
float distance = dot(viewPos.xyz, viewPos.xyz);
fogDensity = FogDensity(distance);
vec2 horzRelativePos = pos.xy - viewOriginVector.xy;
float horzDistance = dot(horzRelativePos, horzRelativePos);
fogDensity = FogDensity(horzDistance);
}

30 changes: 16 additions & 14 deletions Resources/Shaders/OptimizedVoxelModel.vs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/*
Copyright (c) 2013 yvt
This file is part of OpenSpades.
OpenSpades is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenSpades is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenSpades. If not, see <http://www.gnu.org/licenses/>.
*/


Expand All @@ -28,6 +28,7 @@ uniform vec3 modelOrigin;
uniform float fogDistance;
uniform vec3 sunLightDirection;
uniform vec2 texScale;
uniform vec3 viewOriginVector;

// [x, y, z]
attribute vec3 positionAttribute;
Expand All @@ -48,27 +49,28 @@ void PrepareForShadow(vec3 worldOrigin, vec3 normal);
vec4 FogDensity(float poweredLength);

void main() {

vec4 vertexPos = vec4(positionAttribute.xyz, 1.);

vertexPos.xyz += modelOrigin;

gl_Position = projectionViewModelMatrix * vertexPos;

textureCoord = textureCoordAttribute.xyxy * vec4(texScale.xy, vec2(1.));

// direct sunlight
vec3 normal = normalAttribute;
normal = (modelNormalMatrix * vec4(normal, 1.)).xyz;
normal = normalize(normal);
float sunlight = dot(normal, sunLightDirection);
sunlight = max(sunlight, 0.);
flatShading = sunlight;

vec4 viewPos = viewModelMatrix * vertexPos;
float distance = dot(viewPos.xyz, viewPos.xyz);
fogDensity = FogDensity(distance).xyz;

vec2 horzRelativePos = (modelMatrix * vertexPos).xy - viewOriginVector.xy;
float horzDistance = dot(horzRelativePos, horzRelativePos);
fogDensity = FogDensity(horzDistance).xyz;

PrepareForShadow((modelMatrix * vertexPos).xyz, normal);
}

Loading

0 comments on commit 4047b61

Please sign in to comment.