Skip to content

Commit 9c44de6

Browse files
committed
Update
1 parent eb19370 commit 9c44de6

30 files changed

+240
-75
lines changed

shaders/lang/en_US.lang

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ option.WavingLeaves=WavingLeaves
1414
option.WavingLeavesSpeed=WavingLeavesSpeed
1515
option.WaterWave=WaterWave
1616
option.UnderWaterCaustics=UnderWaterCaustics
17+
option.Water_Red=Red
18+
option.Water_Green=Green
19+
option.Water_Blue=Blue
1720
screen.CREDIT=CREDIT
1821
screen.CREDIT.comment=Thanks for the jebbyk's code contribution https://github.com/Open4Es/Open4Es-Shader-IOS
1922
screen.INFO=Open4ES-Shader-IOS
2023
screen.INFO.comment=Made by: §5@ENDERMANYK§r
2124
screen.WorldColor=WorldColor
25+
screen.WaterColor=WaterColor
2226
screen.Postprocessing=PostProcessing
2327
screen.ShadowSettings=ShadowSettings
2428
screen.WavingSettings=WavingSettings

shaders/lang/zh_CN.lang

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@ option.WavingLeaves=树叶晃动
1414
option.WavingLeavesSpeed=树叶晃动速度
1515
option.WaterWave=水体晃动
1616
option.UnderWaterCaustics=水下焦散
17+
option.Water_Red=红色
18+
option.Water_Green=绿色
19+
option.Water_Blue=红色
1720

18-
screen.CREDIT=CREDIT
21+
screen.CREDIT=鸣谢
1922
screen.CREDIT.comment=Thanks for the jebbyk's code contribution https://github.com/Open4Es/Open4Es-Shader-IOS
20-
screen.INFO=Open4ES-Shader-IOS
23+
screen.INFO=信息
2124
screen.INFO.comment=Made by: §5@ENDERMANYK§r
2225
screen.WorldColor=全局颜色
23-
screen.Postprocessing=后期处理
26+
screen.WaterColor=水体颜色
27+
screen.PostProcessing=后期处理
2428
screen.ShadowSettings=阴影设置
2529
screen.WavingSettings=晃动设置
2630
screen.WavingPlants=植物晃动

shaders/shaders.properties

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ screen.CREDIT=CREDIT
44
screen.WavingSettings=[WavingPlants] <empty> [WavingLeaves] <empty> [WavingWater]
55
screen.PostProcessing =[WorldColor] Brightness Bloom BloomQuality ChromaticAberration ChromaticAberrationQuality
66
screen.WorldColor=Red Green Blue
7-
screen.WavingWater=WaterWave UnderWaterCaustics
7+
screen.WavingWater=WaterWave UnderWaterCaustics [WaterColor]
8+
screen.WaterColor=Water_Red Water_Green Water_Blue
89
screen.ShadowSettings=ShadowMapping ShadowSamples
910
screen.WavingPlants=WavingPlants WavingPlantsSpeed
1011
screen.WavingLeaves=WavingLeaves WavingLeavesSpeed
11-
sliders=WavingLeavesSpeed WavingPlantsSpeed ShadowSamples BloomQuality ChromaticAberrationQuality Red Green Blue Brightness
12+
sliders=WavingLeavesSpeed WavingPlantsSpeed ShadowSamples BloomQuality ChromaticAberrationQuality Red Green Blue Brightness Water_Red Water_Green Water_Blue
1213
screen.columns=1
1314
screen.WavingSettings.columns=1

shaders/world0/composite.fsh

Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#version 120
1+
#version 130
22

33
#include "/lib/lib.glsl"
44
#define SHADOW_MAP_BIAS 0.85
@@ -11,6 +11,11 @@ uniform sampler2D gcolor;
1111
uniform sampler2D gnormal;
1212
uniform sampler2D shadow;
1313
uniform sampler2D depthtex0;
14+
uniform sampler2D depthtex1;
15+
uniform sampler2D shadowtex1;
16+
uniform sampler2D gtexture;
17+
uniform sampler2D colortex4;
18+
uniform sampler2D noisetex;
1419
uniform vec3 sunPosition;
1520
uniform vec3 moonPosition;
1621
uniform float rainStrength;
@@ -22,9 +27,6 @@ varying vec2 lmcoord;
2227
varying vec2 texcoord;
2328
varying float extShadow;
2429
varying vec3 lightPosition;
25-
varying vec3 mySunColor;
26-
varying vec3 mySkyColor;
27-
varying vec4 positionInViewCoord;
2830

2931
uniform vec3 cameraPosition;
3032
uniform vec3 fogColor;
@@ -56,49 +58,72 @@ vec2 rand2d(highp vec2 coord)
5658
return vec2(x, y);
5759
}
5860

61+
vec3 normalDecode(vec2 enc) {
62+
vec4 nn = vec4(2.0 * enc - 1.0, 1.0, -1.0);
63+
float l = dot(nn.xyz,-nn.xyw);
64+
nn.z = l;
65+
nn.xy *= sqrt(l);
66+
return nn.xyz * 2.0 + vec3(0.0, 0.0, -1.0);
67+
}
68+
5969
#ifdef ShadowMapping
60-
float shadowMapping(vec4 worldPosition, float dist) {
61-
if(dist > 0.9) //distance
70+
float shadowMapping(vec4 worldPosition, float dist, vec3 normal, float alpha){
71+
if(dist > 0.9)
6272
return extShadow;
6373
float shade = 0.0;
64-
vec4 shadowposition = shadowModelView * worldPosition;
65-
shadowposition = shadowProjection * shadowposition;
66-
float distb = sqrt(shadowposition.x * shadowposition.x + shadowposition.y * shadowposition.y);
67-
float distortFactor = (1.0 - SHADOW_MAP_BIAS) + distb * SHADOW_MAP_BIAS;
68-
shadowposition.xy /= distortFactor;
69-
shadowposition /= shadowposition.w;
70-
shadowposition = shadowposition * 0.5 + 0.5;
71-
72-
float shadowSamplesRadius = 0.001;
73-
74-
for(float i = 1.0; i <= ShadowSamples; i += 1.0)
74+
float angle = dot(lightPosition, normal);
75+
if(angle <= 0.1 && alpha > 0.99)
76+
{
77+
shade = 1.0;
78+
}
79+
else
7580
{
81+
vec4 shadowposition = shadowModelView * worldPosition;
82+
shadowposition = shadowProjection * shadowposition;
83+
float distb = sqrt(shadowposition.x * shadowposition.x + shadowposition.y * shadowposition.y);
84+
float distortFactor = (1.0 - SHADOW_MAP_BIAS) + distb * SHADOW_MAP_BIAS;
85+
shadowposition.xy /= distortFactor;
86+
shadowposition /= shadowposition.w;
87+
shadowposition = shadowposition * 0.5 + 0.5;
88+
float shadowSamplesRadius = 0.001;
89+
90+
for(float i = 1.0; i <= ShadowSamples; i += 1.0){
7691
vec2 sampleCoord = rand2d(shadowposition.xy * i) - 0.5;
7792
float shadowDepth = texture2D(shadow, shadowposition.st + sampleCoord * shadowSamplesRadius).z;
78-
if(shadowDepth + 0.0005 < shadowposition.z ){
93+
if(shadowDepth + 0.0003 < shadowposition.z ){
7994
shade += 1.0;
80-
}
95+
}if(angle < 0.2 && alpha > 0.99)
96+
shade = max(shade, 1.0 - (angle - 0.1) * 10.0);}
97+
shade /= ShadowSamples;
8198
}
82-
shade /= ShadowSamples;
83-
8499
shade -= clamp((dist - 0.7) * 5.0, 0.0, 1.0);
85-
shade = clamp(shade, 0.0, 1.0);
100+
shade = clamp(shade, 0.0, 1.0);
86101
return max(shade, extShadow);
87102
}
88103
#endif
104+
89105
void main() {
106+
90107
vec4 color = texture2D(gcolor, texcoord.st);
108+
vec3 normal = normalDecode(texture2D(gnormal, texcoord.st).rg);
91109
#ifdef ShadowMapping
92110
float indoor=smoothstep(.95,1.,lmcoord.y);
93111
float cave=smoothstep(.7,1.,lmcoord.y);
94112
float day=saturate(skyColor.r*2.);
95113
float sunset=saturate((fogColor.r-.1)-fogColor.b);
96-
float depth = texture2D(depthtex0, texcoord.st).x;
97-
vec4 viewPosition = gbufferProjectionInverse * vec4(texcoord.s * 2.0 - 1.0, texcoord.t * 2.0 - 1.0, 2.0 * depth - 1.0, 1.0f);
98-
viewPosition /= viewPosition.w;
99-
vec4 worldPosition = gbufferModelViewInverse * viewPosition;
100-
float dist = length(worldPosition.xyz) / far;
101-
float shade = shadowMapping(worldPosition, dist);
114+
115+
float depth0 = texture2D(depthtex0, texcoord.st).x;
116+
vec4 viewPosition0 = gbufferProjectionInverse * vec4(texcoord.s * 2.0 - 1.0, texcoord.t * 2.0 - 1.0, 2.0 * depth0 - 1.0, 1.0f);
117+
viewPosition0 /= viewPosition0.w;
118+
vec4 worldPosition0 = gbufferModelViewInverse * viewPosition0;
119+
120+
/*float depth1 = texture2D(depthtex1, texcoord.st).x;
121+
vec4 viewPosition1 = gbufferProjectionInverse * vec4(texcoord.s * 2.0 - 1.0, texcoord.t * 2.0 - 1.0, 2.0 * depth1 - 1.0, 1.0f);
122+
viewPosition1 /= viewPosition1.w;
123+
vec4 worldPosition1 = gbufferModelViewInverse * viewPosition1;*/
124+
125+
float dist = length(worldPosition0.xyz) / far;
126+
float shade = shadowMapping(worldPosition0, dist, normal, color.a);
102127
if(12000<worldTime && worldTime<13000) {
103128
color.rgb *=(1.0 - shade *0.5*(1.0-rainStrength*0.8)*(1.0-lmcoord.x*0.4)); // dusk
104129
}
@@ -120,5 +145,4 @@ return;
120145
/* DRAWBUFFERS:0 */
121146
gl_FragData[0] = color;
122147

123-
124148
}

shaders/world0/final.fsh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111
#define ChromaticAberrationQuality 1.0 //[1.0 2.0 4.0 8.0]
1212

1313
uniform sampler2D gcolor;
14+
uniform sampler2D colortex4;
15+
uniform sampler2D depthtex0;
1416
uniform float rainStrength;
1517
uniform float aspectRatio;
1618
uniform int worldTime;
1719
varying vec2 texcoord;
20+
1821

1922
float A = 0.2;
2023
float B = 0.50;

shaders/world0/final.vsh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#version 120
22

33
varying vec2 texcoord;
4-
4+
55
void main() {
66
vec4 position = gl_ModelViewMatrix * gl_Vertex;
77
gl_Position = gl_ProjectionMatrix * position;
88

99
texcoord = gl_MultiTexCoord0.st;
10+
1011
}

shaders/world0/gbuffers_basic.fsh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#version 120
22

33
varying vec4 color;
4+
varying vec2 normal;
45

5-
/* DRAWBUFFERS:0 */
6+
/* DRAWBUFFERS:02 */
67
void main() {
78
gl_FragData[0] = color;
8-
9+
gl_FragData[1] = vec4(normal, 0.0, 1.0);
910
}

shaders/world0/gbuffers_basic.vsh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
#version 120
22

33
varying vec4 color;
4+
varying vec2 normal;
5+
6+
vec2 normalEncode(vec3 n) {
7+
vec2 enc = normalize(n.xy) * (sqrt(-n.z*0.5+0.5));
8+
enc = enc*0.5+0.5;
9+
return enc;
10+
}
411

512
void main() {
613

714
vec4 position = gl_ModelViewMatrix * gl_Vertex;
815
gl_Position = gl_ProjectionMatrix * position;
16+
normal = normalEncode(gl_NormalMatrix * gl_Normal);
917
color = gl_Color;
1018
}

shaders/world0/gbuffers_clouds.fsh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ varying vec2 texcoord;
1010
varying vec3 cPos;
1111
varying vec3 wPos;
1212
varying vec4 glcolor;
13-
14-
/* DRAWBUFFERS:0 */
13+
varying vec2 normal;
14+
15+
/* DRAWBUFFERS:02 */
1516
void main(){
1617
#ifdef VANILLA_CLOUDS
1718
vec4 color=texture(gtexture,texcoord)*glcolor;
1819
color.rgb=mix(color.rgb,fogColor,smoothstep(0.,far,length(wPos.xz)));
1920
gl_FragData[0]=color;
21+
gl_FragData[1] = vec4(normal, 0.0, 1.0);
2022
#else
2123
discard;
2224
#endif

shaders/world0/gbuffers_clouds.vsh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,18 @@ varying vec2 texcoord;
99
varying vec3 cPos;
1010
varying vec3 wPos;
1111
varying vec4 glcolor;
12+
varying vec2 normal;
13+
14+
vec2 normalEncode(vec3 n) {
15+
vec2 enc = normalize(n.xy) * (sqrt(-n.z*0.5+0.5));
16+
enc = enc*0.5+0.5;
17+
return enc;
18+
}
1219

1320
void main(){
1421
vec4 position = gl_ModelViewMatrix * gl_Vertex;
1522
gl_Position = gl_ProjectionMatrix * position;
23+
normal = normalEncode(gl_NormalMatrix * gl_Normal);
1624
texcoord=(gl_TextureMatrix[0]*gl_MultiTexCoord0).xy;
1725
glcolor=gl_Color;
1826
vec4 pos=gbufferModelViewInverse*gl_ModelViewMatrix*gl_Vertex;

0 commit comments

Comments
 (0)