forked from yvt/openspades
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Original author: dd
- Loading branch information
Showing
51 changed files
with
2,472 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Shaders/BasicBlockOutlines.fs | ||
Shaders/BasicBlockOutlines.vs | ||
*shadow* | ||
Shaders/Fog.vs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Shaders/BasicBlockTextures.fs | ||
Shaders/BasicBlockTextures.vs | ||
*shadow* | ||
Shaders/Fog.vs |
Oops, something went wrong.