Skip to content

Commit

Permalink
Integrated various graphical tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
immortius committed Aug 17, 2013
1 parent cceb5d4 commit 4ad8748
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 24 deletions.
2 changes: 2 additions & 0 deletions intellij-setup.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
call gradlew.bat cleanIdea idea
pause
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ public enum LightType {
public Vector3f lightColorAmbient = new Vector3f(1.0f, 1.0f, 1.0f);

@Replicate
public float lightDiffuseIntensity = 2.0f;
public float lightDiffuseIntensity = 1.0f;
@Replicate
public float lightSpecularIntensity = 0.1f;
@Replicate
public float lightAmbientIntensity = 1.0f;

@Replicate
public float lightSpecularPower = 4.0f;
public float lightSpecularPower = 1.0f;
@Replicate
public float lightAttenuationRange = 16.0f;
@Replicate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public class DefaultRenderingProcess {
@EditorRange(min = 0.0f, max = 10.0f)
private float hdrMaxExposure = 8.0f;
@EditorRange(min = 0.0f, max = 10.0f)
private float hdrMaxExposureNight = 1.0f;
private float hdrMaxExposureNight = 8.0f;
@EditorRange(min = 0.0f, max = 10.0f)
private float hdrMinExposure = 1.0f;
@EditorRange(min = 0.0f, max = 4.0f)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class ShaderParametersChunk extends ShaderParametersBase {
float waterOffsetY = 0.0f;

@EditorRange(min = 0.0f, max = 1024.0f)
float waterSpecExp = 512.0f;
float waterSpecExp = 200.0f;

@EditorRange(min = 0.0f, max = 0.5f)
float parallaxBias = 0.05f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ public WorldRenderer(WorldProvider worldProvider, ChunkProvider chunkProvider, L
mainDirectionalLight.lightType = LightComponent.LightType.DIRECTIONAL;
mainDirectionalLight.lightColorAmbient = new Vector3f(1.0f, 1.0f, 1.0f);
mainDirectionalLight.lightColorDiffuse = new Vector3f(1.0f, 1.0f, 1.0f);
mainDirectionalLight.lightAmbientIntensity = 2.0f;
mainDirectionalLight.lightDiffuseIntensity = 1.0f;
mainDirectionalLight.lightAmbientIntensity = 1.0f;
mainDirectionalLight.lightDiffuseIntensity = 2.0f;
mainDirectionalLight.lightSpecularIntensity = 0.0f;

localPlayerSystem.setPlayerCamera(localPlayerCamera);
Expand Down Expand Up @@ -734,6 +734,8 @@ public void renderWorld(Camera camera) {

// Sunlight
Vector3f sunlightWorldPosition = new Vector3f(skysphere.getSunDirection(true));
sunlightWorldPosition.scale(50000f);
sunlightWorldPosition.add(activeCamera.getPosition());
renderLightComponent(mainDirectionalLight, sunlightWorldPosition, program, camera, false);

DefaultRenderingProcess.getInstance().endRenderDirectionalLights();
Expand Down
5 changes: 3 additions & 2 deletions src/main/resources/assets/shaders/chunk_frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#define WATER_COLOR_SWIMMING 0.8, 1.0, 1.0, 0.975
#define WATER_TINT 0.1, 0.41, 0.627, 1.0
#define WATER_SPEC 2.0
#define WATER_SPEC 1.0

#ifdef FEATURE_REFRACTIVE_PASS
varying vec3 waterNormalViewSpace;
Expand Down Expand Up @@ -236,7 +236,8 @@ void main() {
// Apply reflection and refraction AFTER the lighting has been applied (otherwise bright areas below water become dark)
// The water tint has still to be adjusted adjusted though...
if (isWater && isOceanWater) {
color.xyz += calcSpecLight(normalWater, sunVecViewAdjusted, normalizedVPos, waterSpecExp) * WATER_SPEC;
float specularHighlight = WATER_SPEC * calcDayAndNightLightingFactor(daylightValue, daylight) * calcSpecLightNormalized(normalWater, sunVecViewAdjusted, normalizedVPos, waterSpecExp);
color.xyz += vec3(specularHighlight, specularHighlight, specularHighlight);

vec4 reflectionColor = vec4(texture2D(textureWaterReflection, projectedPos + normalWaterOffset.xy * waterRefraction).xyz, 1.0);
vec4 refractionColor = vec4(texture2D(texSceneOpaque, projectedPos + normalWaterOffset.xy * waterRefraction).xyz, 1.0);
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/assets/shaders/chunk_vert.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ void main()
}
#endif

#ifdef FEATURE_REFRACTIVE_PASS
# ifdef ANIMATED_WATER
#if defined (FEATURE_REFRACTIVE_PASS)
# if defined (ANIMATED_WATER)
if (checkFlag(BLOCK_HINT_WATER, blockHint)) {
// Only animate blocks on sea level
if (vertexWorldPos.y < 32.5 && vertexWorldPos.y > 31.5) {
Expand Down
19 changes: 14 additions & 5 deletions src/main/resources/assets/shaders/lightGeometryPass_frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

varying vec4 vertexProjPos;
varying vec3 eyeVec;

uniform vec3 lightViewPos;

Expand All @@ -42,7 +41,7 @@ uniform mat4 invProjMatrix;
uniform sampler2D texSceneClouds;
# endif

#define SHADOW_MAP_BIAS 0.003
#define SHADOW_MAP_BIAS 0.01

uniform sampler2D texSceneShadowMap;
uniform mat4 lightViewProjMatrix;
Expand Down Expand Up @@ -99,16 +98,26 @@ void main() {
// TODO: Costly - would be nice to use Crytek's view frustum ray method at this point
vec3 viewSpacePos = reconstructViewPos(depth, projectedPos, invProjMatrix);

vec3 lightDir = lightViewPos.xyz - viewSpacePos;
vec3 lightDir;
#if defined (FEATURE_LIGHT_POINT)
lightDir = lightViewPos.xyz - viewSpacePos;
#else if defined (FEATURE_LIGHT_DIRECTIONAL)
lightDir = lightViewPos.xyz;
#endif

vec3 eyeVec = -normalize(viewSpacePos.xyz).xyz;

float lightDist = length(lightDir);
vec3 lightDirNorm = lightDir / lightDist;

float ambTerm = lightAmbientIntensity;
float lambTerm = calcLambLight(normal, lightDirNorm);
float specTerm = calcSpecLight(normal, lightDirNorm, eyeVec, lightSpecularPower);
float specTerm = calcSpecLightNormalized(normal, lightDirNorm, eyeVec, lightSpecularPower);

#if defined (DYNAMIC_SHADOWS) && defined (FEATURE_LIGHT_DIRECTIONAL)
lambTerm *= shadowTerm;
specTerm *= shadowTerm;

ambTerm *= clamp(shadowTerm, 0.25, 1.0);
#endif

Expand All @@ -120,7 +129,7 @@ void main() {
#elif defined (FEATURE_LIGHT_DIRECTIONAL)
vec3 color = calcSunlightColorDeferred(normalBuffer.a, lambTerm, ambTerm, lightDiffuseIntensity, lightColorAmbient, lightColorDiffuse);
#else
vec3 color = vec3(0.0);
vec3 color = vec3(1.0, 0.0, 1.0);
#endif

#if defined (FEATURE_LIGHT_POINT)
Expand Down
3 changes: 0 additions & 3 deletions src/main/resources/assets/shaders/lightGeometryPass_vert.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

varying vec4 vertexProjPos;
varying vec3 eyeVec;

uniform mat4 modelMatrix;
uniform mat4 viewMatrix;
Expand All @@ -30,8 +29,6 @@ void main()
vertexProjPos = gl_Vertex;
#endif

eyeVec = -normalize(viewMatrix * gl_Vertex).xyz;

gl_Position = vertexProjPos;
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_FrontColor = gl_Color;
Expand Down
10 changes: 6 additions & 4 deletions src/main/resources/org/terasology/include/globalDefinesIncl.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@
#define DAYLIGHT_AMBIENT_COLOR 1.0, 0.9, 0.9
#define MOONLIGHT_AMBIENT_COLOR 0.5, 0.5, 1.0

#define NIGHT_BRIGHTNESS 0.1
#define NIGHT_BRIGHTNESS 0.125

#define WATER_AMB 1.0
#define WATER_DIFF 0.75
#define WATER_DIFF 2.0

#define BLOCK_AMB 1.0
#define BLOCK_DIFF 2.0

#define BLOCK_DIFF 0.75
#define BLOCK_AMB 2.0

#define EPSILON 0.000001
#define PI 3.14159265359

#define A 0.15
#define B 0.50
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ float calcSpecLight(vec3 normal, vec3 lightVec, vec3 eyeVec, float exp) {
return pow(clamp(dot(halfWay, normal), 0.0, 1.0), exp);
}

float calcSpecLightNormalized(vec3 normal, vec3 lightVec, vec3 eyeVec, float exp) {
const float PI_TIMES_8 = 8.0 * PI;

vec3 halfWay = normalize(eyeVec+lightVec);
return clamp(((exp + 8.0) / PI_TIMES_8) * pow(dot(halfWay, normal), exp), 0.0, 1.0);
}

vec4 linearToSrgb(vec4 color) {
return vec4(sqrt(color.rgb), color.a);
}
Expand Down Expand Up @@ -167,15 +174,19 @@ vec3 calcBlocklightColor(float blocklightValue
return vec3(blockBrightness) * vec3(1.0, 0.95, 0.94);
}

vec3 calcSunlightColorDeferred(float daylightValue, float diffuseLighting, float ambientIntensity, float diffuseIntensity, vec3 ambientColor, vec3 diffuseColor) {
float calcDayAndNightLightingFactor(float daylightValue, float daylight) {
float daylightScaledValue = daylight * daylightValue;
return expLightValue(daylightScaledValue) + (NIGHT_BRIGHTNESS * (1.0 - daylight) * expLightValue(daylightValue));
}

vec3 calcSunlightColorDeferred(float daylightValue, float diffuseLighting, float ambientIntensity, float diffuseIntensity, vec3 ambientColor, vec3 diffuseColor) {
vec3 daylightColorValue = vec3(ambientIntensity) + diffuseLighting * diffuseIntensity * diffuseColor;

vec3 ambientTint = mix(vec3(MOONLIGHT_AMBIENT_COLOR), vec3(DAYLIGHT_AMBIENT_COLOR), daylight) * ambientColor;
daylightColorValue.xyz *= ambientTint;

// Scale the lighting according to the daylight and daylight block values and add moonlight during the nights
daylightColorValue.xyz *= expLightValue(daylightScaledValue) + (NIGHT_BRIGHTNESS * (1.0 - daylight) * expLightValue(daylightValue));
daylightColorValue.xyz *= calcDayAndNightLightingFactor(daylightValue, daylight);

return daylightColorValue;
}
Expand Down

0 comments on commit 4ad8748

Please sign in to comment.