Update included lumilights, fix values being reset on restart

This commit is contained in:
JFronny 2020-12-20 14:24:48 +01:00
parent 59f4530b4c
commit 3c3928eeb8
34 changed files with 925 additions and 402 deletions

View File

@ -1,8 +1,3 @@
# Lumi Lights # Lumi Lights
[Lumi Lights](https://github.com/spiralhalo/LumiLights) by [spiralhalo](https://github.com/spiralhalo/LumiLights) is a shader for canvas.\ [Lumi Lights](https://github.com/spiralhalo/LumiLights) by [spiralhalo](https://github.com/spiralhalo/LumiLights) is a shader for canvas.\
I used it here as the fact it provides sevaral versions with only slight changes makes it an easy example for this library.\ This modified version uses respackopts for configuration instead of forcing the user to edit glsl
Modified/added files:
- [minecraft/lang/en_us.json](https://gitlab.com/JFronny/respackopts/-/blob/master/run/resourcepacks/lumi/assets/minecraft/lang/en_us.json)
- [respackopts/conf.json](https://gitlab.com/JFronny/respackopts/-/blob/master/run/resourcepacks/lumi/assets/respackopts/conf.json)
- [lumi/shaders/material/water.frag](https://gitlab.com/JFronny/respackopts/-/blob/master/run/resourcepacks/lumi/assets/lumi/shaders/material/water.frag)
- [canvas/shaders/internal/material_main.frag](https://gitlab.com/JFronny/respackopts/-/blob/master/run/resourcepacks/lumi/assets/canvas/shaders/internal/material_main.frag)

View File

@ -1,283 +1,57 @@
/* /*******************************************************
* Lumi Lights - A shader pack for Canvas * Lumi Lights - Shader pack for Canvas *
* Copyright (c) 2020 spiralhalo and Contributors *******************************************************
* * Copyright (c) 2020 spiralhalo and Contributors. *
* See `README.md` for license notice. * Released WITHOUT WARRANTY under the terms of the *
*/ * GNU Lesser General Public License version 3 as *
* published by the Free Software Foundation, Inc. *
*******************************************************/
#include canvas:shaders/internal/header.glsl #include canvas:shaders/internal/header.glsl
#include canvas:shaders/internal/varying.glsl #include canvas:shaders/internal/varying.glsl
#include canvas:shaders/internal/diffuse.glsl #include canvas:shaders/internal/diffuse.glsl
#include canvas:shaders/internal/flags.glsl #include canvas:shaders/internal/flags.glsl
#include canvas:shaders/internal/fog.glsl #include canvas:shaders/internal/fog.glsl
#include canvas:shaders/internal/program.glsl
#include frex:shaders/api/world.glsl #include frex:shaders/api/world.glsl
#include frex:shaders/api/camera.glsl
#include frex:shaders/api/player.glsl #include frex:shaders/api/player.glsl
#include frex:shaders/api/material.glsl #include frex:shaders/api/material.glsl
#include frex:shaders/api/fragment.glsl #include frex:shaders/api/fragment.glsl
#include frex:shaders/api/sampler.glsl #include frex:shaders/api/sampler.glsl
#include frex:shaders/lib/math.glsl #include frex:shaders/lib/math.glsl
#include frex:shaders/lib/color.glsl #include frex:shaders/lib/color.glsl
#include canvas:shaders/internal/program.glsl #include respackopts:config_supplier
#include lumi:shaders/api/varying.glsl #include lumi:shaders/api/pbr_frag.glsl
#include lumi:shaders/api/context_bump.glsl
#include lumi:shaders/lib/pbr.glsl
#include lumi:shaders/internal/varying.glsl
#include lumi:shaders/internal/main_frag.glsl
#include lumi:shaders/internal/lightsource.glsl
#include lumi:shaders/internal/tonemap.glsl
#include lumi:shaders/internal/pbr_shading.glsl
#include lumi:shaders/internal/phong_shading.glsl
#include lumi:shaders/internal/skybloom.glsl
#include lumi:shaders/internal/debug_shading.glsl
#include canvas:apitarget #include canvas:apitarget
#include respackopts:config_supplier
/****************************************************** /******************************************************
canvas:shaders/internal/material_main.frag canvas:shaders/internal/material_main.frag
******************************************************/ ******************************************************/
#define M_PI 3.1415926535897932384626433832795
const float hdr_sunStr = 3;
const float hdr_moonStr = 0.4;
const float hdr_blockStr = 1.5;
const float hdr_handHeldStr = 0.9;
const float hdr_skylessStr = 0.2;
const float hdr_baseMinStr = 0.0;
const float hdr_baseMaxStr = 0.25;
const float hdr_emissiveStr = 1;
const float hdr_relAmbient = 0.09;
const float hdr_relSunHorizon = 0.5;
const float hdr_zWobbleDefault = 0.1;
const float hdr_finalMult = 1;
const float hdr_gamma = 2.2;
float hdr_gammaAdjust(float x){
return pow(x, hdr_gamma);
}
vec3 hdr_gammaAdjust(vec3 x){
return pow(x, vec3(hdr_gamma));
}
vec3 hdr_reinhardJodieTonemap(in vec3 v) {
float l = frx_luminance(v);
vec3 tv = v / (1.0f + v);
return mix(v / (1.0f + l), tv, tv);
}
vec3 hdr_vibrantTonemap(in vec3 v){
return v / (frx_luminance(v) + vec3(1.0));
}
void _cv_startFragment(inout frx_FragmentData data) { void _cv_startFragment(inout frx_FragmentData data) {
int cv_programId = _cv_fragmentProgramId(); int cv_programId = _cv_fragmentProgramId();
#include canvas:startfragment #include canvas:startfragment
} }
float l2_clampScale(float e0, float e1, float v){ void main() {
return clamp((v-e0)/(e1-e0), 0.0, 1.0); #ifndef PROGRAM_BY_UNIFORM
} if (_cv_programDiscard()) {
discard;
float l2_max3(vec3 vec){
return max(vec.x, max(vec.y, vec.z));
}
// vec3 l2_what(vec3 rgb){
// return vec3(0.4123910 * rgb.r + 0.3575840 * rgb.g + 0.1804810 * rgb.b,
// 0.2126390 * rgb.r + 0.7151690 * rgb.g + 0.0721923 * rgb.b,
// 0.0193308 * rgb.r + 0.1191950 * rgb.g + 0.9505320 * rgb.b);
// }
vec3 l2_blockLight(float blockLight){
float bl = l2_clampScale(0.03125, 1.0, blockLight);
bl *= bl * hdr_blockStr;
vec3 block = hdr_gammaAdjust(vec3(bl, bl*0.875, bl*0.75));
#if HANDHELD_LIGHT_RADIUS != 0
vec4 held = frx_heldLight();
if (held.w > 0.0) {
float hl = l2_clampScale(held.w * HANDHELD_LIGHT_RADIUS, 0.0, gl_FogFragCoord);
hl *= hl * hdr_handHeldStr;
return block + hdr_gammaAdjust(held.rgb * hl);
} }
#endif #endif
return block;
}
vec3 l2_emissiveLight(float emissivity){
return vec3(hdr_gammaAdjust(emissivity) * hdr_emissiveStr);
}
float l2_skyLight(float skyLight, float intensity)
{
float sl = l2_clampScale(0.03125, 1.0, skyLight);
return hdr_gammaAdjust(sl) * intensity;
}
vec3 l2_ambientColor(float time){
vec3 ambientColor = hdr_gammaAdjust(vec3(0.6, 0.9, 1.0)) * hdr_sunStr * hdr_relAmbient;
vec3 sunriseAmbient = hdr_gammaAdjust(vec3(1.0, 0.8, 0.4)) * hdr_sunStr * hdr_relAmbient * hdr_relSunHorizon;
vec3 sunsetAmbient = hdr_gammaAdjust(vec3(1.0, 0.6, 0.2)) * hdr_sunStr * hdr_relAmbient * hdr_relSunHorizon;
vec3 nightAmbient = hdr_gammaAdjust(vec3(1.0, 1.0, 2.0)) * hdr_moonStr * hdr_relAmbient;
if(time > 0.94){
ambientColor = mix(nightAmbient, sunriseAmbient, l2_clampScale(0.94, 0.98, time));
} else if(time > 0.52){
ambientColor = mix(sunsetAmbient, nightAmbient, l2_clampScale(0.52, 0.56, time));
} else if(time > 0.48){
ambientColor = mix(ambientColor, sunsetAmbient, l2_clampScale(0.48, 0.5, time));
} else if(time < 0.02){
ambientColor = mix(ambientColor, sunriseAmbient, l2_clampScale(0.02, 0, time));
}
return ambientColor;
}
vec3 l2_skyAmbient(float skyLight, float time, float intensity){
float sa = l2_skyLight(skyLight, intensity) * 2.5;
return sa * l2_ambientColor(time);
}
float l2_userBrightness(){
float base = texture2D(frxs_lightmap, vec2(0.03125, 0.03125)).r;
// if(frx_isWorldTheNether()){
// return smoothstep(0.15/*0.207 no true darkness in nether*/, 0.577, base);
// } else if (frx_isWorldTheEnd(){
// return smoothstep(0.18/*0.271 no true darkness in the end*/, 0.685, base);
// } else {
// return smoothstep(0.053, 0.135, base);
// }
// Simplify nether/the end check
if(frx_worldHasSkylight()){
return smoothstep(0.053, 0.135, base);
} else {
return smoothstep(0.15, 0.63, base);
}
}
vec3 l2_skylessLightColor(){
return hdr_gammaAdjust(vec3(1.0));
}
vec3 l2_dimensionColor(){
if (frx_isWorldTheNether()) {
float min_col = min(min(gl_Fog.color.rgb.x, gl_Fog.color.rgb.y), gl_Fog.color.rgb.z);
float max_col = max(max(gl_Fog.color.rgb.x, gl_Fog.color.rgb.y), gl_Fog.color.rgb.z);
float sat = 0.0;
if (max_col != 0.0) {
sat = (max_col-min_col)/max_col;
}
return hdr_gammaAdjust(clamp((gl_Fog.color.rgb*(1/max_col))+pow(sat,2)/2, 0.0, 1.0));
}
else {
return hdr_gammaAdjust(vec3(0.8, 0.7, 1.0));
}
}
vec3 l2_skylessLight(vec3 normal){
if(frx_worldHasSkylight()){
return vec3(0);
} else {
float yalign = dot(normal,vec3(0, 0.977358, 0.211593)); // a bit towards z for more interesting effect
yalign = frx_isSkyDarkened()?abs(yalign):max(0,yalign);
return yalign * hdr_skylessStr * l2_skylessLightColor() * l2_userBrightness();
}
}
vec3 l2_baseAmbient(){
if(frx_worldHasSkylight()){
return vec3(0.1) * mix(hdr_baseMinStr, hdr_baseMaxStr, l2_userBrightness());
} else {
return l2_dimensionColor() * mix(hdr_baseMinStr, hdr_baseMaxStr, l2_userBrightness());
}
}
vec3 l2_sunColor(float time){
vec3 sunColor = hdr_gammaAdjust(vec3(1.0, 1.0, lumi_sunColorFactor)) * hdr_sunStr;
vec3 sunriseColor = hdr_gammaAdjust(vec3(1.0, 0.8, 0.4)) * hdr_sunStr * hdr_relSunHorizon;
vec3 sunsetColor = hdr_gammaAdjust(vec3(1.0, 0.6, 0.4)) * hdr_sunStr * hdr_relSunHorizon;
if(time > 0.94){
sunColor = sunriseColor;
} else if(time > 0.56){
sunColor = vec3(0); // pitch black at night
} else if(time > 0.54){
sunColor = mix(sunsetColor, vec3(0), l2_clampScale(0.54, 0.56, time));
} else if(time > 0.5){
sunColor = sunsetColor;
} else if(time > 0.48){
sunColor = mix(sunColor, sunsetColor, l2_clampScale(0.48, 0.5, time));
} else if(time < 0.02){
sunColor = mix(sunColor, sunriseColor, l2_clampScale(0.02, 0, time));
}
return sunColor;
}
vec3 l2_vanillaSunDir(in float time, float zWobble){
// wrap time to account for sunrise
time -= (time >= 0.75) ? 1.0 : 0.0;
// supposed offset of sunset/sunrise from 0/12000 daytime. might get better result with datamining?
float sunHorizonDur = 0.04;
// angle of sun in radians
float angleRad = l2_clampScale(-sunHorizonDur, 0.5+sunHorizonDur, time) * M_PI;
return normalize(vec3(cos(angleRad), sin(angleRad), zWobble));
}
vec3 l2_sunLight(float skyLight, in float time, float intensity, float rainGradient, vec3 diffuseNormal){
// wrap time to account for sunrise
float customTime = (time >= 0.75) ? (time - 1.0) : time;
float customIntensity = l2_clampScale(-0.08, 0.00, customTime);
if(customTime >= 0.25){
customIntensity = l2_clampScale(0.58, 0.5, customTime);
}
customIntensity *= mix(1.0, 0.0, rainGradient);
float sl = l2_skyLight(skyLight, max(customIntensity, intensity));
// direct sun light doesn't reach into dark spot as much as sky ambient
sl = frx_smootherstep(0.5,1.0,sl);
// zWobble is added to make more interesting looking diffuse light
// TODO: might be fun to use frx_worldDay() with sine wave for the zWobble to simulate annual sun position change
sl *= max(0.0, dot(l2_vanillaSunDir(time, hdr_zWobbleDefault), diffuseNormal));
return sl * l2_sunColor(time);
}
vec3 l2_moonLight(float skyLight, float time, float intensity, vec3 diffuseNormal){
float ml = l2_skyLight(skyLight, intensity) * frx_moonSize() * hdr_moonStr;
float aRad = l2_clampScale(0.56, 0.94, time) * M_PI;
ml *= max(0.0, dot(vec3(cos(aRad), sin(aRad), 0), diffuseNormal));
if(time < 0.58){
ml *= l2_clampScale(0.54, 0.58, time);
} else if(time > 0.92){
ml *= l2_clampScale(0.96, 0.92, time);
}
return vec3(ml);
}
float l2_specular(float time, vec3 aNormal, vec3 aPos, vec3 cameraPos, float power)
{
// calculate sun position (0 zWobble to make it look accurate with vanilla sun visuals)
vec3 sunDir = l2_vanillaSunDir(time, 0);
// obtain the direction of the camera
vec3 viewDir = normalize(cameraPos - aPos);
// calculate the specular light
return pow(max(0.0, dot(reflect(-sunDir, aNormal), viewDir)),power);
}
float l2_ao(frx_FragmentData fragData) {
#if AO_SHADING_MODE != AO_MODE_NONE
float ao = fragData.ao ? _cvv_ao : 1.0;
return hdr_gammaAdjust(min(1.0, ao + fragData.emissivity));
#else
return 1.0;
#endif
}
void main() {
frx_FragmentData fragData = frx_FragmentData ( frx_FragmentData fragData = frx_FragmentData (
texture2D(frxs_spriteAltas, _cvv_texcoord, _cv_getFlag(_CV_FLAG_UNMIPPED) * -4.0), texture2D(frxs_spriteAltas, _cvv_texcoord, _cv_getFlag(_CV_FLAG_UNMIPPED) * -4.0),
_cvv_color, _cvv_color,
@ -288,10 +62,19 @@ void main() {
_cvv_lightcoord _cvv_lightcoord
); );
#ifdef lumi_pbr
pbr_roughness = 1.0;
pbr_metallic = 0.0;
pbr_f0 = vec3(-1.0);
#else
ww_specular = 0.0;
#endif
_cv_startFragment(fragData); _cv_startFragment(fragData);
vec4 a = fragData.spriteColor * fragData.vertexColor; vec4 a = clamp(fragData.spriteColor * fragData.vertexColor, 0.0, 1.0);
float bloom = fragData.emissivity; // separate bloom from emissivity float bloom = fragData.emissivity; // separate bloom from emissivity
bool translucent = _cv_getFlag(_CV_FLAG_CUTOUT) == 0.0 && a.a < 0.99;
if(frx_isGui()){ if(frx_isGui()){
#if DIFFUSE_SHADING_MODE != DIFFUSE_MODE_NONE #if DIFFUSE_SHADING_MODE != DIFFUSE_MODE_NONE
@ -302,52 +85,27 @@ void main() {
} }
#endif #endif
} else { } else {
a.rgb = hdr_gammaAdjust(a.rgb); #if lumi_debugMode != lumi_debugMode_none
debug_shading(a);
// If diffuse is disabled (e.g. grass) then the normal points up by default
float ao = l2_ao(fragData);
vec3 diffuseNormal = fragData.diffuse?fragData.vertexNormal * frx_normalModelMatrix():vec3(0,1,0);
vec3 block = l2_blockLight(fragData.light.x);
vec3 sun = l2_sunLight(fragData.light.y, frx_worldTime(), frx_ambientIntensity(), frx_rainGradient(), diffuseNormal);
vec3 moon = l2_moonLight(fragData.light.y, frx_worldTime(), frx_ambientIntensity(), diffuseNormal);
vec3 skyAmbient = l2_skyAmbient(fragData.light.y, frx_worldTime(), frx_ambientIntensity());
vec3 emissive = l2_emissiveLight(fragData.emissivity);
vec3 nether = l2_skylessLight(diffuseNormal);
vec3 light = block + moon + l2_baseAmbient() + skyAmbient + sun + nether;
light *= ao; // AO is supposed to be applied to ambient only, but things look better with AO on everything except for emissive light
light += emissive;
vec3 specular = vec3(0.0);
if (wwv_specPower > 0.01) {
vec3 specularNormal = fragData.vertexNormal * frx_normalModelMatrix();
float skyAccess = smoothstep(0.89, 1.0, fragData.light.y);
vec3 fragPos = frx_var0.xyz;
vec3 cameraPos = frx_var1.xyz;
vec3 sunDir = l2_vanillaSunDir(frx_worldTime(), 0);
vec3 sun = l2_sunLight(fragData.light.y, frx_worldTime(), frx_ambientIntensity(), frx_rainGradient(), sunDir);
float specularAmount = l2_specular(frx_worldTime(), specularNormal, fragPos, cameraPos, wwv_specPower);
specular = sun * specularAmount * skyAccess;
}
a.rgb *= light;
a.rgb += specular;
float specularLuminance = frx_luminance(specular);
a.a += specularLuminance;
bloom += specularLuminance;
a.rgb *= hdr_finalMult;
#if lumi_tonemap == lumi_tonemap_vibrant
a.rgb = pow(hdr_vibrantTonemap(a.rgb), vec3(1.0 / hdr_gamma));
#elif lumi_tonemap == reinhardJodie
a.rgb = pow(hdr_reinhardJodieTonemap(a.rgb), vec3(1.0 / hdr_gamma));
#else #else
a.rgb = pow(frx_toneMap(a.rgb), vec3(1.0 / hdr_gamma)); float userBrightness;
float brightnessBase = texture2D(frxs_lightmap, vec2(0.03125, 0.03125)).r;
if(frx_worldHasSkylight()){
userBrightness = smoothstep(0.053, 0.135, brightnessBase);
} else {
// simplified for both nether and the end
userBrightness = smoothstep(0.15, 0.63, brightnessBase);
// if(frx_isWorldTheNether()){
// userBrightness = smoothstep(0.15/*0.207 no true darkness in nether*/, 0.577, brightnessBase);
// } else if (frx_isWorldTheEnd(){
// userBrightness = smoothstep(0.18/*0.271 no true darkness in the end*/, 0.685, brightnessBase);
// }
}
#ifdef lumi_pbr
pbr_shading(fragData, a, bloom, userBrightness, translucent);
#else
phong_shading(fragData, a, bloom, userBrightness, translucent);
#endif
#endif #endif
} }
@ -372,6 +130,7 @@ void main() {
gl_FragDepth = gl_FragCoord.z; gl_FragDepth = gl_FragCoord.z;
#if TARGET_EMISSIVE > 0 #if TARGET_EMISSIVE > 0
gl_FragData[TARGET_EMISSIVE] = vec4(bloom * a.a, 1.0, 0.0, 1.0); translucent = translucent && a.a < 0.99;
gl_FragData[TARGET_EMISSIVE] = vec4(bloom * a.a, 1.0, 0.0, translucent ? step(hdr_skyBloom, bloom) : 1.0);
#endif #endif
} }

View File

@ -1,13 +1,22 @@
/******************************************************************************************************
* Derived from Canvas (https://github.com/grondag/canvas) material_main shader, Apache 2.0 license. *
* Modified to add PBR varyings and support for texture-based bump map generation. *
* The modifications are licensed under the GNU Lesser General Public License version 3. *
******************************************************************************************************/
#include canvas:shaders/internal/header.glsl #include canvas:shaders/internal/header.glsl
#include frex:shaders/api/context.glsl
#include canvas:shaders/internal/varying.glsl #include canvas:shaders/internal/varying.glsl
#include canvas:shaders/internal/vertex.glsl #include canvas:shaders/internal/vertex.glsl
#include canvas:shaders/internal/flags.glsl #include canvas:shaders/internal/flags.glsl
#include frex:shaders/api/vertex.glsl
#include frex:shaders/api/sampler.glsl
#include canvas:shaders/internal/diffuse.glsl #include canvas:shaders/internal/diffuse.glsl
#include canvas:shaders/internal/program.glsl #include canvas:shaders/internal/program.glsl
#include lumi:shaders/api/varying.glsl #include frex:shaders/api/context.glsl
#include frex:shaders/api/vertex.glsl
#include frex:shaders/api/sampler.glsl
#include respackopts:config_supplier
#include lumi:shaders/api/context_bump.glsl
#include lumi:shaders/internal/varying.glsl
#include lumi:shaders/internal/main_vert.glsl
#include canvas:apitarget #include canvas:apitarget
@ -36,13 +45,22 @@ void main() {
// due to FP error on some cards/drivers. Also made varying attribute invariant (rolls eyes at OpenGL) // due to FP error on some cards/drivers. Also made varying attribute invariant (rolls eyes at OpenGL)
_cvv_flags = uint(in_normal_flags.w + 0.5); _cvv_flags = uint(in_normal_flags.w + 0.5);
wwv_specPower = 0.0; // pbrv_roughness = 1.0;
// pbrv_metallic = 0.0;
_cv_setupProgram(); _cv_setupProgram();
#ifdef LUMI_BUMP
startBump();
#endif
int cv_programId = _cv_vertexProgramId(); int cv_programId = _cv_vertexProgramId();
_cv_startVertex(data, cv_programId); _cv_startVertex(data, cv_programId);
#ifdef LUMI_BUMP
setupBump(data);
#endif
if (_cvu_atlas[_CV_SPRITE_INFO_TEXTURE_SIZE] != 0.0) { if (_cvu_atlas[_CV_SPRITE_INFO_TEXTURE_SIZE] != 0.0) {
float spriteIndex = in_material.x; float spriteIndex = in_material.x;
// for sprite atlas textures, convert from normalized (0-1) to interpolated coordinates // for sprite atlas textures, convert from normalized (0-1) to interpolated coordinates
@ -58,6 +76,10 @@ void main() {
spriteBounds /= vec4(atlasWidth, atlasHeight, atlasWidth, atlasHeight); spriteBounds /= vec4(atlasWidth, atlasHeight, atlasWidth, atlasHeight);
data.spriteUV = spriteBounds.xy + data.spriteUV * spriteBounds.zw; data.spriteUV = spriteBounds.xy + data.spriteUV * spriteBounds.zw;
#ifdef LUMI_BUMP
endBump(spriteBounds);
#endif
} }
data.spriteUV = _cv_textureCoord(data.spriteUV, 0); data.spriteUV = _cv_textureCoord(data.spriteUV, 0);
@ -66,6 +88,8 @@ void main() {
gl_ClipVertex = viewCoord; gl_ClipVertex = viewCoord;
gl_FogFragCoord = length(viewCoord.xyz); gl_FogFragCoord = length(viewCoord.xyz);
setVaryings(viewCoord);
//data.normal *= gl_NormalMatrix; //data.normal *= gl_NormalMatrix;
data.vertex = gl_ModelViewProjectionMatrix * data.vertex; data.vertex = gl_ModelViewProjectionMatrix * data.vertex;

View File

@ -8,6 +8,7 @@
#include frex:shaders/lib/color.glsl #include frex:shaders/lib/color.glsl
#include frex:shaders/lib/sample.glsl #include frex:shaders/lib/sample.glsl
#include frex:shaders/lib/math.glsl #include frex:shaders/lib/math.glsl
#include lumi:shaders/internal/skybloom.glsl
/****************************************************** /******************************************************
canvas:shaders/internal/process/emissive_color.frag canvas:shaders/internal/process/emissive_color.frag
@ -22,7 +23,7 @@ void main() {
vec4 e = texture2D(_cvu_emissive, _cvv_texcoord); vec4 e = texture2D(_cvu_emissive, _cvv_texcoord);
bool sky = e.g == 0.0; bool sky = e.g == 0.0;
float bloom = sky ? 0.25 : e.r; float bloom = sky ? hdr_skyBloom : e.r;
vec4 c = frx_fromGamma(texture2D(_cvu_base, _cvv_texcoord)); vec4 c = frx_fromGamma(texture2D(_cvu_base, _cvv_texcoord));

View File

@ -1,7 +1,6 @@
{ {
"blendMode": "translucent", "blendMode": "translucent",
"disableAo": true, "disableAo": true,
"disableDiffuse": true,
"vertexSource": "lumi:shaders/material/water.vert", "vertexSource": "lumi:shaders/material/water.vert",
"fragmentSource": "lumi:shaders/material/water.frag" "fragmentSource": "lumi:shaders/material/water.frag"
} }

View File

@ -0,0 +1,8 @@
#define LUMI_PBR_API 1
// API 0
float pbr_roughness;
float pbr_metallic;
// API 1
vec3 pbr_f0;

View File

@ -1,2 +0,0 @@
// If wwv_specPower is used, frx_var0 must be reserved for fragPos and frx_var1 must be reserved for cameraPos
varying float wwv_specPower;

View File

@ -0,0 +1,20 @@
/*******************************************************
* lumi:shaders/internal/debug_shading.glsl *
*******************************************************
* Copyright (c) 2020 spiralhalo and Contributors. *
* Released WITHOUT WARRANTY under the terms of the *
* GNU Lesser General Public License version 3 as *
* published by the Free Software Foundation, Inc. *
*******************************************************/
#if lumi_debugMode != lumi_debugMode_none
void debug_shading(inout vec4 a) {
#if lumi_debugMode == lumi_debugMode_viewDir
vec3 viewDir = normalize(-pbrv_viewPos) * frx_normalModelMatrix() * gl_NormalMatrix;
a.rgb = viewDir * 0.5 + 0.5;
#else
vec3 normal = fragData.vertexNormal * frx_normalModelMatrix();
a.rgb = normal * 0.5 + 0.5;
#endif
}
#endif

View File

@ -0,0 +1,226 @@
/*******************************************************
* lumi:shaders/internal/lightsource.glsl *
*******************************************************
* Copyright (c) 2020 spiralhalo and Contributors. *
* Released WITHOUT WARRANTY under the terms of the *
* GNU Lesser General Public License version 3 as *
* published by the Free Software Foundation, Inc. *
*******************************************************/
#ifdef lumi_pbr
const float hdr_sunStr = 5;
const float hdr_moonStr = 0.4;
const float hdr_blockMinStr = 2;
const float hdr_blockMaxStr = 3;
const float hdr_handHeldStr = 1.5;
const float hdr_skylessStr = 0.2;
const float hdr_baseMinStr = 0.01;
const float hdr_baseMaxStr = 0.8;
const float hdr_emissiveStr = 1;
const float hdr_relAmbient = 0.2;
#else
const float hdr_sunStr = 2;
const float hdr_moonStr = 0.4;
const float hdr_blockMinStr = 1.0;
const float hdr_blockMaxStr = 1.4;
const float hdr_handHeldStr = 0.9;
const float hdr_skylessStr = 0.2;
const float hdr_baseMinStr = 0.0;
const float hdr_baseMaxStr = 0.25;
const float hdr_emissiveStr = 1;
const float hdr_relAmbient = 0.09;
#endif
const float hdr_zWobbleDefault = 0.1;
const vec3 blockColor = vec3(1.0, 0.875, 0.75);
#if lumi_tonemap == lumi_tonemap_vibrant
const vec3 sunColor = vec3(1.0, 1.0, 1.0);
#else
const vec3 sunColor = vec3(1.0, 1.0, 0.8);
#endif
/* BLOCK LIGHT
*******************************************************/
vec3 l2_blockRadiance(float blockLight, float userBrightness) {
float bl = l2_clampScale(0.03125, 1.0, blockLight);
bl *= bl * mix(hdr_blockMinStr, hdr_blockMaxStr, userBrightness);
return hdr_gammaAdjust(bl * blockColor);
}
/* HELD LIGHT
*******************************************************/
#if HANDHELD_LIGHT_RADIUS != 0
vec3 l2_handHeldRadiance() {
vec4 held = frx_heldLight();
float hl = l2_clampScale(held.w * HANDHELD_LIGHT_RADIUS, 0.0, gl_FogFragCoord);
hl *= hl * hdr_handHeldStr;
return hdr_gammaAdjust(held.rgb * hl);
}
#endif
/* EMISSIVE LIGHT
*******************************************************/
vec3 l2_emissiveRadiance(float emissivity) {
return vec3(hdr_gammaAdjust(emissivity) * hdr_emissiveStr);
}
/* SKY AMBIENT LIGHT
*******************************************************/
float l2_skyLight(float skyLight, float intensity) {
float sl = l2_clampScale(0.03125, 1.0, skyLight);
return hdr_gammaAdjust(sl) * intensity;
}
vec3 l2_ambientColor(float time) {
vec3 ambientColor = hdr_gammaAdjust(vec3(0.6, 0.9, 1.0)) * hdr_sunStr * hdr_relAmbient;
vec3 sunriseAmbient = hdr_gammaAdjust(vec3(1.0, 0.8, 0.4)) * hdr_sunStr * hdr_relAmbient;
vec3 sunsetAmbient = hdr_gammaAdjust(vec3(1.0, 0.6, 0.2)) * hdr_sunStr * hdr_relAmbient;
vec3 nightAmbient = hdr_gammaAdjust(vec3(1.0, 1.0, 2.0)) * hdr_moonStr * hdr_relAmbient;
if(time > 0.94){
ambientColor = mix(nightAmbient, sunriseAmbient, l2_clampScale(0.94, 0.98, time));
} else if(time > 0.52){
ambientColor = mix(sunsetAmbient, nightAmbient, l2_clampScale(0.52, 0.56, time));
} else if(time > 0.48){
ambientColor = mix(ambientColor, sunsetAmbient, l2_clampScale(0.48, 0.5, time));
} else if(time < 0.02){
ambientColor = mix(ambientColor, sunriseAmbient, l2_clampScale(0.02, 0, time));
}
return ambientColor;
}
vec3 l2_skyAmbient(float skyLight, float time, float intensity) {
float sa = l2_skyLight(skyLight, intensity) * 2.5;
return sa * l2_ambientColor(time);
}
/* SKYLESS LIGHT
*******************************************************/
vec3 l2_skylessLightColor() {
return hdr_gammaAdjust(vec3(1.0));
}
vec3 l2_dimensionColor() {
if (frx_isWorldTheNether()) {
float min_col = min(min(gl_Fog.color.rgb.x, gl_Fog.color.rgb.y), gl_Fog.color.rgb.z);
float max_col = max(max(gl_Fog.color.rgb.x, gl_Fog.color.rgb.y), gl_Fog.color.rgb.z);
float sat = 0.0;
if (max_col != 0.0) {
sat = (max_col-min_col)/max_col;
}
return hdr_gammaAdjust(clamp((gl_Fog.color.rgb*(1/max_col))+pow(sat,2)/2, 0.0, 1.0));
}
else {
return hdr_gammaAdjust(vec3(0.8, 0.7, 1.0));
}
}
vec3 l2_skylessDarkenedDir() {
return vec3(0, -0.977358, 0.211593);
}
vec3 l2_skylessDir() {
return vec3(0, 0.977358, 0.211593);
}
vec3 l2_skylessRadiance(float userBrightness) {
if (frx_worldHasSkylight()) {
return vec3(0);
} else {
return ( frx_isSkyDarkened() ? 0.5 : 1.0 )
* hdr_skylessStr
* l2_skylessLightColor()
* userBrightness;
}
}
/* BASE AMBIENT LIGHT
*******************************************************/
vec3 l2_baseAmbient(float userBrightness){
if(frx_worldHasSkylight()){
return vec3(0.1) * mix(hdr_baseMinStr, hdr_baseMaxStr, userBrightness);
} else {
return l2_dimensionColor() * mix(hdr_baseMinStr, hdr_baseMaxStr, userBrightness);
}
}
/* SUN LIGHT
*******************************************************/
vec3 l2_sunColor(float time){
vec3 sunColor = hdr_gammaAdjust(sunColor) * hdr_sunStr;
vec3 sunriseColor = hdr_gammaAdjust(vec3(1.0, 0.8, 0.4)) * hdr_sunStr;
vec3 sunsetColor = hdr_gammaAdjust(vec3(1.0, 0.6, 0.4)) * hdr_sunStr;
if(time > 0.94){
sunColor = sunriseColor;
} else if(time > 0.56){
sunColor = vec3(0); // pitch black at night
} else if(time > 0.54){
sunColor = mix(sunsetColor, vec3(0), l2_clampScale(0.54, 0.56, time));
} else if(time > 0.5){
sunColor = sunsetColor;
} else if(time > 0.48){
sunColor = mix(sunColor, sunsetColor, l2_clampScale(0.48, 0.5, time));
} else if(time < 0.02){
sunColor = mix(sunColor, sunriseColor, l2_clampScale(0.02, 0, time));
}
return sunColor;
}
vec3 l2_vanillaSunDir(in float time, float zWobble){
// wrap time to account for sunrise
time -= (time >= 0.75) ? 1.0 : 0.0;
// supposed offset of sunset/sunrise from 0/12000 daytime. might get better result with datamining?
float sunHorizonDur = 0.04;
// angle of sun in radians
float angleRad = l2_clampScale(-sunHorizonDur, 0.5+sunHorizonDur, time) * PI;
return normalize(vec3(cos(angleRad), sin(angleRad), zWobble));
}
vec3 l2_sunRadiance(float skyLight, in float time, float intensity, float rainGradient){
// wrap time to account for sunrise
float customTime = (time >= 0.75) ? (time - 1.0) : time;
float customIntensity = l2_clampScale(-0.08, 0.00, customTime);
if(customTime >= 0.25){
customIntensity = l2_clampScale(0.58, 0.5, customTime);
}
customIntensity *= mix(1.0, 0.0, rainGradient);
float sl = l2_skyLight(skyLight, max(customIntensity, intensity));
// direct sun light doesn't reach into dark spot as much as sky ambient
sl = frx_smootherstep(0.5,1.0,sl);
return sl * l2_sunColor(time);
}
/* MOON LIGHT
*******************************************************/
vec3 l2_moonDir(float time){
float aRad = l2_clampScale(0.56, 0.94, time) * PI;
return normalize(vec3(cos(aRad), sin(aRad), 0));
}
vec3 l2_moonRadiance(float skyLight, float time, float intensity){
float ml = l2_skyLight(skyLight, intensity) * frx_moonSize() * hdr_moonStr;
if(time < 0.58){
ml *= l2_clampScale(0.54, 0.58, time);
} else if(time > 0.92){
ml *= l2_clampScale(0.96, 0.92, time);
}
return vec3(ml);
}

View File

@ -0,0 +1,36 @@
/*******************************************************
* lumi:shaders/internal/main_frag.glsl *
*******************************************************
* Copyright (c) 2020 spiralhalo and Contributors. *
* Released WITHOUT WARRANTY under the terms of the *
* GNU Lesser General Public License version 3 as *
* published by the Free Software Foundation, Inc. *
*******************************************************/
const float hdr_finalMult = 1;
const float hdr_gamma = 2.2;
float hdr_gammaAdjust(float x){
return pow(x, hdr_gamma);
}
vec3 hdr_gammaAdjust(vec3 x){
return pow(x, vec3(hdr_gamma));
}
float l2_clampScale(float e0, float e1, float v){
return clamp((v-e0)/(e1-e0), 0.0, 1.0);
}
float l2_max3(vec3 vec){
return max(vec.x, max(vec.y, vec.z));
}
float l2_ao(frx_FragmentData fragData) {
#if AO_SHADING_MODE != AO_MODE_NONE
float ao = fragData.ao ? _cvv_ao : 1.0;
return hdr_gammaAdjust(min(1.0, ao + fragData.emissivity));
#else
return 1.0;
#endif
}

View File

@ -0,0 +1,37 @@
/*******************************************************
* lumi:shaders/internal/main_vert.glsl *
*******************************************************
* Copyright (c) 2020 spiralhalo and Contributors. *
* Released WITHOUT WARRANTY under the terms of the *
* GNU Lesser General Public License version 3 as *
* published by the Free Software Foundation, Inc. *
*******************************************************/
#ifdef LUMI_BUMP
float bump_resolution;
vec2 uvN;
vec2 uvT;
vec2 uvB;
void startBump() {
bump_resolution = 1.0;
}
void setupBump(frx_VertexData data) {
float bumpSample = 0.015625 * bump_resolution;
uvN = clamp(data.spriteUV + vec2(-bumpSample, bumpSample), 0.0, 1.0);
uvT = clamp(data.spriteUV + vec2(bumpSample, 0), 0.0, 1.0);
uvB = clamp(data.spriteUV - vec2(0, bumpSample), 0.0, 1.0);
}
void endBump(vec4 spriteBounds) {
uvN = spriteBounds.xy + uvN * spriteBounds.zw;
uvT = spriteBounds.xy + uvT * spriteBounds.zw;
uvB = spriteBounds.xy + uvB * spriteBounds.zw;
}
#endif
void setVaryings(vec4 viewCoord) {
l2_viewPos = viewCoord.xyz;
}

View File

@ -0,0 +1,138 @@
/*******************************************************
* lumi:shaders/internal/pbr_shading.glsl *
*******************************************************
* Copyright (c) 2020 spiralhalo and Contributors. *
* Released WITHOUT WARRANTY under the terms of the *
* GNU Lesser General Public License version 3 as *
* published by the Free Software Foundation, Inc. *
*******************************************************/
const float pbr_specularBloomStr = 0.01;
const float pbr_specularAlphaStr = 0.1;
vec3 pbr_specularBRDF(float roughness, vec3 radiance, vec3 halfway, vec3 lightDir, vec3 viewDir, vec3 normal, vec3 fresnel, float NdotL) {
// cook-torrance brdf
float distribution = pbr_distributionGGX(normal, halfway, roughness);
float geometry = pbr_geometrySmith(normal, viewDir, lightDir, roughness);
vec3 num = distribution * geometry * fresnel;
float denom = 4.0 * pbr_dot(normal, viewDir) * NdotL;
vec3 specular = num / max(denom, 0.001);
return specular * radiance * NdotL;
}
vec3 pbr_lightCalc(vec3 albedo, vec3 radiance, vec3 lightDir, vec3 viewDir, vec3 normal, bool diffuseOn, bool isAmbiance, float haloBlur, inout vec3 specularAccu) {
vec3 halfway = normalize(viewDir + lightDir);
float roughness = pbr_roughness;
// ambiance hack
if (isAmbiance) {
roughness = min(1.0, roughness + 0.5 * (1 - pbr_metallic));
}
// disableDiffuse hack
if (!diffuseOn) {
return albedo / PI * radiance * pbr_dot(lightDir, vec3(.0, 1.0, .0));
}
vec3 specularRadiance;
vec3 fresnel = pbr_fresnelSchlick(pbr_dot(viewDir, halfway), pbr_f0);
float NdotL = pbr_dot(normal, lightDir);
if (haloBlur > roughness) {
// sun halo hack
specularRadiance = pbr_specularBRDF(roughness, radiance * 0.75, halfway, lightDir, viewDir, normal, fresnel, NdotL);
specularRadiance += pbr_specularBRDF(haloBlur, radiance * 0.25, halfway, lightDir, viewDir, normal, fresnel, NdotL);
} else {
specularRadiance = pbr_specularBRDF(roughness, radiance, halfway, lightDir, viewDir, normal, fresnel, NdotL);
}
vec3 diffuse = (1.0 - fresnel) * (1.0 - pbr_metallic);
vec3 diffuseRadiance = albedo * diffuse / PI * radiance * NdotL;
specularAccu += specularRadiance;
return specularRadiance + diffuseRadiance;
}
void pbr_shading(in frx_FragmentData fragData, inout vec4 a, inout float bloom, in float userBrightness, in bool translucent) {
vec3 albedo = hdr_gammaAdjust(a.rgb);
vec3 dielectricF0 = vec3(0.1) * frx_luminance(albedo);
pbr_roughness = clamp(pbr_roughness, 0.0, 1.0);
pbr_metallic = clamp(pbr_metallic, 0.0, 1.0);
pbr_f0 = pbr_f0.r < 0 ? mix(dielectricF0, albedo, pbr_metallic) : clamp(pbr_f0, 0.0, 1.0);
a.rgb = albedo;
float ao = l2_ao(fragData);
vec3 emissive = l2_emissiveRadiance(fragData.emissivity);
a.rgb *= emissive;
vec3 viewDir = normalize(-l2_viewPos) * frx_normalModelMatrix() * gl_NormalMatrix;
vec3 normal = fragData.vertexNormal * frx_normalModelMatrix();
vec3 specularAccu = vec3(0.0);
#if HANDHELD_LIGHT_RADIUS != 0
if (frx_heldLight().w > 0) {
vec3 handHeldDir = viewDir;
vec3 handHeldRadiance = l2_handHeldRadiance();
if(handHeldRadiance.x * handHeldRadiance.y * handHeldRadiance.z > 0) {
vec3 adjustedNormal = fragData.diffuse ? normal : viewDir;
a.rgb += pbr_lightCalc(albedo, handHeldRadiance, handHeldDir, viewDir, adjustedNormal, true, false, 0.0, specularAccu);
}
}
#endif
vec3 blockRadiance = l2_blockRadiance(fragData.light.x, userBrightness);
vec3 baseAmbientRadiance = l2_baseAmbient(userBrightness);
vec3 ambientDir = normalize(vec3(0.1, 0.9, 0.1) + normal);
a.rgb += pbr_lightCalc(albedo, blockRadiance * ao, ambientDir, viewDir, normal, fragData.diffuse, true, 0.0, specularAccu);
a.rgb += pbr_lightCalc(albedo, baseAmbientRadiance * ao, ambientDir, viewDir, normal, fragData.diffuse, true, 0.0, specularAccu);
if (frx_worldHasSkylight()) {
if (fragData.light.y > 0.03125) {
vec3 moonRadiance = l2_moonRadiance(fragData.light.y, frx_worldTime(), frx_ambientIntensity());
vec3 moonDir = l2_moonDir(frx_worldTime());
vec3 sunRadiance = l2_sunRadiance(fragData.light.y, frx_worldTime(), frx_ambientIntensity(), frx_rainGradient());
vec3 sunDir = l2_vanillaSunDir(frx_worldTime(), 0.0);
vec3 skyRadiance = l2_skyAmbient(fragData.light.y, frx_worldTime(), frx_ambientIntensity());
a.rgb += pbr_lightCalc(albedo, moonRadiance * ao, moonDir, viewDir, normal, fragData.diffuse, false, 0.15, specularAccu);
a.rgb += pbr_lightCalc(albedo, sunRadiance * ao, sunDir, viewDir, normal, fragData.diffuse, false, 0.15, specularAccu);
a.rgb += pbr_lightCalc(albedo, skyRadiance * ao, ambientDir, viewDir, normal, fragData.diffuse, true, 0.0, specularAccu);
}
} else {
vec3 skylessRadiance = l2_skylessRadiance(userBrightness);
vec3 skylessDir = l2_skylessDir();
a.rgb += pbr_lightCalc(albedo, skylessRadiance * ao, skylessDir, viewDir, normal, fragData.diffuse, false, 0.0, specularAccu);
if (frx_isSkyDarkened()) {
vec3 skylessDarkenedDir = l2_skylessDarkenedDir();
a.rgb += pbr_lightCalc(albedo, skylessRadiance * ao, skylessDarkenedDir, viewDir, normal, fragData.diffuse, false, 0.0, specularAccu);
}
}
// float skyAccess = smoothstep(0.89, 1.0, fragData.light.y);
float specularLuminance = frx_luminance(specularAccu);
float smoothness = (1-pbr_roughness);
bloom += specularLuminance * pbr_specularBloomStr * smoothness * smoothness;
if (translucent) {
a.a += specularLuminance * pbr_specularBloomStr;
}
a.rgb *= hdr_finalMult;
tonemap(a);
}

View File

@ -0,0 +1,74 @@
/*******************************************************
* lumi:shaders/internal/phong_shading.glsl *
*******************************************************
* Copyright (c) 2020 spiralhalo and Contributors. *
* Released WITHOUT WARRANTY under the terms of the *
* GNU Lesser General Public License version 3 as *
* published by the Free Software Foundation, Inc. *
*******************************************************/
float ww_specular;
float l2_specular(float time, vec3 aNormal, vec3 viewDir, float power)
{
// calculate sun position (0 zWobble to make it look accurate with vanilla sun visuals)
vec3 sunDir = l2_vanillaSunDir(time, 0);
// calculate the specular light
return pow(max(0.0, dot(reflect(-sunDir, aNormal), viewDir)), power);
}
void phong_shading(in frx_FragmentData fragData, inout vec4 a, inout float bloom, in float userBrightness, in bool translucent) {
a.rgb = hdr_gammaAdjust(a.rgb);
float ao = l2_ao(fragData);
// If diffuse is disabled (e.g. grass) then the normal points up by default
vec3 diffuseNormal = fragData.diffuse?fragData.vertexNormal * frx_normalModelMatrix():vec3(0,1,0);
float sunDot = max(0.0, dot(l2_vanillaSunDir(frx_worldTime(), hdr_zWobbleDefault), diffuseNormal));
float moonDot = max(0.0, dot(l2_moonDir(frx_worldTime()), diffuseNormal));
float skyLessDot = max(0.0, dot(l2_skylessDir(), diffuseNormal));
float skyLessDarkenedDot = max(0.0, dot(l2_skylessDarkenedDir(), diffuseNormal));
#if HANDHELD_LIGHT_RADIUS == 0
vec3 held = vec3(0);
#else
vec3 held = l2_handHeldRadiance();
#endif
vec3 block = l2_blockRadiance(fragData.light.x, userBrightness);
vec3 sun = l2_sunRadiance(fragData.light.y, frx_worldTime(), frx_ambientIntensity(), frx_rainGradient()) * sunDot;
vec3 moon = l2_moonRadiance(fragData.light.y, frx_worldTime(), frx_ambientIntensity()) * moonDot;
vec3 skyAmbient = l2_skyAmbient(fragData.light.y, frx_worldTime(), frx_ambientIntensity());
vec3 emissive = l2_emissiveRadiance(fragData.emissivity);
vec3 skylessRadiance = l2_skylessRadiance(userBrightness);
vec3 skyless = skylessRadiance * skyLessDot + (frx_isSkyDarkened() ? skylessRadiance * skyLessDarkenedDot : vec3(0.0));
vec3 baseAmbient = l2_baseAmbient(userBrightness);
vec3 light = baseAmbient + held + block + moon + skyAmbient + sun + skyless;
light *= ao; // AO is supposed to be applied to ambient only, but things look better with AO on everything except for emissive light
light += emissive;
vec3 specular = vec3(0.0);
if (ww_specular > 0) {
vec3 specularNormal = fragData.vertexNormal * frx_normalModelMatrix();
float skyAccess = smoothstep(0.89, 1.0, fragData.light.y);
vec3 sunDir = l2_vanillaSunDir(frx_worldTime(), 0);
float specSunDot = max(0.0, dot(l2_vanillaSunDir(frx_worldTime(), hdr_zWobbleDefault), specularNormal));
vec3 viewDir = normalize(-l2_viewPos) * frx_normalModelMatrix() * gl_NormalMatrix;
vec3 sun = l2_sunRadiance(fragData.light.y, frx_worldTime(), frx_ambientIntensity(), frx_rainGradient()) * specSunDot;
float specularAmount = l2_specular(frx_worldTime(), specularNormal, viewDir, ww_specular);
specular = sun * specularAmount * skyAccess;
float specularLuminance = frx_luminance(specular);
a.a += specularLuminance;
bloom += specularLuminance;
}
a.rgb *= light;
a.rgb += specular;
a.rgb *= hdr_finalMult;
tonemap(a);
}

View File

@ -0,0 +1,5 @@
/***********************************************************
* lumi:shaders/internal/skybloom.glsl *
***********************************************************/
const float hdr_skyBloom = 0.25;

View File

@ -0,0 +1,25 @@
/***********************************************************
* lumi:shaders/internal/tonemap.glsl *
***********************************************************/
vec3 hdr_reinhardJodieTonemap(in vec3 v) {
float l = frx_luminance(v);
vec3 tv = v / (1.0f + v);
return mix(v / (1.0f + l), tv, tv);
}
#if lumi_tonemap == lumi_tonemap_vibrant
vec3 hdr_vibrantTonemap(in vec3 hdrColor){
return hdrColor / (frx_luminance(hdrColor) + vec3(1.0));
}
#endif
void tonemap(inout vec4 a) {
#if lumi_tonemap == lumi_tonemap_film
a.rgb = frx_toGamma(frx_toneMap(a.rgb));
#elif lumi_tonemap == lumi_tonemap_vibrant
a.rgb = pow(hdr_vibrantTonemap(a.rgb), vec3(1.0 / hdr_gamma));
#else
a.rgb = pow(hdr_reinhardJodieTonemap(a.rgb), vec3(1.0 / hdr_gamma));
#endif
}

View File

@ -0,0 +1,5 @@
/***********************************************************
* lumi:shaders/internal/varying.glsl *
***********************************************************/
varying vec3 l2_viewPos;

View File

@ -0,0 +1,48 @@
/*******************************************************
* lumi:shaders/lib/bump.glsl *
*******************************************************
* Copyright (c) 2020 spiralhalo and Contributors. *
* Released WITHOUT WARRANTY under the terms of the *
* GNU Lesser General Public License version 3 as *
* published by the Free Software Foundation, Inc. *
*******************************************************/
const mat4 _bump_tRotm = mat4(
0, 0, -1, 0,
0, 1, 0, 0,
1, 0, 0, 0,
0, 0, 0, 1 );
vec3 _bump_tangentMove(vec3 normal)
{
vec3 aaNormal = vec3(normal.x + 0.01, 0, normal.z + 0.01);
aaNormal = normalize(aaNormal);
return (_bump_tRotm * vec4(aaNormal, 0.0)).xyz;
}
vec3 _bump_bitangentMove(vec3 normal, vec3 tangent)
{
return cross(normal, tangent);
}
float _bump_height(float raw)
{
return frx_smootherstep(0, 1, pow(raw, 1 + raw * raw));
}
vec3 bump_normal(sampler2D tex, vec3 normal, vec2 uvn, vec2 uvt, vec2 uvb)
{
vec3 tangentMove = _bump_tangentMove(normal);
vec3 bitangentMove = _bump_bitangentMove(normal, tangentMove);
vec4 texel = texture2D(tex, uvn, _cv_getFlag(_CV_FLAG_UNMIPPED) * -4.0);
vec3 origin = _bump_height(frx_luminance(texel.rgb)) * normal;
texel = texture2D(tex, uvt, _cv_getFlag(_CV_FLAG_UNMIPPED) * -4.0);
vec3 tangent = tangentMove + _bump_height(frx_luminance(texel.rgb)) * normal - origin;
texel = texture2D(tex, uvb, _cv_getFlag(_CV_FLAG_UNMIPPED) * -4.0);
vec3 bitangent = bitangentMove + _bump_height(frx_luminance(texel.rgb)) * normal - origin;
return normalize(cross(tangent, bitangent));
}

View File

@ -1,7 +0,0 @@
#include frex:shaders/lib/noise/noise3d.glsl
float l2_noise(vec3 aPos, float renderTime, float scale, float amplitude)
{
float invScale = 1/scale;
return (snoise(vec3(aPos.x*invScale, aPos.z*invScale, renderTime)) * 0.5+0.5) * amplitude;
}

View File

@ -0,0 +1,48 @@
/*******************************************************
* lumi:shaders/lib/pbr.glsl *
*******************************************************/
float pbr_dot(vec3 a, vec3 b)
{
return clamp(dot(a, b), 0.0, 1.0);
}
float pbr_distributionGGX(vec3 N, vec3 H, float roughness)
{
float a = roughness*roughness;
float a2 = a*a;
float NdotH = pbr_dot(N, H);
float NdotH2 = NdotH*NdotH;
float num = a2;
float denom = (NdotH2 * (a2 - 1.0) + 1.0);
denom = PI * denom * denom;
return num / denom;
}
float pbr_geometrySchlickGGX(float NdotV, float roughness)
{
float r = (roughness + 1.0);
float k = (r*r) / 8.0;
float num = NdotV;
float denom = NdotV * (1.0 - k) + k;
return num / denom;
}
float pbr_geometrySmith(vec3 N, vec3 V, vec3 L, float roughness)
{
float NdotV = pbr_dot(N, V);
float NdotL = pbr_dot(N, L);
float ggx2 = pbr_geometrySchlickGGX(NdotV, roughness);
float ggx1 = pbr_geometrySchlickGGX(NdotL, roughness);
return ggx1 * ggx2;
}
vec3 pbr_fresnelSchlick(float cosTheta, vec3 F0)
{
return F0 + (1.0 - F0) * pow(1.0 - cosTheta, 5.0);
}

View File

@ -0,0 +1,35 @@
#include lumi:shaders/lib/bump.glsl
/*******************************************************
* lumi:shaders/lib/water.glsl *
*******************************************************
* Copyright (c) 2020 spiralhalo and Contributors. *
* Released WITHOUT WARRANTY under the terms of the *
* GNU Lesser General Public License version 3 as *
* published by the Free Software Foundation, Inc. *
*******************************************************/
float ww_noise(vec3 pos, vec3 move, float invScale, float amplitude, float stretch)
{
vec3 noisePos = vec3(pos.x * invScale * stretch, pos.y * invScale, pos.z * invScale) + move;
return (snoise(noisePos) * 0.5 + 0.5) * amplitude;
}
vec3 ww_normals(vec3 up, vec3 samplePos, float waveSpeed, float scale, float amplitude, float stretch, vec3 moveSpeed)
{
float microSample = 0.01 * scale;
float invScale = 1 / scale;
vec3 waveMove = moveSpeed * frx_renderSeconds() * waveSpeed;
waveMove.xz *= abs(up.y);
vec3 tmove = _bump_tangentMove(up);
vec3 bmove = _bump_bitangentMove(up, tmove) * microSample;
tmove *= microSample;
vec3 origin = ww_noise(samplePos, waveMove, invScale, amplitude, stretch) * up;
vec3 tangent = tmove + ww_noise(samplePos + tmove, waveMove, invScale, amplitude, stretch) * up - origin;
vec3 bitangent = bmove + ww_noise(samplePos + bmove, waveMove, invScale, amplitude, stretch) * up - origin;
vec3 noisyNormal = normalize(cross(tangent, bitangent));
return noisyNormal;
}

View File

@ -1,38 +1,43 @@
#include lumi:shaders/api/varying.glsl
#include lumi:shaders/lib/noise.glsl
#include frex:shaders/api/fragment.glsl #include frex:shaders/api/fragment.glsl
#include frex:shaders/api/world.glsl #include frex:shaders/api/world.glsl
#include respackopts:config_supplier #include frex:shaders/lib/noise/noise3d.glsl
#include frex:shaders/lib/color.glsl
#include lumi:shaders/lib/water.glsl
void frx_startFragment(inout frx_FragmentData fragData) { void frx_startFragment(inout frx_FragmentData fragData) {
fragData.spriteColor.rgb *= fragData.spriteColor.rgb * lumi_waterColorFactor; #ifdef lumi_pbr
/* PBR PARAMS */
pbr_f0 = vec3(0.02);
pbr_roughness = 0.05;
#else
/* HACK */
fragData.light.y += 0.077 * smoothstep(1.0, 0.99, fragData.vertexNormal.y);
fragData.light.y = min(0.96875, fragData.light.y);
if(fragData.vertexNormal.y > 0.01) { /* LUMI PARAMS */
ww_specular = 500.0;
// hack #endif
fragData.light.y += 0.077 * smoothstep(1.0, 0.99, fragData.vertexNormal.y);
fragData.light.y = min(0.96875, fragData.light.y); /* WATER RECOLOR */
vec3 desat = vec3(frx_luminance(fragData.vertexColor.rgb));
vec3 worldPos = frx_modelOriginWorldPos() + frx_var0.xyz; fragData.vertexColor.rgb = mix(fragData.vertexColor.rgb, desat, 0.7);
// water wavyness parameter
float timeScale = 2; // speed
float noiseScale = 2; // wavelength
float noiseAmp = 0.03125 * noiseScale;// * timeScale; // amplitude
// inferred parameter float maxc = max(fragData.spriteColor.r, max(fragData.spriteColor.g, fragData.spriteColor.b));
float renderTime = frx_renderSeconds() * 0.5 * timeScale; fragData.spriteColor.rgb *= fragData.spriteColor.rgb * fragData.spriteColor.rgb * 2.0;
float microSample = 0.01 * noiseScale;
// base noise float l = frx_luminance(fragData.spriteColor.rgb);
float noise = l2_noise(worldPos, renderTime, noiseScale, noiseAmp); pbr_f0 = mix(pbr_f0, vec3(0.2), l * l);
// normal recalculation /* WAVY NORMALS */
vec3 noiseOrigin = vec3(0, noise, 0); float waveSpeed = 1;
vec3 noiseTangent = vec3(microSample, l2_noise(worldPos + vec3(microSample,0,0), renderTime, noiseScale, noiseAmp), 0) - noiseOrigin; float scale = 1.5;
vec3 noiseBitangent = vec3(0, l2_noise(worldPos + vec3(0,0,microSample), renderTime, noiseScale, noiseAmp), microSample) - noiseOrigin; float amplitude = 0.01;
float stretch = 2;
// noisy normal // wave movement doesn't necessarily follow flow direction for the time being
vec3 noisyNormal = normalize(cross(noiseBitangent, noiseTangent)); vec3 moveSpeed = vec3(0.5, 1.5, -0.5);
fragData.vertexNormal = noisyNormal; // const float texAmplitude = 0.005;
} vec3 up = fragData.vertexNormal.xyz;// * (1.0 + texAmplitude);
vec3 samplePos = frx_var0.xyz;
// samplePos = floor(samplePos) + floor(fract(samplePos) * 16) / 16;
fragData.vertexNormal = ww_normals(up, samplePos, waveSpeed, scale, amplitude, stretch, moveSpeed);
} }

View File

@ -1,8 +1,14 @@
#include frex:shaders/api/vertex.glsl #include frex:shaders/api/vertex.glsl
#include lumi:shaders/api/varying.glsl #include frex:shaders/api/world.glsl
#include frex:shaders/lib/noise/noise3d.glsl
#include lumi:shaders/api/water_param.glsl
// #define WATER_VERTEX_WAVY
void frx_startVertex(inout frx_VertexData data) { void frx_startVertex(inout frx_VertexData data) {
frx_var0.xyz = data.vertex.xyz; frx_var0.xyz = data.vertex.xyz + frx_modelOriginWorldPos();
frx_var1.xyz = (gl_ModelViewMatrixInverse * vec4(0.0, 0.0, 0.0, 1.0)).xyz; #ifdef WATER_VERTEX_WAVY
wwv_specPower = 100.0; float amplitude = 0.03;
data.vertex.y += snoise(vec3(frx_var0.x, frx_renderSeconds(), frx_var0.z)) * amplitude;
#endif
} }

View File

@ -1,9 +0,0 @@
{
"respackopts.title.lumi": "Lumi Lights",
"respackopts.field.lumi.waterColorFactor": "Water Color Factor",
"respackopts.field.lumi.sunColorFactor": "Sun Color Factor",
"respackopts.field.lumi.tonemap": "Tonemap",
"respackopts.field.lumi.tonemap.reinhardJodie": "Reinhard Jodie",
"respackopts.field.lumi.tonemap.vibrant": "Vibrant",
"respackopts.field.lumi.tonemap.fxr": "Fxr"
}

View File

@ -0,0 +1,7 @@
{
"intensity": 1.0,
"red": 1.0,
"green": 0.875,
"blue": 0.75,
"worksInFluid": true
}

View File

@ -0,0 +1,8 @@
{
"intensity": 0.93,
"red": 1.0,
"green": 0.875,
"blue": 0.75,
"worksInFluid": false
}

View File

@ -0,0 +1,7 @@
{
"intensity": 0.93,
"red": 1.0,
"green": 0.875,
"blue": 0.75,
"worksInFluid": false
}

View File

@ -0,0 +1,8 @@
{
"intensity": 1.0,
"red": 1.0,
"green": 0.875,
"blue": 0.75,
"worksInFluid": true
}

View File

@ -0,0 +1,8 @@
{
"intensity": 0.93,
"red": 1.0,
"green": 0.875,
"blue": 0.75,
"worksInFluid": false
}

View File

@ -0,0 +1,3 @@
{
"defaultMaterial": "fabric:standard"
}

View File

@ -3,11 +3,16 @@
"version": 1, "version": 1,
"conf": { "conf": {
"tonemap": [ "tonemap": [
"reinhardJodie", "default",
"vibrant", "vibrant",
"fxr" "film"
], ],
"sunColorFactor": 0.8, "pbr": true,
"waterColorFactor": 1 "debugMode": [
"none",
"normal",
"viewDir"
],
"waterVertexWavy": false
} }
} }

View File

@ -1,6 +1,6 @@
{ {
"pack": { "pack": {
"pack_format": 6, "pack_format": 6,
"description": "§3Aesthetic shader pack\n§8by awoo [v1.0-wip]" "description": "§3Aesthetic shader pack\n§8by spiralhalo [v0.4]"
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -32,19 +32,12 @@ public class Respackopts implements ClientModInitializer {
public static final HashSet<Runnable> saveActions = new HashSet<>(); public static final HashSet<Runnable> saveActions = new HashSet<>();
@Override @Override
public void onInitializeClient() { public void onInitializeClient() {
load(); deNull();
Respackopts.save();
if (FabricLoader.getInstance().isDevelopmentEnvironment()) if (FabricLoader.getInstance().isDevelopmentEnvironment())
saveActions.add(() -> System.out.println("Save")); saveActions.add(() -> System.out.println("Save"));
} }
public static void save() { public static void save() {
deNull();
try {
Files.createDirectories(p);
} catch (IOException e) {
e.printStackTrace();
}
for (String s : resPackMetas.keySet()) { for (String s : resPackMetas.keySet()) {
s = resPackMetas.get(s).id; s = resPackMetas.get(s).id;
Config cfg = new Config(); Config cfg = new Config();
@ -72,31 +65,38 @@ public class Respackopts implements ClientModInitializer {
public static void load() { public static void load() {
try { try {
for (String s : resPackMetas.keySet()) { for (String s : resPackMetas.keySet()) {
s = resPackMetas.get(s).id; load(resPackMetas.get(s).id);
Path q = p.resolve(s + ".json");
if (Files.exists(q)) {
try {
Reader reader = Files.newBufferedReader(q);
Config c = g.fromJson(reader, Config.class);
reader.close();
if (c.bools != null)
boolVals.put(s, c.bools);
if (c.doubles != null)
numVals.put(s, c.doubles);
if (c.strings != null)
strVals.put(s, c.strings);
} catch (IOException e) {
e.printStackTrace();
}
}
} }
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
} }
deNull(); }
public static void load(String id) {
Path q = p.resolve(id + ".json");
if (Files.exists(q)) {
try {
Reader reader = Files.newBufferedReader(q);
Config c = g.fromJson(reader, Config.class);
reader.close();
if (c.bools != null)
boolVals.put(id, c.bools);
if (c.doubles != null)
numVals.put(id, c.doubles);
if (c.strings != null)
strVals.put(id, c.strings);
} catch (IOException e) {
e.printStackTrace();
}
}
} }
private static void deNull() { private static void deNull() {
try {
Files.createDirectories(p);
} catch (IOException e) {
e.printStackTrace();
}
if (boolVals == null) if (boolVals == null)
boolVals = new HashMap<>(); boolVals = new HashMap<>();
if (numVals == null) if (numVals == null)

View File

@ -17,7 +17,6 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.TreeSet; import java.util.TreeSet;
@ -39,6 +38,14 @@ public class ResourcePackManagerMixin {
Respackopts.strVals.put(conf.id, new HashMap<>()); Respackopts.strVals.put(conf.id, new HashMap<>());
if (!Respackopts.enumKeys.containsKey(conf.id)) if (!Respackopts.enumKeys.containsKey(conf.id))
Respackopts.enumKeys.put(conf.id, new HashMap<>()); Respackopts.enumKeys.put(conf.id, new HashMap<>());
if (Respackopts.metaVersion.equals(conf.version)) {
Respackopts.resPackMetas.put(v.getDisplayName().asString(), conf);
Respackopts.load(conf.id);
}
else {
System.err.println(s + " was not loaded as it specifies a different respackopts version than is installed");
return;
}
for (Map.Entry<String, JsonElement> entry : conf.conf.entrySet()) { for (Map.Entry<String, JsonElement> entry : conf.conf.entrySet()) {
String n = entry.getKey(); String n = entry.getKey();
if (n.contains(":") || n.contains(".") || n.contains("_")) { if (n.contains(":") || n.contains(".") || n.contains("_")) {
@ -91,12 +98,6 @@ public class ResourcePackManagerMixin {
System.err.println("[respackopts] Unsupported non-primitive datatype"); System.err.println("[respackopts] Unsupported non-primitive datatype");
} }
} }
if (Respackopts.metaVersion.equals(conf.version)) {
Respackopts.resPackMetas.put(v.getDisplayName().asString(), conf);
}
else {
System.err.println(s + " was not loaded as it specifies a different respackopts version than is installed");
}
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
} }