Skip to content

Commit

Permalink
Fixes yvt#807
Browse files Browse the repository at this point in the history
Original author: dd
  • Loading branch information
Conticop committed Aug 3, 2020
1 parent 8f21710 commit 10cdecd
Show file tree
Hide file tree
Showing 51 changed files with 2,472 additions and 203 deletions.
1 change: 1 addition & 0 deletions Resources/Scripts/Gui/Client/ChatSayWindow.as
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ namespace spades {
@field = CommandField(Manager, ui.chatHistory);
field.Bounds = AABB2(winX, winY, winW, 30.f);
field.Placeholder = _Tr("Client", "Chat Text");
field.MaxLength = 93; // ADDED
@field.Changed = spades::ui::EventHandler(this.OnFieldChanged);
AddChild(field);
}
Expand Down
15 changes: 15 additions & 0 deletions Resources/Scripts/Gui/Preferences.as
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,19 @@ namespace spades {
_Tr("Preferences", "OFF")},
array<int> = {2, 1, 0});

layouter.AddHeading(_Tr("Preferences", "OpenGL Effects")); // ADDED
layouter.AddToggleField(_Tr("Preferences", "Outlines"), "cg_outlines"); // ADDED
layouter.AddSliderField(_Tr("Preferences", "Outline Strength"), "cg_outlineStrength", 2, 5, 1, // ADDED
ConfigNumberFormatter(0, "px")); // ADDED
layouter.AddToggleField(_Tr("Preferences", "Textures"), "cg_textures"); // ADDED
layouter.AddToggleField(_Tr("Preferences", "Multi-Texture Mode"), "cg_multiTextures"); // ADDED
layouter.AddSliderField(_Tr("Preferences", "Texture Strength"), "cg_textureStrength", 0, 100, 1, // ADDED
ConfigNumberFormatter(0, "%")); // ADDED

layouter.AddHeading(_Tr("Preferences", "Spectator Tools")); // ADDED
layouter.AddToggleField(_Tr("Preferences", "Spectator Player Names"), "dd_specNames"); // ADDED
layouter.AddToggleField(_Tr("Preferences", "Spectator Wallhack"), "dd_specWallhack"); // ADDED

layouter.AddHeading(_Tr("Preferences", "Feedbacks"));
layouter.AddToggleField(_Tr("Preferences", "Chat Notify Sounds"), "cg_chatBeep");
layouter.AddToggleField(_Tr("Preferences", "Hit Indicator"), "cg_hitIndicator");
Expand All @@ -654,6 +667,8 @@ namespace spades {
layouter.AddToggleField(_Tr("Preferences", "Server Alert"), "cg_serverAlert");

layouter.AddHeading(_Tr("Preferences", "Misc"));
layouter.AddToggleField(_Tr("Preferences", "Cheats"), "sv_cheats"); // ADDED
layouter.AddSliderField(_Tr("Preferences", "Volume"), "s_volume", 0, 100, 1, ConfigNumberFormatter(0, "%")); // ADDED
layouter.AddSliderField(_Tr("Preferences", "Field of View"), "cg_fov", 45, 90, 1,
ConfigNumberFormatter(0, " deg"));
layouter.AddSliderField(_Tr("Preferences", "Minimap size"), "cg_minimapSize", 128, 256,
Expand Down
16 changes: 16 additions & 0 deletions Resources/Shaders/BasicBlockOutlines.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
uniform vec3 fogColor;
uniform vec3 outlineColor;

varying vec3 fogDensity;

void main() {

gl_FragColor.rgb = mix(outlineColor, fogColor, fogDensity);
gl_FragColor.a = 1.0;

#if !LINEAR_FRAMEBUFFER
// gamma correct
gl_FragColor.xyz = sqrt(gl_FragColor.xyz);
#endif
}

4 changes: 4 additions & 0 deletions Resources/Shaders/BasicBlockOutlines.program
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Shaders/BasicBlockOutlines.fs
Shaders/BasicBlockOutlines.vs
*shadow*
Shaders/Fog.vs
26 changes: 26 additions & 0 deletions Resources/Shaders/BasicBlockOutlines.vs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
uniform mat4 projectionViewMatrix;
uniform mat4 viewMatrix;
uniform vec3 chunkPosition;
uniform vec3 viewOriginVector;

attribute vec3 positionAttribute;

varying vec3 fogDensity;

vec4 FogDensity(float poweredLength);

void main() {

vec4 vertexPos = vec4(chunkPosition, 1.);

vertexPos.xyz += positionAttribute.xyz;

gl_Position = projectionViewMatrix * vertexPos;

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

}

105 changes: 105 additions & 0 deletions Resources/Shaders/BasicBlockPhysTextures.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
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/>.
*/



varying vec4 color;
varying vec2 ambientOcclusionCoord;
varying vec3 fogDensity;
varying vec2 blockTexCoord; // ADDED

varying vec3 viewSpaceCoord;
varying vec3 viewSpaceNormal;
uniform vec3 viewSpaceLight;

varying vec3 reflectionDir;

uniform sampler2D ambientOcclusionTexture;
uniform sampler2D detailTexture;
uniform vec3 fogColor;

uniform sampler2D blockTexture; // ADDED
uniform float blockTextureStrength; // ADDED

vec3 EvaluateSunLight();
vec3 EvaluateAmbientLight(float detailAmbientOcclusion);
vec3 EvaluateDirectionalAmbientLight(float detailAmbientOcclusion, vec3 direction);
//void VisibilityOfSunLight_Model_Debug();

float OrenNayar(float sigma, float dotLight, float dotEye);
float CockTorrance(vec3 eyeVec, vec3 lightVec, vec3 normal);

void main() {
// color is linear
gl_FragColor = vec4(color.xyz, 1.);

gl_FragColor.rgb = mix(gl_FragColor.rgb, texture2D(blockTexture, blockTexCoord).rgb, blockTextureStrength); // ADDED

vec3 shading = vec3(OrenNayar(.8, color.w,
-dot(viewSpaceNormal, normalize(viewSpaceCoord))));
vec3 sunLight = EvaluateSunLight();
shading *= sunLight;

float ao = texture2D(ambientOcclusionTexture, ambientOcclusionCoord).x;

shading += EvaluateAmbientLight(ao);

// apply diffuse shading
gl_FragColor.xyz *= shading;

// fresnel term
// FIXME: use split-sum approximation from UE4
float fresnel2 = 1. - (-dot(viewSpaceNormal, normalize(viewSpaceCoord)));
float fresnel = fresnel2 * fresnel2;

fresnel = .03 + fresnel * 0.1;

// blurred reflections
vec3 reflectWS = normalize(reflectionDir);
vec3 reflection = EvaluateDirectionalAmbientLight(ao, reflectWS);

gl_FragColor.xyz = mix(gl_FragColor.xyz, reflection, fresnel);

// specular shading
if(color.w > .1 && dot(sunLight, vec3(1.)) > 0.001){
vec3 specularColor = sunLight;
gl_FragColor.xyz += specularColor * CockTorrance(-normalize(viewSpaceCoord),
viewSpaceLight,
viewSpaceNormal);
}

// apply fog
gl_FragColor.xyz = mix(gl_FragColor.xyz, fogColor, fogDensity);

gl_FragColor.xyz = max(gl_FragColor.xyz, 0.);

// gamma correct
#if !LINEAR_FRAMEBUFFER
gl_FragColor.xyz = sqrt(gl_FragColor.xyz);
#endif

#if USE_HDR
// somehow denormal occurs, so detect it here and remove
// (denormal destroys screen)
if(gl_FragColor.xyz != gl_FragColor.xyz)
gl_FragColor.xyz = vec3(0.);
#endif
}

6 changes: 6 additions & 0 deletions Resources/Shaders/BasicBlockPhysTextures.program
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Shaders/BasicBlockPhysTextures.fs
Shaders/BasicBlockPhysTextures.vs
Shaders/PhysicalModel/OrenNayar.fs
Shaders/PhysicalModel/CookTorrance.fs
*shadow*
Shaders/Fog.vs
102 changes: 102 additions & 0 deletions Resources/Shaders/BasicBlockPhysTextures.vs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
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 chunkPosition;
uniform float fogDistance;
uniform vec3 viewOriginVector;

// --- Vertex attribute ---
// [x, y, z]
attribute vec3 positionAttribute;

// [ax, ay]
attribute vec2 ambientOcclusionCoordAttribute;

// [R, G, B, diffuse]
attribute vec4 colorAttribute;

// [nx, ny, nz]
attribute vec3 normalAttribute;

// [sx, sy, sz]
attribute vec3 fixedPositionAttribute;

// [ux, uy] // ADDED
attribute vec2 blockTexCoordAttribute; // ADDED

varying vec2 ambientOcclusionCoord;
varying vec4 color;
varying vec3 fogDensity;
varying vec2 blockTexCoord; // ADDED

varying vec3 viewSpaceCoord;
varying vec3 viewSpaceNormal;

varying vec3 reflectionDir;

void PrepareForShadowForMap(vec3 vertexCoord, vec3 fixedVertexCoord, vec3 normal);
vec4 FogDensity(float poweredLength);

void main() {

blockTexCoord = blockTexCoordAttribute; // ADDED

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;
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);

// reflection vector (used for specular lighting)
reflectionDir = reflect(vertexPos.xyz - viewOriginVector, normal);

// used for diffuse lighting
viewSpaceCoord = viewPos.xyz;
viewSpaceNormal = (viewMatrix * vec4(normal, 0.)).xyz;
}

64 changes: 64 additions & 0 deletions Resources/Shaders/BasicBlockTextures.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
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/>.
*/



varying vec4 color;
varying vec2 ambientOcclusionCoord;
varying vec2 detailCoord;
varying vec3 fogDensity;
varying vec2 blockTexCoord; // ADDED

uniform sampler2D ambientOcclusionTexture;
uniform sampler2D detailTexture;
uniform vec3 fogColor;

uniform sampler2D blockTexture; // ADDED
uniform float blockTextureStrength; // ADDED

vec3 EvaluateSunLight();
vec3 EvaluateAmbientLight(float detailAmbientOcclusion);
//void VisibilityOfSunLight_Model_Debug();

void main() {
// color is linear
gl_FragColor = vec4(color.xyz, 1.);

gl_FragColor.rgb = mix(gl_FragColor.rgb, texture2D(blockTexture, blockTexCoord).rgb, blockTextureStrength); // ADDED

vec3 shading = vec3(color.w);
shading *= EvaluateSunLight();

float ao = texture2D(ambientOcclusionTexture, ambientOcclusionCoord).x;

shading += EvaluateAmbientLight(ao);

// apply diffuse shading
gl_FragColor.xyz *= shading;

// apply fog
gl_FragColor.xyz = mix(gl_FragColor.xyz, fogColor, fogDensity);

#if !LINEAR_FRAMEBUFFER
// gamma correct
gl_FragColor.xyz = sqrt(gl_FragColor.xyz);
#endif
}

4 changes: 4 additions & 0 deletions Resources/Shaders/BasicBlockTextures.program
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Shaders/BasicBlockTextures.fs
Shaders/BasicBlockTextures.vs
*shadow*
Shaders/Fog.vs

0 comments on commit 10cdecd

Please sign in to comment.