Reduces shader inputs duplication and wraps them in a macro. Refs #6636
Tested By: Stan Differential Revision: https://code.wildfiregames.com/D4837 This was SVN commit r27282.
This commit is contained in:
parent
a451da151d
commit
7c20a8c958
@ -1,17 +1,12 @@
|
||||
#version 110
|
||||
|
||||
#include "canvas2d.h"
|
||||
|
||||
#include "common/fragment.h"
|
||||
|
||||
uniform sampler2D tex;
|
||||
uniform vec4 colorAdd;
|
||||
uniform vec4 colorMul;
|
||||
uniform float grayscaleFactor;
|
||||
|
||||
varying vec2 v_uv;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 colorTex = texture2D(tex, v_uv);
|
||||
vec4 colorTex = SAMPLE_2D(GET_DRAW_TEXTURE_2D(tex), v_uv);
|
||||
vec3 grayColor = vec3(dot(vec3(0.3, 0.59, 0.11), colorTex.rgb));
|
||||
OUTPUT_FRAGMENT_SINGLE_COLOR(clamp(mix(colorTex, vec4(grayColor, colorTex.a), grayscaleFactor) * colorMul + colorAdd, 0.0, 1.0));
|
||||
}
|
||||
|
15
binaries/data/mods/mod/shaders/glsl/canvas2d.h
Normal file
15
binaries/data/mods/mod/shaders/glsl/canvas2d.h
Normal file
@ -0,0 +1,15 @@
|
||||
#include "common/stage.h"
|
||||
|
||||
BEGIN_DRAW_TEXTURES
|
||||
TEXTURE_2D(0, tex)
|
||||
END_DRAW_TEXTURES
|
||||
|
||||
BEGIN_DRAW_UNIFORMS
|
||||
UNIFORM(vec4, transform)
|
||||
UNIFORM(vec2, translation)
|
||||
UNIFORM(vec4, colorAdd)
|
||||
UNIFORM(vec4, colorMul)
|
||||
UNIFORM(float, grayscaleFactor)
|
||||
END_DRAW_UNIFORMS
|
||||
|
||||
VERTEX_OUTPUT(0, vec2, v_uv);
|
@ -1,15 +1,12 @@
|
||||
#version 110
|
||||
|
||||
#include "canvas2d.h"
|
||||
|
||||
#include "common/vertex.h"
|
||||
|
||||
uniform vec4 transform;
|
||||
uniform vec2 translation;
|
||||
|
||||
VERTEX_INPUT_ATTRIBUTE(0, vec2, a_vertex);
|
||||
VERTEX_INPUT_ATTRIBUTE(1, vec2, a_uv0);
|
||||
|
||||
varying vec2 v_uv;
|
||||
|
||||
void main()
|
||||
{
|
||||
v_uv = a_uv0;
|
||||
|
@ -20,13 +20,19 @@
|
||||
// GLSL port of the CasFilter() (no scaling). https://github.com/GPUOpen-Effects/FidelityFX-CAS/blob/master/ffx-cas/ffx_cas.h
|
||||
|
||||
#include "common/fragment.h"
|
||||
#include "common/stage.h"
|
||||
|
||||
uniform sampler2D renderedTex;
|
||||
uniform float width;
|
||||
uniform float height;
|
||||
uniform float sharpness;
|
||||
BEGIN_DRAW_TEXTURES
|
||||
TEXTURE_2D(0, renderedTex)
|
||||
END_DRAW_TEXTURES
|
||||
|
||||
varying vec2 v_tex;
|
||||
BEGIN_DRAW_UNIFORMS
|
||||
UNIFORM(float, width)
|
||||
UNIFORM(float, height)
|
||||
UNIFORM(float, sharpness)
|
||||
END_DRAW_UNIFORMS
|
||||
|
||||
VERTEX_OUTPUT(0, vec2, v_tex);
|
||||
|
||||
float saturate(float inputFloat)
|
||||
{
|
||||
@ -38,7 +44,7 @@ vec3 saturate(vec3 inputFloat)
|
||||
return vec3(saturate(inputFloat.x), saturate(inputFloat.y), saturate(inputFloat.z));
|
||||
}
|
||||
|
||||
vec3 sharpen()
|
||||
vec3 sharpen(sampler2D tex)
|
||||
{
|
||||
vec2 invSSize = vec2(1.0 / width, 1.0 / height);
|
||||
|
||||
@ -46,15 +52,15 @@ vec3 sharpen()
|
||||
// a b c
|
||||
// d(e)f
|
||||
// g h i
|
||||
vec3 a = texture2D(renderedTex, v_tex + vec2(-1.0, -1.0) * invSSize).rgb;
|
||||
vec3 b = texture2D(renderedTex, v_tex + vec2(0.0, -1.0) * invSSize).rgb;
|
||||
vec3 c = texture2D(renderedTex, v_tex + vec2(1.0, -1.0) * invSSize).rgb;
|
||||
vec3 d = texture2D(renderedTex, v_tex + vec2(-1.0, 0.0) * invSSize).rgb;
|
||||
vec3 e = texture2D(renderedTex, v_tex + vec2(0.0, 0.0) * invSSize).rgb;
|
||||
vec3 f = texture2D(renderedTex, v_tex + vec2(1.0, 0.0) * invSSize).rgb;
|
||||
vec3 g = texture2D(renderedTex, v_tex + vec2(-1.0, 1.0) * invSSize).rgb;
|
||||
vec3 h = texture2D(renderedTex, v_tex + vec2(0.0, 1.0) * invSSize).rgb;
|
||||
vec3 i = texture2D(renderedTex, v_tex + vec2(1.0, 1.0) * invSSize).rgb;
|
||||
vec3 a = SAMPLE_2D(tex, v_tex + vec2(-1.0, -1.0) * invSSize).rgb;
|
||||
vec3 b = SAMPLE_2D(tex, v_tex + vec2(0.0, -1.0) * invSSize).rgb;
|
||||
vec3 c = SAMPLE_2D(tex, v_tex + vec2(1.0, -1.0) * invSSize).rgb;
|
||||
vec3 d = SAMPLE_2D(tex, v_tex + vec2(-1.0, 0.0) * invSSize).rgb;
|
||||
vec3 e = SAMPLE_2D(tex, v_tex + vec2(0.0, 0.0) * invSSize).rgb;
|
||||
vec3 f = SAMPLE_2D(tex, v_tex + vec2(1.0, 0.0) * invSSize).rgb;
|
||||
vec3 g = SAMPLE_2D(tex, v_tex + vec2(-1.0, 1.0) * invSSize).rgb;
|
||||
vec3 h = SAMPLE_2D(tex, v_tex + vec2(0.0, 1.0) * invSSize).rgb;
|
||||
vec3 i = SAMPLE_2D(tex, v_tex + vec2(1.0, 1.0) * invSSize).rgb;
|
||||
|
||||
// Soft min and max.
|
||||
// a b c b
|
||||
@ -91,5 +97,5 @@ vec3 sharpen()
|
||||
|
||||
void main()
|
||||
{
|
||||
OUTPUT_FRAGMENT_SINGLE_COLOR(vec4(sharpen(), 1.0));
|
||||
OUTPUT_FRAGMENT_SINGLE_COLOR(vec4(sharpen(GET_DRAW_TEXTURE_2D(renderedTex)), 1.0));
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
#ifndef INCLUDED_COMMON_FRAGMENT
|
||||
#define INCLUDED_COMMON_FRAGMENT
|
||||
|
||||
#include "common/texture.h"
|
||||
#include "common/uniform.h"
|
||||
|
||||
#define OUTPUT_FRAGMENT_SINGLE_COLOR(COLOR) \
|
||||
gl_FragColor = COLOR
|
||||
|
||||
|
9
binaries/data/mods/mod/shaders/glsl/common/stage.h
Normal file
9
binaries/data/mods/mod/shaders/glsl/common/stage.h
Normal file
@ -0,0 +1,9 @@
|
||||
#ifndef INCLUDED_COMMON_STAGE
|
||||
#define INCLUDED_COMMON_STAGE
|
||||
|
||||
#include "common/uniform.h"
|
||||
|
||||
#define VERTEX_OUTPUT(LOCATION, TYPE, NAME) \
|
||||
varying TYPE NAME
|
||||
|
||||
#endif // INCLUDED_COMMON_STAGE
|
8
binaries/data/mods/mod/shaders/glsl/common/texture.h
Normal file
8
binaries/data/mods/mod/shaders/glsl/common/texture.h
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef INCLUDED_COMMON_TEXTURE
|
||||
#define INCLUDED_COMMON_TEXTURE
|
||||
|
||||
#define SAMPLE_2D texture2D
|
||||
#define SAMPLE_2D_SHADOW shadow2D
|
||||
#define SAMPLE_CUBE textureCube
|
||||
|
||||
#endif // INCLUDED_COMMON_TEXTURE
|
36
binaries/data/mods/mod/shaders/glsl/common/uniform.h
Normal file
36
binaries/data/mods/mod/shaders/glsl/common/uniform.h
Normal file
@ -0,0 +1,36 @@
|
||||
#ifndef INCLUDED_COMMON_UNIFORM
|
||||
#define INCLUDED_COMMON_UNIFORM
|
||||
|
||||
#define BEGIN_DRAW_TEXTURES
|
||||
#define END_DRAW_TEXTURES
|
||||
#define NO_DRAW_TEXTURES
|
||||
|
||||
#if STAGE_FRAGMENT
|
||||
#define TEXTURE_2D(LOCATION, NAME) \
|
||||
uniform sampler2D NAME;
|
||||
#define TEXTURE_2D_SHADOW(LOCATION, NAME) \
|
||||
uniform sampler2DShadow NAME;
|
||||
#define TEXTURE_CUBE(LOCATION, NAME) \
|
||||
uniform samplerCube NAME;
|
||||
#else
|
||||
#define TEXTURE_2D(LOCATION, NAME)
|
||||
#define TEXTURE_2D_SHADOW(LOCATION, NAME)
|
||||
#define TEXTURE_CUBE(LOCATION, NAME)
|
||||
#endif
|
||||
|
||||
#define GET_DRAW_TEXTURE_2D(NAME) \
|
||||
NAME
|
||||
#define GET_DRAW_TEXTURE_2D_SHADOW(NAME) \
|
||||
NAME
|
||||
#define GET_DRAW_TEXTURE_CUBE(NAME) \
|
||||
NAME
|
||||
|
||||
#define BEGIN_DRAW_UNIFORMS
|
||||
#define END_DRAW_UNIFORMS
|
||||
#define BEGIN_MATERIAL_UNIFORMS
|
||||
#define END_MATERIAL_UNIFORMS
|
||||
|
||||
#define UNIFORM(TYPE, NAME) \
|
||||
uniform TYPE NAME;
|
||||
|
||||
#endif // INCLUDED_COMMON_UNIFORM
|
@ -1,6 +1,8 @@
|
||||
#ifndef INCLUDED_COMMON_VERTEX
|
||||
#define INCLUDED_COMMON_VERTEX
|
||||
|
||||
#include "common/uniform.h"
|
||||
|
||||
#define VERTEX_INPUT_ATTRIBUTE(LOCATION, TYPE, NAME) \
|
||||
attribute TYPE NAME
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
// * Luma calculated by 3 components instead of the only green one.
|
||||
|
||||
#include "common/fragment.h"
|
||||
#include "common/stage.h"
|
||||
|
||||
#define FXAA_QUALITY__PRESET 10
|
||||
|
||||
@ -604,11 +605,16 @@ vec4 FxaaPixelShader(
|
||||
return vec4(FxaaTexTop(tex, posM).xyz, lumaM);
|
||||
}
|
||||
|
||||
uniform sampler2D renderedTex;
|
||||
uniform float width;
|
||||
uniform float height;
|
||||
BEGIN_DRAW_TEXTURES
|
||||
TEXTURE_2D(0, renderedTex)
|
||||
END_DRAW_TEXTURES
|
||||
|
||||
varying vec2 v_tex;
|
||||
BEGIN_DRAW_UNIFORMS
|
||||
UNIFORM(float, width)
|
||||
UNIFORM(float, height)
|
||||
END_DRAW_UNIFORMS
|
||||
|
||||
VERTEX_OUTPUT(0, vec2, v_tex);
|
||||
|
||||
void main()
|
||||
{
|
||||
@ -617,7 +623,7 @@ void main()
|
||||
const float fxaaQualityEdgeThreshold = 0.125;
|
||||
const float fxaaQualityEdgeThresholdMin = 0.0312;
|
||||
OUTPUT_FRAGMENT_SINGLE_COLOR(FxaaPixelShader(
|
||||
v_tex, renderedTex,
|
||||
v_tex, GET_DRAW_TEXTURE_2D(renderedTex),
|
||||
vec2(1.0, 1.0) / vec2(width, height),
|
||||
fxaaQualitySubpix,
|
||||
fxaaQualityEdgeThreshold,
|
||||
|
@ -1,12 +1,13 @@
|
||||
#version 110
|
||||
|
||||
#include "common/stage.h"
|
||||
#include "common/vertex.h"
|
||||
|
||||
varying vec2 v_tex;
|
||||
|
||||
VERTEX_INPUT_ATTRIBUTE(0, vec3, a_vertex);
|
||||
VERTEX_INPUT_ATTRIBUTE(1, vec2, a_uv0);
|
||||
|
||||
VERTEX_OUTPUT(0, vec2, v_tex);
|
||||
|
||||
void main()
|
||||
{
|
||||
OUTPUT_VERTEX_POSITION(vec4(a_vertex, 1.0));
|
||||
|
@ -1,15 +1,22 @@
|
||||
#version 110
|
||||
|
||||
#include "common/fragment.h"
|
||||
#include "common/stage.h"
|
||||
|
||||
varying vec2 v_tex;
|
||||
uniform sampler2D renderedTex;
|
||||
uniform vec2 texSize;
|
||||
BEGIN_DRAW_TEXTURES
|
||||
TEXTURE_2D(0, renderedTex)
|
||||
END_DRAW_TEXTURES
|
||||
|
||||
BEGIN_DRAW_UNIFORMS
|
||||
UNIFORM(vec2, texSize)
|
||||
END_DRAW_UNIFORMS
|
||||
|
||||
VERTEX_OUTPUT(0, vec2, v_tex);
|
||||
|
||||
void main()
|
||||
{
|
||||
#if BLOOM_NOP
|
||||
OUTPUT_FRAGMENT_SINGLE_COLOR(vec4(texture2D(renderedTex, v_tex).rgb, 1.0));
|
||||
OUTPUT_FRAGMENT_SINGLE_COLOR(vec4(SAMPLE_2D(GET_DRAW_TEXTURE_2D(renderedTex), v_tex).rgb, 1.0));
|
||||
#endif
|
||||
|
||||
#if BLOOM_PASS_H
|
||||
@ -18,7 +25,7 @@ void main()
|
||||
|
||||
for (int i = 0; i < 6; ++i)
|
||||
{
|
||||
color += texture2D(renderedTex, v_tex_offs);
|
||||
color += SAMPLE_2D(GET_DRAW_TEXTURE_2D(renderedTex), v_tex_offs);
|
||||
v_tex_offs += vec2(0.004, 0.0);
|
||||
}
|
||||
|
||||
@ -31,10 +38,10 @@ void main()
|
||||
|
||||
for (int i = 0; i < 6; ++i)
|
||||
{
|
||||
color += texture2D(renderedTex, v_tex_offs);
|
||||
color += SAMPLE_2D(GET_DRAW_TEXTURE_2D(renderedTex), v_tex_offs);
|
||||
v_tex_offs += vec2(0.0, 0.004);
|
||||
}
|
||||
|
||||
OUTPUT_FRAGMENT_SINGLE_COLOR(vec4(color.rgb / 6.0, 1.0));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,7 @@
|
||||
#ifndef INCLUDED_FOG
|
||||
#define INCLUDED_FOG
|
||||
#ifndef INCLUDED_COMMON_FOG
|
||||
#define INCLUDED_COMMON_FOG
|
||||
|
||||
#if USE_FOG
|
||||
uniform vec3 fogColor;
|
||||
uniform vec2 fogParams;
|
||||
#endif
|
||||
|
||||
vec3 applyFog(vec3 color)
|
||||
vec3 applyFog(vec3 color, vec3 fogColor, vec2 fogParams)
|
||||
{
|
||||
#if USE_FOG
|
||||
float density = fogParams.x;
|
||||
@ -26,4 +21,4 @@ vec3 applyFog(vec3 color)
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // INCLUDED_FOG
|
||||
#endif // INCLUDED_COMMON_FOG
|
||||
|
@ -1,21 +1,17 @@
|
||||
#ifndef INCLUDED_LOS_FRAGMENT
|
||||
#define INCLUDED_LOS_FRAGMENT
|
||||
#ifndef INCLUDED_COMMON_LOS_FRAGMENT
|
||||
#define INCLUDED_COMMON_LOS_FRAGMENT
|
||||
|
||||
#include "common/texture.h"
|
||||
|
||||
#if !IGNORE_LOS
|
||||
uniform sampler2D losTex;
|
||||
|
||||
varying vec2 v_los;
|
||||
#endif
|
||||
|
||||
float getLOS()
|
||||
float getLOS(sampler2D losTex, vec2 uv)
|
||||
{
|
||||
#if !IGNORE_LOS
|
||||
float los = texture2D(losTex, v_los).r;
|
||||
float los = SAMPLE_2D(losTex, uv).r;
|
||||
float threshold = 0.03;
|
||||
return clamp(los - threshold, 0.0, 1.0) / (1.0 - threshold);
|
||||
#else
|
||||
return 1.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // INCLUDED_LOS_FRAGMENT
|
||||
return 1.0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // INCLUDED_COMMON_LOS_FRAGMENT
|
||||
|
@ -1,17 +1,11 @@
|
||||
#ifndef INCLUDED_LOS_VERTEX
|
||||
#define INCLUDED_LOS_VERTEX
|
||||
#ifndef INCLUDED_COMMON_LOS_VERTEX
|
||||
#define INCLUDED_COMMON_LOS_VERTEX
|
||||
|
||||
#if !IGNORE_LOS
|
||||
uniform vec2 losTransform;
|
||||
|
||||
varying vec2 v_los;
|
||||
#endif
|
||||
|
||||
void calculateLOSCoordinates(vec2 position)
|
||||
vec2 calculateLOSCoordinates(vec2 position, vec2 losTransform)
|
||||
{
|
||||
#if !IGNORE_LOS
|
||||
v_los = position * losTransform.x + losTransform.y;
|
||||
#endif
|
||||
return position * losTransform.x + losTransform.y;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // INCLUDED_LOS_VERTEX
|
||||
#endif // INCLUDED_COMMON_LOS_VERTEX
|
||||
|
40
binaries/data/mods/public/shaders/glsl/common/shadows.h
Normal file
40
binaries/data/mods/public/shaders/glsl/common/shadows.h
Normal file
@ -0,0 +1,40 @@
|
||||
#ifndef INCLUDED_SHADOWS
|
||||
#define INCLUDED_SHADOWS
|
||||
|
||||
#include "common/stage.h"
|
||||
|
||||
#if USE_SHADOW
|
||||
|
||||
#if USE_SHADOW_SAMPLER
|
||||
#define SHADOWS_TEXTURES(START_LOCATION) \
|
||||
TEXTURE_2D_SHADOW(START_LOCATION, shadowTex)
|
||||
#else
|
||||
#define SHADOWS_TEXTURES(START_LOCATION) \
|
||||
TEXTURE_2D(START_LOCATION, shadowTex)
|
||||
#endif
|
||||
|
||||
#if SHADOWS_CASCADE_COUNT == 1
|
||||
#define SHADOWS_UNIFORMS \
|
||||
UNIFORM(vec4, cameraForward) \
|
||||
UNIFORM(vec4, shadowScale) \
|
||||
UNIFORM(mat4, shadowTransform) \
|
||||
UNIFORM(float, shadowDistance)
|
||||
|
||||
#define SHADOWS_VERTEX_OUTPUTS(START_LOCATION) \
|
||||
VERTEX_OUTPUT(START_LOCATION + 0, float, v_depth); \
|
||||
VERTEX_OUTPUT(START_LOCATION + 1, vec4, v_shadow);
|
||||
#else // SHADOWS_CASCADE_COUNT == 1
|
||||
#define SHADOWS_UNIFORMS \
|
||||
UNIFORM(vec4, cameraForward) \
|
||||
UNIFORM(vec4, shadowScale) \
|
||||
UNIFORM(mat4, shadowTransforms[SHADOWS_CASCADE_COUNT]) \
|
||||
UNIFORM(float, shadowDistances[SHADOWS_CASCADE_COUNT])
|
||||
|
||||
#define SHADOWS_VERTEX_OUTPUTS(START_LOCATION) \
|
||||
VERTEX_OUTPUT(START_LOCATION + 0, float, v_depth); \
|
||||
VERTEX_OUTPUT(START_LOCATION + 1, vec4, v_shadow[SHADOWS_CASCADE_COUNT]);
|
||||
#endif // SHADOWS_CASCADE_COUNT == 1
|
||||
|
||||
#endif // USE_SHADOW
|
||||
|
||||
#endif // INCLUDED_SHADOWS
|
@ -1,24 +1,7 @@
|
||||
#ifndef INCLUDED_SHADOWS_FRAGMENT
|
||||
#define INCLUDED_SHADOWS_FRAGMENT
|
||||
|
||||
#if USE_SHADOW
|
||||
varying float v_depth;
|
||||
#if USE_SHADOW_SAMPLER
|
||||
uniform sampler2DShadow shadowTex;
|
||||
#if USE_SHADOW_PCF
|
||||
uniform vec4 shadowScale;
|
||||
#endif
|
||||
#else
|
||||
uniform sampler2D shadowTex;
|
||||
#endif
|
||||
#if SHADOWS_CASCADE_COUNT == 1
|
||||
uniform float shadowDistance;
|
||||
varying vec4 v_shadow;
|
||||
#else
|
||||
uniform float shadowDistances[SHADOWS_CASCADE_COUNT];
|
||||
varying vec4 v_shadow[SHADOWS_CASCADE_COUNT];
|
||||
#endif
|
||||
#endif
|
||||
#include "common/shadows.h"
|
||||
|
||||
float getShadowImpl(vec4 shadowVertex, float shadowBias)
|
||||
{
|
||||
@ -30,17 +13,17 @@ float getShadowImpl(vec4 shadowVertex, float shadowBias)
|
||||
vec4 size = vec4(offset + 1.0, 2.0 - offset);
|
||||
vec4 weight = (vec4(1.0, 1.0, -0.5, -0.5) + (shadowVertex.xy - 0.5*offset).xyxy) * shadowScale.zwzw;
|
||||
return (1.0/9.0)*dot(size.zxzx*size.wwyy,
|
||||
vec4(shadow2D(shadowTex, vec3(weight.zw, biasedShdwZ)).r,
|
||||
shadow2D(shadowTex, vec3(weight.xw, biasedShdwZ)).r,
|
||||
shadow2D(shadowTex, vec3(weight.zy, biasedShdwZ)).r,
|
||||
shadow2D(shadowTex, vec3(weight.xy, biasedShdwZ)).r));
|
||||
vec4(SAMPLE_2D_SHADOW(GET_DRAW_TEXTURE_2D_SHADOW(shadowTex), vec3(weight.zw, biasedShdwZ)).r,
|
||||
SAMPLE_2D_SHADOW(GET_DRAW_TEXTURE_2D_SHADOW(shadowTex), vec3(weight.xw, biasedShdwZ)).r,
|
||||
SAMPLE_2D_SHADOW(GET_DRAW_TEXTURE_2D_SHADOW(shadowTex), vec3(weight.zy, biasedShdwZ)).r,
|
||||
SAMPLE_2D_SHADOW(GET_DRAW_TEXTURE_2D_SHADOW(shadowTex), vec3(weight.xy, biasedShdwZ)).r));
|
||||
#else
|
||||
return shadow2D(shadowTex, vec3(shadowVertex.xy, biasedShdwZ)).r;
|
||||
return SAMPLE_2D_SHADOW(GET_DRAW_TEXTURE_2D_SHADOW(shadowTex), vec3(shadowVertex.xy, biasedShdwZ)).r;
|
||||
#endif
|
||||
#else
|
||||
if (biasedShdwZ >= 1.0)
|
||||
return 1.0;
|
||||
return (biasedShdwZ < texture2D(shadowTex, shadowVertex.xy).x ? 1.0 : 0.0);
|
||||
return (biasedShdwZ < SAMPLE_2D(GET_DRAW_TEXTURE_2D(shadowTex), shadowVertex.xy).x ? 1.0 : 0.0);
|
||||
#endif
|
||||
#else
|
||||
return 1.0;
|
||||
|
@ -1,40 +1,30 @@
|
||||
#ifndef INCLUDED_SHADOWS_VERTEX
|
||||
#define INCLUDED_SHADOWS_VERTEX
|
||||
|
||||
#if USE_SHADOW
|
||||
uniform vec4 cameraForward;
|
||||
varying float v_depth;
|
||||
#if SHADOWS_CASCADE_COUNT == 1
|
||||
uniform mat4 shadowTransform;
|
||||
varying vec4 v_shadow;
|
||||
#else
|
||||
uniform mat4 shadowTransforms[SHADOWS_CASCADE_COUNT];
|
||||
varying vec4 v_shadow[SHADOWS_CASCADE_COUNT];
|
||||
#endif
|
||||
#include "common/shadows.h"
|
||||
|
||||
vec4 calculatePositionInShadowSpaceImpl(
|
||||
vec4 position, mat4 shadowTransform, vec4 shadowScale)
|
||||
{
|
||||
vec4 shadow = shadowTransform * position;
|
||||
#if USE_SHADOW_SAMPLER && USE_SHADOW_PCF
|
||||
uniform vec4 shadowScale;
|
||||
shadow.xy *= shadowScale.xy;
|
||||
#endif
|
||||
#endif // USE_SHADOW
|
||||
return shadow;
|
||||
}
|
||||
|
||||
void calculatePositionInShadowSpace(vec4 position)
|
||||
{
|
||||
#if USE_SHADOW
|
||||
v_depth = dot(cameraForward.xyz, position.xyz) - cameraForward.w;
|
||||
#if SHADOWS_CASCADE_COUNT == 1
|
||||
v_shadow = shadowTransform * position;
|
||||
#if USE_SHADOW_SAMPLER && USE_SHADOW_PCF
|
||||
v_shadow.xy *= shadowScale.xy;
|
||||
#endif
|
||||
v_shadow = calculatePositionInShadowSpaceImpl(position, shadowTransform, shadowScale);
|
||||
#else
|
||||
for (int cascade = 0; cascade < SHADOWS_CASCADE_COUNT; ++cascade)
|
||||
{
|
||||
v_shadow[cascade] = shadowTransforms[cascade] * position;
|
||||
#if USE_SHADOW_SAMPLER && USE_SHADOW_PCF
|
||||
v_shadow[cascade].xy *= shadowScale.xy;
|
||||
#endif
|
||||
v_shadow[cascade] = calculatePositionInShadowSpaceImpl(
|
||||
position, shadowTransforms[cascade], shadowScale);
|
||||
}
|
||||
#else
|
||||
|
||||
#endif
|
||||
#endif // USE_SHADOW
|
||||
}
|
||||
|
@ -1,19 +1,13 @@
|
||||
#version 110
|
||||
|
||||
#include "debug_overlay.h"
|
||||
|
||||
#include "common/fragment.h"
|
||||
|
||||
#if DEBUG_TEXTURED
|
||||
uniform sampler2D baseTex;
|
||||
|
||||
varying vec2 v_tex;
|
||||
#else
|
||||
uniform vec4 color;
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
#if DEBUG_TEXTURED
|
||||
OUTPUT_FRAGMENT_SINGLE_COLOR(texture2D(baseTex, v_tex));
|
||||
OUTPUT_FRAGMENT_SINGLE_COLOR(SAMPLE_2D(GET_DRAW_TEXTURE_2D(baseTex), v_tex));
|
||||
#else
|
||||
OUTPUT_FRAGMENT_SINGLE_COLOR(color);
|
||||
#endif
|
||||
|
22
binaries/data/mods/public/shaders/glsl/debug_overlay.h
Normal file
22
binaries/data/mods/public/shaders/glsl/debug_overlay.h
Normal file
@ -0,0 +1,22 @@
|
||||
#include "common/stage.h"
|
||||
|
||||
BEGIN_DRAW_TEXTURES
|
||||
#if DEBUG_TEXTURED
|
||||
TEXTURE_2D(0, baseTex)
|
||||
#else
|
||||
NO_DRAW_TEXTURES
|
||||
#endif
|
||||
END_DRAW_TEXTURES
|
||||
|
||||
BEGIN_DRAW_UNIFORMS
|
||||
UNIFORM(mat4, transform)
|
||||
#if DEBUG_TEXTURED
|
||||
UNIFORM(vec2, textureTransform)
|
||||
#else
|
||||
UNIFORM(vec4, color)
|
||||
#endif
|
||||
END_DRAW_UNIFORMS
|
||||
|
||||
#if DEBUG_TEXTURED
|
||||
VERTEX_OUTPUT(0, vec2, v_tex);
|
||||
#endif
|
@ -1,16 +1,9 @@
|
||||
#version 110
|
||||
|
||||
#include "debug_overlay.h"
|
||||
|
||||
#include "common/vertex.h"
|
||||
|
||||
uniform mat4 transform;
|
||||
#if DEBUG_TEXTURED
|
||||
uniform vec2 textureTransform;
|
||||
#endif
|
||||
|
||||
#if DEBUG_TEXTURED
|
||||
varying vec2 v_tex;
|
||||
#endif
|
||||
|
||||
VERTEX_INPUT_ATTRIBUTE(0, vec3, a_vertex);
|
||||
#if DEBUG_TEXTURED
|
||||
VERTEX_INPUT_ATTRIBUTE(1, vec3, a_uv0);
|
||||
|
@ -1,48 +1,49 @@
|
||||
#version 120
|
||||
|
||||
#include "common/fragment.h"
|
||||
#include "common/stage.h"
|
||||
|
||||
uniform sampler2D renderedTex;
|
||||
uniform sampler2D depthTex;
|
||||
uniform sampler2D blurTex2;
|
||||
uniform sampler2D blurTex4;
|
||||
uniform sampler2D blurTex8;
|
||||
BEGIN_DRAW_TEXTURES
|
||||
TEXTURE_2D(0, renderedTex)
|
||||
TEXTURE_2D(1, depthTex)
|
||||
TEXTURE_2D(2, blurTex2)
|
||||
TEXTURE_2D(3, blurTex4)
|
||||
TEXTURE_2D(4, blurTex8)
|
||||
END_DRAW_TEXTURES
|
||||
|
||||
uniform float width;
|
||||
uniform float height;
|
||||
|
||||
uniform float zNear;
|
||||
uniform float zFar;
|
||||
|
||||
uniform float brightness;
|
||||
uniform float hdr;
|
||||
uniform float saturation;
|
||||
uniform float bloom;
|
||||
|
||||
varying vec2 v_tex;
|
||||
BEGIN_DRAW_UNIFORMS
|
||||
UNIFORM(float, width)
|
||||
UNIFORM(float, height)
|
||||
UNIFORM(float, zNear)
|
||||
UNIFORM(float, zFar)
|
||||
UNIFORM(float, brightness)
|
||||
UNIFORM(float, hdr)
|
||||
UNIFORM(float, saturation)
|
||||
UNIFORM(float, bloom)
|
||||
END_DRAW_UNIFORMS
|
||||
|
||||
VERTEX_OUTPUT(0, vec2, v_tex);
|
||||
|
||||
float linearizeDepth(float depth)
|
||||
{
|
||||
return -zFar * zNear / (depth * (zFar - zNear) - zFar);
|
||||
}
|
||||
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec3 color = texture2D(renderedTex, v_tex).rgb;
|
||||
vec3 color = SAMPLE_2D(GET_DRAW_TEXTURE_2D(renderedTex), v_tex).rgb;
|
||||
|
||||
vec3 blur2 = texture2D(blurTex2, v_tex).rgb;
|
||||
vec3 blur4 = texture2D(blurTex4, v_tex).rgb;
|
||||
vec3 blur8 = texture2D(blurTex8, v_tex).rgb;
|
||||
vec3 blur2 = SAMPLE_2D(GET_DRAW_TEXTURE_2D(blurTex2), v_tex).rgb;
|
||||
vec3 blur4 = SAMPLE_2D(GET_DRAW_TEXTURE_2D(blurTex4), v_tex).rgb;
|
||||
vec3 blur8 = SAMPLE_2D(GET_DRAW_TEXTURE_2D(blurTex8), v_tex).rgb;
|
||||
|
||||
float depth = texture2D(depthTex, v_tex).r;
|
||||
float depth = SAMPLE_2D(GET_DRAW_TEXTURE_2D(depthTex), v_tex).r;
|
||||
|
||||
float midDepth = texture2D(depthTex, vec2(0.5, 0.5)).r;
|
||||
midDepth += texture2D(depthTex, vec2(0.4, 0.4)).r;
|
||||
midDepth += texture2D(depthTex, vec2(0.4, 0.6)).r;
|
||||
midDepth += texture2D(depthTex, vec2(0.6, 0.4)).r;
|
||||
midDepth += texture2D(depthTex, vec2(0.6, 0.6)).r;
|
||||
float midDepth = SAMPLE_2D(GET_DRAW_TEXTURE_2D(depthTex), vec2(0.5, 0.5)).r;
|
||||
midDepth += SAMPLE_2D(GET_DRAW_TEXTURE_2D(depthTex), vec2(0.4, 0.4)).r;
|
||||
midDepth += SAMPLE_2D(GET_DRAW_TEXTURE_2D(depthTex), vec2(0.4, 0.6)).r;
|
||||
midDepth += SAMPLE_2D(GET_DRAW_TEXTURE_2D(depthTex), vec2(0.6, 0.4)).r;
|
||||
midDepth += SAMPLE_2D(GET_DRAW_TEXTURE_2D(depthTex), vec2(0.6, 0.6)).r;
|
||||
|
||||
midDepth /= 5.0;
|
||||
|
||||
@ -60,5 +61,3 @@ void main(void)
|
||||
|
||||
OUTPUT_FRAGMENT_SINGLE_COLOR(vec4(color, 1.0));
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
#version 110
|
||||
|
||||
#include "common/fragment.h"
|
||||
#include "dummy.h"
|
||||
|
||||
uniform vec4 color;
|
||||
#include "common/fragment.h"
|
||||
|
||||
void main()
|
||||
{
|
||||
|
10
binaries/data/mods/public/shaders/glsl/dummy.h
Normal file
10
binaries/data/mods/public/shaders/glsl/dummy.h
Normal file
@ -0,0 +1,10 @@
|
||||
#include "common/stage.h"
|
||||
|
||||
BEGIN_DRAW_TEXTURES
|
||||
NO_DRAW_TEXTURES
|
||||
END_DRAW_TEXTURES
|
||||
|
||||
BEGIN_DRAW_UNIFORMS
|
||||
UNIFORM(mat4, transform)
|
||||
UNIFORM(vec4, color)
|
||||
END_DRAW_UNIFORMS
|
@ -1,11 +1,11 @@
|
||||
#version 110
|
||||
|
||||
#include "dummy.h"
|
||||
|
||||
#include "common/vertex.h"
|
||||
|
||||
VERTEX_INPUT_ATTRIBUTE(0, vec3, a_vertex);
|
||||
|
||||
uniform mat4 transform;
|
||||
|
||||
void main()
|
||||
{
|
||||
OUTPUT_VERTEX_POSITION(transform * vec4(a_vertex, 1.0));
|
||||
|
@ -1,12 +1,10 @@
|
||||
#version 110
|
||||
|
||||
#include "foreground_overlay.h"
|
||||
|
||||
#include "common/fragment.h"
|
||||
|
||||
uniform sampler2D baseTex;
|
||||
uniform vec4 colorMul;
|
||||
varying vec2 v_tex;
|
||||
|
||||
void main()
|
||||
{
|
||||
OUTPUT_FRAGMENT_SINGLE_COLOR(texture2D(baseTex, v_tex) * colorMul);
|
||||
OUTPUT_FRAGMENT_SINGLE_COLOR(SAMPLE_2D(GET_DRAW_TEXTURE_2D(baseTex), v_tex) * colorMul);
|
||||
}
|
||||
|
12
binaries/data/mods/public/shaders/glsl/foreground_overlay.h
Normal file
12
binaries/data/mods/public/shaders/glsl/foreground_overlay.h
Normal file
@ -0,0 +1,12 @@
|
||||
#include "common/stage.h"
|
||||
|
||||
BEGIN_DRAW_TEXTURES
|
||||
TEXTURE_2D(0, baseTex)
|
||||
END_DRAW_TEXTURES
|
||||
|
||||
BEGIN_DRAW_UNIFORMS
|
||||
UNIFORM(mat4, transform)
|
||||
UNIFORM(vec4, colorMul)
|
||||
END_DRAW_UNIFORMS
|
||||
|
||||
VERTEX_OUTPUT(0, vec2, v_tex);
|
@ -1,11 +1,9 @@
|
||||
#version 110
|
||||
|
||||
#include "foreground_overlay.h"
|
||||
|
||||
#include "common/vertex.h"
|
||||
|
||||
uniform mat4 transform;
|
||||
|
||||
varying vec2 v_tex;
|
||||
|
||||
VERTEX_INPUT_ATTRIBUTE(0, vec3, a_vertex);
|
||||
VERTEX_INPUT_ATTRIBUTE(1, vec2, a_uv0);
|
||||
|
||||
|
@ -1,30 +1,33 @@
|
||||
#version 120
|
||||
|
||||
#include "common/fragment.h"
|
||||
#include "common/stage.h"
|
||||
|
||||
uniform sampler2D renderedTex;
|
||||
uniform sampler2D depthTex;
|
||||
uniform sampler2D blurTex2;
|
||||
uniform sampler2D blurTex4;
|
||||
uniform sampler2D blurTex8;
|
||||
BEGIN_DRAW_TEXTURES
|
||||
TEXTURE_2D(0, renderedTex)
|
||||
TEXTURE_2D(1, depthTex)
|
||||
TEXTURE_2D(2, blurTex2)
|
||||
TEXTURE_2D(3, blurTex4)
|
||||
TEXTURE_2D(4, blurTex8)
|
||||
END_DRAW_TEXTURES
|
||||
|
||||
uniform float width;
|
||||
uniform float height;
|
||||
|
||||
uniform float brightness;
|
||||
uniform float hdr;
|
||||
uniform float saturation;
|
||||
uniform float bloom;
|
||||
|
||||
varying vec2 v_tex;
|
||||
BEGIN_DRAW_UNIFORMS
|
||||
UNIFORM(float, width)
|
||||
UNIFORM(float, height)
|
||||
UNIFORM(float, brightness)
|
||||
UNIFORM(float, hdr)
|
||||
UNIFORM(float, saturation)
|
||||
UNIFORM(float, bloom)
|
||||
END_DRAW_UNIFORMS
|
||||
|
||||
VERTEX_OUTPUT(0, vec2, v_tex);
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec3 color = texture2D(renderedTex, v_tex).rgb;
|
||||
vec3 bloomv2 = texture2D(blurTex2, v_tex).rgb;
|
||||
vec3 bloomv4 = texture2D(blurTex4, v_tex).rgb;
|
||||
vec3 bloomv8 = texture2D(blurTex8, v_tex).rgb;
|
||||
vec3 color = SAMPLE_2D(GET_DRAW_TEXTURE_2D(renderedTex), v_tex).rgb;
|
||||
vec3 bloomv2 = SAMPLE_2D(GET_DRAW_TEXTURE_2D(blurTex2), v_tex).rgb;
|
||||
vec3 bloomv4 = SAMPLE_2D(GET_DRAW_TEXTURE_2D(blurTex4), v_tex).rgb;
|
||||
vec3 bloomv8 = SAMPLE_2D(GET_DRAW_TEXTURE_2D(blurTex8), v_tex).rgb;
|
||||
|
||||
bloomv2 = max(bloomv2 - bloom, vec3(0.0));
|
||||
bloomv4 = max(bloomv4 - bloom, vec3(0.0));
|
||||
@ -46,5 +49,3 @@ void main(void)
|
||||
|
||||
OUTPUT_FRAGMENT_SINGLE_COLOR(vec4(color, 1.0));
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,18 +1,13 @@
|
||||
#version 110
|
||||
|
||||
#include "los_interp.h"
|
||||
|
||||
#include "common/fragment.h"
|
||||
|
||||
varying vec2 v_tex;
|
||||
|
||||
uniform sampler2D losTex1, losTex2;
|
||||
|
||||
uniform float delta;
|
||||
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec4 los2 = texture2D(losTex1, v_tex).rrrr;
|
||||
vec4 los1 = texture2D(losTex2, v_tex).rrrr;
|
||||
vec4 los2 = SAMPLE_2D(GET_DRAW_TEXTURE_2D(losTex1), v_tex).rrrr;
|
||||
vec4 los1 = SAMPLE_2D(GET_DRAW_TEXTURE_2D(losTex2), v_tex).rrrr;
|
||||
|
||||
OUTPUT_FRAGMENT_SINGLE_COLOR(mix(los1, los2, clamp(delta, 0.0, 1.0)));
|
||||
}
|
||||
|
14
binaries/data/mods/public/shaders/glsl/los_interp.h
Normal file
14
binaries/data/mods/public/shaders/glsl/los_interp.h
Normal file
@ -0,0 +1,14 @@
|
||||
#include "common/stage.h"
|
||||
|
||||
BEGIN_DRAW_TEXTURES
|
||||
TEXTURE_2D(0, losTex1)
|
||||
TEXTURE_2D(1, losTex2)
|
||||
END_DRAW_TEXTURES
|
||||
|
||||
BEGIN_DRAW_UNIFORMS
|
||||
UNIFORM(mat4, transform)
|
||||
UNIFORM(vec2, losTransform)
|
||||
UNIFORM(float, delta)
|
||||
END_DRAW_UNIFORMS
|
||||
|
||||
VERTEX_OUTPUT(0, vec2, v_tex);
|
@ -1,13 +1,9 @@
|
||||
#version 110
|
||||
|
||||
#include "los_interp.h"
|
||||
|
||||
#include "common/vertex.h"
|
||||
|
||||
uniform mat4 transform;
|
||||
uniform vec2 losTransform;
|
||||
|
||||
varying vec2 v_tex;
|
||||
varying vec2 v_los;
|
||||
|
||||
VERTEX_INPUT_ATTRIBUTE(0, vec3, a_vertex);
|
||||
VERTEX_INPUT_ATTRIBUTE(1, vec2, a_uv0);
|
||||
|
||||
|
@ -1,27 +1,17 @@
|
||||
#version 110
|
||||
|
||||
#include "minimap.h"
|
||||
|
||||
#include "common/fragment.h"
|
||||
|
||||
#if MINIMAP_BASE || MINIMAP_LOS
|
||||
uniform sampler2D baseTex;
|
||||
#endif
|
||||
|
||||
#if MINIMAP_BASE || MINIMAP_LOS
|
||||
varying vec2 v_tex;
|
||||
#endif
|
||||
|
||||
#if MINIMAP_POINT
|
||||
varying vec3 color;
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
#if MINIMAP_BASE
|
||||
OUTPUT_FRAGMENT_SINGLE_COLOR(texture2D(baseTex, v_tex));
|
||||
OUTPUT_FRAGMENT_SINGLE_COLOR(SAMPLE_2D(GET_DRAW_TEXTURE_2D(baseTex), v_tex));
|
||||
#endif
|
||||
|
||||
#if MINIMAP_LOS
|
||||
OUTPUT_FRAGMENT_SINGLE_COLOR(texture2D(baseTex, v_tex).rrrr);
|
||||
OUTPUT_FRAGMENT_SINGLE_COLOR(SAMPLE_2D(GET_DRAW_TEXTURE_2D(baseTex), v_tex).rrrr);
|
||||
#endif
|
||||
|
||||
#if MINIMAP_POINT
|
||||
|
26
binaries/data/mods/public/shaders/glsl/minimap.h
Normal file
26
binaries/data/mods/public/shaders/glsl/minimap.h
Normal file
@ -0,0 +1,26 @@
|
||||
#include "common/stage.h"
|
||||
|
||||
BEGIN_DRAW_TEXTURES
|
||||
#if MINIMAP_BASE || MINIMAP_LOS
|
||||
TEXTURE_2D(0, baseTex)
|
||||
#else
|
||||
NO_DRAW_TEXTURES
|
||||
#endif
|
||||
END_DRAW_TEXTURES
|
||||
|
||||
BEGIN_DRAW_UNIFORMS
|
||||
UNIFORM(vec4, transform)
|
||||
UNIFORM(vec4, translation)
|
||||
UNIFORM(vec4, textureTransform)
|
||||
#if MINIMAP_POINT && USE_GPU_INSTANCING
|
||||
UNIFORM(float, width)
|
||||
#endif
|
||||
END_DRAW_UNIFORMS
|
||||
|
||||
#if MINIMAP_BASE || MINIMAP_LOS
|
||||
VERTEX_OUTPUT(0, vec2, v_tex);
|
||||
#endif
|
||||
|
||||
#if MINIMAP_POINT
|
||||
VERTEX_OUTPUT(0, vec3, color);
|
||||
#endif
|
@ -1,20 +1,13 @@
|
||||
#version 110
|
||||
|
||||
#include "minimap.h"
|
||||
|
||||
#include "common/vertex.h"
|
||||
|
||||
uniform vec4 transform;
|
||||
uniform vec4 translation;
|
||||
uniform vec4 textureTransform;
|
||||
#if MINIMAP_POINT && USE_GPU_INSTANCING
|
||||
uniform float width;
|
||||
#endif
|
||||
|
||||
VERTEX_INPUT_ATTRIBUTE(0, vec2, a_vertex);
|
||||
|
||||
#if MINIMAP_BASE || MINIMAP_LOS
|
||||
VERTEX_INPUT_ATTRIBUTE(1, vec2, a_uv0);
|
||||
#endif
|
||||
|
||||
#if MINIMAP_POINT
|
||||
VERTEX_INPUT_ATTRIBUTE(1, vec3, a_color);
|
||||
#if USE_GPU_INSTANCING
|
||||
@ -22,14 +15,6 @@ VERTEX_INPUT_ATTRIBUTE(2, vec2, a_uv1);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if MINIMAP_BASE || MINIMAP_LOS
|
||||
varying vec2 v_tex;
|
||||
#endif
|
||||
|
||||
#if MINIMAP_POINT
|
||||
varying vec3 color;
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
#if MINIMAP_BASE || MINIMAP_LOS
|
||||
|
@ -1,59 +1,13 @@
|
||||
#version 120
|
||||
|
||||
#include "model_common.h"
|
||||
|
||||
#include "common/debug_fragment.h"
|
||||
#include "common/fog.h"
|
||||
#include "common/fragment.h"
|
||||
#include "common/los_fragment.h"
|
||||
#include "common/shadows_fragment.h"
|
||||
|
||||
uniform sampler2D baseTex;
|
||||
uniform sampler2D aoTex;
|
||||
uniform sampler2D normTex;
|
||||
uniform sampler2D specTex;
|
||||
|
||||
#if USE_OBJECTCOLOR
|
||||
uniform vec3 objectColor;
|
||||
#else
|
||||
#if USE_PLAYERCOLOR
|
||||
uniform vec3 playerColor;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
uniform vec3 shadingColor;
|
||||
uniform vec3 ambient;
|
||||
uniform vec3 sunColor;
|
||||
uniform vec3 sunDir;
|
||||
|
||||
varying vec4 v_lighting;
|
||||
varying vec2 v_tex;
|
||||
|
||||
#if (USE_INSTANCING || USE_GPU_SKINNING) && USE_AO
|
||||
varying vec2 v_tex2;
|
||||
#endif
|
||||
|
||||
#if USE_SPECULAR
|
||||
uniform float specularPower;
|
||||
uniform vec3 specularColor;
|
||||
#endif
|
||||
|
||||
#if USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_PARALLAX || USE_AO
|
||||
uniform vec4 effectSettings;
|
||||
#endif
|
||||
|
||||
#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_PARALLAX
|
||||
varying vec4 v_normal;
|
||||
#if (USE_INSTANCING || USE_GPU_SKINNING) && (USE_NORMAL_MAP || USE_PARALLAX)
|
||||
varying vec4 v_tangent;
|
||||
//varying vec3 v_bitangent;
|
||||
#endif
|
||||
#if USE_SPECULAR || USE_SPECULAR_MAP
|
||||
varying vec3 v_half;
|
||||
#endif
|
||||
#if (USE_INSTANCING || USE_GPU_SKINNING) && USE_PARALLAX
|
||||
varying vec3 v_eyeVec;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 coord = v_tex;
|
||||
@ -65,7 +19,7 @@ void main()
|
||||
|
||||
#if (USE_INSTANCING || USE_GPU_SKINNING) && USE_PARALLAX
|
||||
{
|
||||
float h = texture2D(normTex, coord).a;
|
||||
float h = SAMPLE_2D(GET_DRAW_TEXTURE_2D(normTex), coord).a;
|
||||
|
||||
vec3 eyeDir = normalize(v_eyeVec * tbn);
|
||||
float dist = length(v_eyeVec);
|
||||
@ -88,19 +42,19 @@ void main()
|
||||
t = (h < height) ? s : 0.0;
|
||||
vec2 temp = (h < height) ? move : nil;
|
||||
coord += temp;
|
||||
h = texture2D(normTex, coord).a;
|
||||
h = SAMPLE_2D(GET_DRAW_TEXTURE_2D(normTex), coord).a;
|
||||
}
|
||||
|
||||
// Move back to where we collided with the surface.
|
||||
// This assumes the surface is linear between the sample point before we
|
||||
// intersect the surface and after we intersect the surface
|
||||
float hp = texture2D(normTex, coord - move).a;
|
||||
float hp = SAMPLE_2D(GET_DRAW_TEXTURE_2D(normTex), coord - move).a;
|
||||
coord -= move * ((h - height) / (s + h - hp));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
vec4 tex = texture2D(baseTex, coord);
|
||||
vec4 tex = SAMPLE_2D(GET_DRAW_TEXTURE_2D(baseTex), coord);
|
||||
|
||||
// Alpha-test as early as possible
|
||||
#ifdef REQUIRE_ALPHA_GEQUAL
|
||||
@ -117,12 +71,10 @@ void main()
|
||||
vec3 texdiffuse = tex.rgb;
|
||||
|
||||
// Apply-coloring based on texture alpha
|
||||
#if USE_OBJECTCOLOR
|
||||
texdiffuse *= mix(objectColor, vec3(1.0, 1.0, 1.0), tex.a);
|
||||
#else
|
||||
#if USE_PLAYERCOLOR
|
||||
texdiffuse *= mix(playerColor, vec3(1.0, 1.0, 1.0), tex.a);
|
||||
#endif
|
||||
texdiffuse *= mix(playerColor.rgb, vec3(1.0, 1.0, 1.0), tex.a);
|
||||
#elif USE_OBJECTCOLOR
|
||||
texdiffuse *= mix(objectColor, vec3(1.0, 1.0, 1.0), tex.a);
|
||||
#endif
|
||||
|
||||
#if USE_SPECULAR || USE_SPECULAR_MAP || USE_NORMAL_MAP
|
||||
@ -130,7 +82,7 @@ void main()
|
||||
#endif
|
||||
|
||||
#if (USE_INSTANCING || USE_GPU_SKINNING) && USE_NORMAL_MAP
|
||||
vec3 ntex = texture2D(normTex, coord).rgb * 2.0 - 1.0;
|
||||
vec3 ntex = SAMPLE_2D(GET_DRAW_TEXTURE_2D(normTex), coord).rgb * 2.0 - 1.0;
|
||||
ntex.y = -ntex.y;
|
||||
normal = normalize(tbn * ntex);
|
||||
vec3 bumplight = max(dot(-sunDir, normal), 0.0) * sunColor;
|
||||
@ -144,7 +96,7 @@ void main()
|
||||
vec3 specCol;
|
||||
float specPow;
|
||||
#if USE_SPECULAR_MAP
|
||||
vec4 s = texture2D(specTex, coord);
|
||||
vec4 s = SAMPLE_2D(GET_DRAW_TEXTURE_2D(specTex), coord);
|
||||
specCol = s.rgb;
|
||||
specular.a = s.a;
|
||||
specPow = effectSettings.y;
|
||||
@ -156,7 +108,7 @@ void main()
|
||||
#endif
|
||||
|
||||
#if (USE_INSTANCING || USE_GPU_SKINNING) && USE_AO
|
||||
float ao = texture2D(aoTex, v_tex2).r;
|
||||
float ao = SAMPLE_2D(GET_DRAW_TEXTURE_2D(aoTex), v_tex2).r;
|
||||
#else
|
||||
float ao = 1.0;
|
||||
#endif
|
||||
@ -168,9 +120,11 @@ void main()
|
||||
color = mix(texdiffuse, color, specular.a);
|
||||
#endif
|
||||
|
||||
color = applyFog(color);
|
||||
color = applyFog(color, fogColor, fogParams);
|
||||
|
||||
color *= getLOS();
|
||||
#if !IGNORE_LOS
|
||||
color *= getLOS(GET_DRAW_TEXTURE_2D(losTex), v_los);
|
||||
#endif
|
||||
|
||||
color *= shadingColor;
|
||||
|
||||
|
83
binaries/data/mods/public/shaders/glsl/model_common.h
Normal file
83
binaries/data/mods/public/shaders/glsl/model_common.h
Normal file
@ -0,0 +1,83 @@
|
||||
#include "common/shadows.h"
|
||||
#include "common/stage.h"
|
||||
|
||||
#if USE_GPU_SKINNING
|
||||
const int MAX_INFLUENCES = 4;
|
||||
const int MAX_BONES = 64;
|
||||
#endif
|
||||
|
||||
BEGIN_DRAW_TEXTURES
|
||||
TEXTURE_2D(0, baseTex)
|
||||
TEXTURE_2D(1, aoTex)
|
||||
TEXTURE_2D(2, normTex)
|
||||
TEXTURE_2D(3, specTex)
|
||||
#if !IGNORE_LOS
|
||||
TEXTURE_2D(4, losTex)
|
||||
#endif
|
||||
#if USE_SHADOW
|
||||
SHADOWS_TEXTURES(5)
|
||||
#endif
|
||||
END_DRAW_TEXTURES
|
||||
|
||||
BEGIN_DRAW_UNIFORMS
|
||||
UNIFORM(mat4, instancingTransform)
|
||||
#if USE_PLAYERCOLOR
|
||||
UNIFORM(vec4, playerColor)
|
||||
#elif USE_OBJECTCOLOR
|
||||
UNIFORM(vec3, objectColor)
|
||||
#endif
|
||||
UNIFORM(vec3, shadingColor)
|
||||
END_DRAW_UNIFORMS
|
||||
|
||||
BEGIN_MATERIAL_UNIFORMS
|
||||
#if USE_SPECULAR
|
||||
UNIFORM(float, specularPower)
|
||||
UNIFORM(vec3, specularColor)
|
||||
#endif
|
||||
#if USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_PARALLAX || USE_AO
|
||||
UNIFORM(vec4, effectSettings)
|
||||
#endif
|
||||
UNIFORM(vec3, ambient)
|
||||
UNIFORM(vec3, sunColor)
|
||||
UNIFORM(vec3, sunDir)
|
||||
UNIFORM(mat4, transform)
|
||||
UNIFORM(vec3, cameraPos)
|
||||
#if USE_WIND
|
||||
UNIFORM(float, sim_time)
|
||||
UNIFORM(vec4, windData)
|
||||
#endif
|
||||
UNIFORM(vec3, fogColor)
|
||||
UNIFORM(vec2, fogParams)
|
||||
UNIFORM(vec2, losTransform)
|
||||
#if USE_SHADOW
|
||||
SHADOWS_UNIFORMS
|
||||
#endif
|
||||
#if USE_GPU_SKINNING
|
||||
UNIFORM(mat4, skinBlendMatrices[MAX_BONES]);
|
||||
#endif
|
||||
END_MATERIAL_UNIFORMS
|
||||
|
||||
VERTEX_OUTPUT(0, vec4, v_lighting);
|
||||
VERTEX_OUTPUT(1, vec2, v_tex);
|
||||
#if (USE_INSTANCING || USE_GPU_SKINNING) && USE_AO
|
||||
VERTEX_OUTPUT(2, vec2, v_tex2);
|
||||
#endif
|
||||
#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_PARALLAX
|
||||
VERTEX_OUTPUT(3, vec4, v_normal);
|
||||
#if (USE_INSTANCING || USE_GPU_SKINNING) && (USE_NORMAL_MAP || USE_PARALLAX)
|
||||
VERTEX_OUTPUT(4, vec4, v_tangent);
|
||||
//VERTEX_OUTPUT(5, vec3, v_bitangent);
|
||||
#endif
|
||||
#if USE_SPECULAR || USE_SPECULAR_MAP
|
||||
VERTEX_OUTPUT(6, vec3, v_half);
|
||||
#endif
|
||||
#if (USE_INSTANCING || USE_GPU_SKINNING) && USE_PARALLAX
|
||||
VERTEX_OUTPUT(7, vec3, v_eyeVec);
|
||||
#endif
|
||||
#endif
|
||||
#if !IGNORE_LOS
|
||||
VERTEX_OUTPUT(8, vec2, v_los);
|
||||
#endif
|
||||
#if USE_SHADOW
|
||||
SHADOWS_VERTEX_OUTPUTS(9)
|
||||
#endif
|
@ -1,70 +1,29 @@
|
||||
#version 120
|
||||
|
||||
#include "model_common.h"
|
||||
|
||||
#include "common/los_vertex.h"
|
||||
#include "common/shadows_vertex.h"
|
||||
#include "common/vertex.h"
|
||||
|
||||
uniform mat4 transform;
|
||||
uniform vec3 cameraPos;
|
||||
#ifdef GL_ES
|
||||
uniform mediump vec3 sunDir;
|
||||
uniform mediump vec3 sunColor;
|
||||
#else
|
||||
uniform vec3 sunDir;
|
||||
uniform vec3 sunColor;
|
||||
#endif
|
||||
uniform mat4 instancingTransform;
|
||||
|
||||
#if USE_WIND
|
||||
uniform float sim_time;
|
||||
uniform vec4 windData;
|
||||
#endif
|
||||
|
||||
varying vec4 v_lighting;
|
||||
varying vec2 v_tex;
|
||||
|
||||
#if (USE_INSTANCING || USE_GPU_SKINNING) && USE_AO
|
||||
varying vec2 v_tex2;
|
||||
#endif
|
||||
|
||||
#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_PARALLAX
|
||||
varying vec4 v_normal;
|
||||
#if (USE_INSTANCING || USE_GPU_SKINNING) && (USE_NORMAL_MAP || USE_PARALLAX)
|
||||
varying vec4 v_tangent;
|
||||
//varying vec3 v_bitangent;
|
||||
#endif
|
||||
#if USE_SPECULAR || USE_SPECULAR_MAP
|
||||
varying vec3 v_half;
|
||||
#endif
|
||||
#if (USE_INSTANCING || USE_GPU_SKINNING) && USE_PARALLAX
|
||||
varying vec3 v_eyeVec;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
VERTEX_INPUT_ATTRIBUTE(0, vec3, a_vertex);
|
||||
VERTEX_INPUT_ATTRIBUTE(1, vec3, a_normal);
|
||||
#if (USE_INSTANCING || USE_GPU_SKINNING)
|
||||
VERTEX_INPUT_ATTRIBUTE(2, vec4, a_tangent);
|
||||
VERTEX_INPUT_ATTRIBUTE(2, vec4, a_tangent);
|
||||
#endif
|
||||
VERTEX_INPUT_ATTRIBUTE(3, vec2, a_uv0);
|
||||
VERTEX_INPUT_ATTRIBUTE(4, vec2, a_uv1);
|
||||
|
||||
#if USE_GPU_SKINNING
|
||||
const int MAX_INFLUENCES = 4;
|
||||
const int MAX_BONES = 64;
|
||||
uniform mat4 skinBlendMatrices[MAX_BONES];
|
||||
VERTEX_INPUT_ATTRIBUTE(5, vec4, a_skinJoints);
|
||||
VERTEX_INPUT_ATTRIBUTE(6, vec4, a_skinWeights);
|
||||
VERTEX_INPUT_ATTRIBUTE(5, vec4, a_skinJoints);
|
||||
VERTEX_INPUT_ATTRIBUTE(6, vec4, a_skinWeights);
|
||||
#endif
|
||||
|
||||
|
||||
vec4 fakeCos(vec4 x)
|
||||
{
|
||||
vec4 tri = abs(fract(x + 0.5) * 2.0 - 1.0);
|
||||
return tri * tri *(3.0 - 2.0 * tri);
|
||||
}
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
#if USE_GPU_SKINNING
|
||||
@ -168,5 +127,7 @@ void main()
|
||||
|
||||
calculatePositionInShadowSpace(position);
|
||||
|
||||
calculateLOSCoordinates(position.xz);
|
||||
#if !IGNORE_LOS
|
||||
v_los = calculateLOSCoordinates(position.xz, losTransform);
|
||||
#endif
|
||||
}
|
||||
|
10
binaries/data/mods/public/shaders/glsl/model_solid.fs
Normal file
10
binaries/data/mods/public/shaders/glsl/model_solid.fs
Normal file
@ -0,0 +1,10 @@
|
||||
#version 110
|
||||
|
||||
#include "model_common.h"
|
||||
|
||||
#include "common/fragment.h"
|
||||
|
||||
void main()
|
||||
{
|
||||
OUTPUT_FRAGMENT_SINGLE_COLOR(vec4(0.0, 0.0, 0.0, 0.0));
|
||||
}
|
@ -3,10 +3,14 @@
|
||||
|
||||
<vertex file="glsl/model_common.vs">
|
||||
<stream name="pos" attribute="a_vertex"/>
|
||||
<stream name="normal" attribute="a_normal"/>
|
||||
<stream name="uv0" attribute="a_uv0"/>
|
||||
<stream name="uv1" attribute="a_uv1" if="USE_AO"/>
|
||||
<stream name="uv2" attribute="a_skinJoints" if="USE_GPU_SKINNING"/>
|
||||
<stream name="uv3" attribute="a_skinWeights" if="USE_GPU_SKINNING"/>
|
||||
<stream name="uv4" attribute="a_tangent" if="USE_INSTANCING || USE_GPU_SKINNING"/>
|
||||
</vertex>
|
||||
|
||||
<fragment file="glsl/solid.fs"/>
|
||||
<fragment file="glsl/model_solid.fs"/>
|
||||
|
||||
</program>
|
||||
|
@ -1,11 +1,11 @@
|
||||
#version 110
|
||||
|
||||
#include "model_common.h"
|
||||
|
||||
#include "common/fog.h"
|
||||
#include "common/fragment.h"
|
||||
|
||||
uniform vec4 playerColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
OUTPUT_FRAGMENT_SINGLE_COLOR(vec4(applyFog(playerColor.rgb), playerColor.a));
|
||||
OUTPUT_FRAGMENT_SINGLE_COLOR(vec4(applyFog(playerColor.rgb, fogColor, fogParams), playerColor.a));
|
||||
}
|
||||
|
@ -1,10 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<program type="glsl">
|
||||
<define name="USE_PLAYERCOLOR" value="1"/>
|
||||
|
||||
<vertex file="glsl/model_common.vs">
|
||||
<stream name="pos" attribute="a_vertex"/>
|
||||
<stream name="normal" attribute="a_normal"/>
|
||||
<stream name="uv0" attribute="a_uv0"/>
|
||||
<stream name="uv1" attribute="a_uv1" if="USE_AO"/>
|
||||
<stream name="uv2" attribute="a_skinJoints" if="USE_GPU_SKINNING"/>
|
||||
<stream name="uv3" attribute="a_skinWeights" if="USE_GPU_SKINNING"/>
|
||||
<stream name="uv4" attribute="a_tangent" if="USE_INSTANCING || USE_GPU_SKINNING"/>
|
||||
</vertex>
|
||||
|
||||
<fragment file="glsl/model_solid_player.fs"/>
|
||||
|
@ -1,14 +1,12 @@
|
||||
#version 110
|
||||
|
||||
#include "model_common.h"
|
||||
|
||||
#include "common/fragment.h"
|
||||
|
||||
uniform sampler2D baseTex;
|
||||
|
||||
varying vec2 v_tex;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 tex = texture2D(baseTex, v_tex);
|
||||
vec4 tex = SAMPLE_2D(GET_DRAW_TEXTURE_2D(baseTex), v_tex);
|
||||
|
||||
#ifdef REQUIRE_ALPHA_GEQUAL
|
||||
if (tex.a < REQUIRE_ALPHA_GEQUAL)
|
||||
|
@ -3,9 +3,12 @@
|
||||
|
||||
<vertex file="glsl/model_common.vs">
|
||||
<stream name="pos" attribute="a_vertex"/>
|
||||
<stream name="normal" attribute="a_normal"/>
|
||||
<stream name="uv0" attribute="a_uv0"/>
|
||||
<stream name="uv1" attribute="a_uv1" if="USE_AO"/>
|
||||
<stream name="uv2" attribute="a_skinJoints" if="USE_GPU_SKINNING"/>
|
||||
<stream name="uv3" attribute="a_skinWeights" if="USE_GPU_SKINNING"/>
|
||||
<stream name="uv4" attribute="a_tangent" if="USE_INSTANCING || USE_GPU_SKINNING"/>
|
||||
</vertex>
|
||||
|
||||
<fragment file="glsl/model_solid_tex.fs"/>
|
||||
|
@ -1,45 +1,15 @@
|
||||
#version 120
|
||||
|
||||
#include "model_water.h"
|
||||
|
||||
#include "common/debug_fragment.h"
|
||||
#include "common/fragment.h"
|
||||
#include "common/los_fragment.h"
|
||||
#include "common/shadows_fragment.h"
|
||||
|
||||
uniform sampler2D baseTex;
|
||||
uniform sampler2D aoTex;
|
||||
uniform sampler2D normTex;
|
||||
uniform sampler2D specTex;
|
||||
|
||||
uniform sampler2D waterTex;
|
||||
uniform samplerCube skyCube;
|
||||
|
||||
#if USE_OBJECTCOLOR
|
||||
uniform vec3 objectColor;
|
||||
#else
|
||||
#if USE_PLAYERCOLOR
|
||||
uniform vec3 playerColor;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
uniform vec3 shadingColor;
|
||||
uniform vec3 ambient;
|
||||
uniform vec3 sunColor;
|
||||
uniform vec3 sunDir;
|
||||
uniform vec3 cameraPos;
|
||||
|
||||
uniform float specularStrength;
|
||||
uniform float waviness;
|
||||
uniform vec3 waterTint;
|
||||
uniform float murkiness;
|
||||
uniform vec3 reflectionTint;
|
||||
uniform float reflectionTintStrength;
|
||||
|
||||
float waterDepth = 4.0;
|
||||
float fullDepth = 5.0; // Depth at which to use full murkiness (shallower water will be clearer)
|
||||
|
||||
varying vec4 worldPos;
|
||||
varying vec4 v_tex;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 n, l, h, v; // Normal, light vector, half-vector and view vector (vector to eye)
|
||||
@ -50,7 +20,7 @@ void main()
|
||||
vec3 reflColor, refrColor, specular;
|
||||
|
||||
//vec4 wtex = textureGrad(waterTex, vec3(fract(v_tex.xy), v_tex.z), dFdx(v_tex.xy), dFdy(v_tex.xy));
|
||||
vec4 wtex = texture2D(waterTex, fract(v_tex.xy));
|
||||
vec4 wtex = SAMPLE_2D(GET_DRAW_TEXTURE_2D(waterTex), fract(v_tex.xy));
|
||||
|
||||
n = normalize(wtex.xzy - vec3(0.5, 0.5, 0.5));
|
||||
l = -sunDir;
|
||||
@ -70,7 +40,7 @@ void main()
|
||||
|
||||
vec3 eye = reflect(v, n);
|
||||
|
||||
vec3 tex = textureCube(skyCube, eye).rgb;
|
||||
vec3 tex = SAMPLE_CUBE(GET_DRAW_TEXTURE_CUBE(skyCube), eye).rgb;
|
||||
|
||||
reflColor = mix(tex, sunColor * reflectionTint,
|
||||
reflectionTintStrength);
|
||||
@ -92,7 +62,9 @@ void main()
|
||||
#endif
|
||||
|
||||
vec3 color = mix(refrColor + 0.3*specular, reflColor + specular, fresShadow);
|
||||
color *= getLOS();
|
||||
#if !IGNORE_LOS
|
||||
color *= getLOS(GET_DRAW_TEXTURE_2D(losTex), v_los);
|
||||
#endif
|
||||
|
||||
// Make alpha vary based on both depth (so it blends with the shore) and view angle (make it
|
||||
// become opaque faster at lower view angles so we can't look "underneath" the water plane)
|
||||
|
53
binaries/data/mods/public/shaders/glsl/model_water.h
Normal file
53
binaries/data/mods/public/shaders/glsl/model_water.h
Normal file
@ -0,0 +1,53 @@
|
||||
#include "common/shadows.h"
|
||||
#include "common/stage.h"
|
||||
|
||||
BEGIN_DRAW_TEXTURES
|
||||
TEXTURE_2D(0, waterTex)
|
||||
TEXTURE_CUBE(1, skyCube)
|
||||
#if !IGNORE_LOS
|
||||
TEXTURE_2D(2, losTex)
|
||||
#endif
|
||||
#if USE_SHADOW
|
||||
SHADOWS_TEXTURES(3)
|
||||
#endif
|
||||
END_DRAW_TEXTURES
|
||||
|
||||
BEGIN_DRAW_UNIFORMS
|
||||
UNIFORM(mat4, instancingTransform)
|
||||
END_DRAW_UNIFORMS
|
||||
|
||||
BEGIN_MATERIAL_UNIFORMS
|
||||
UNIFORM(vec3, shadingColor)
|
||||
UNIFORM(vec3, ambient)
|
||||
|
||||
UNIFORM(float, specularStrength)
|
||||
UNIFORM(float, waviness)
|
||||
UNIFORM(vec3, waterTint)
|
||||
UNIFORM(float, murkiness)
|
||||
UNIFORM(vec3, reflectionTint)
|
||||
UNIFORM(float, reflectionTintStrength)
|
||||
|
||||
UNIFORM(mat4, transform)
|
||||
UNIFORM(vec3, cameraPos)
|
||||
UNIFORM(vec3, sunDir)
|
||||
UNIFORM(vec3, sunColor)
|
||||
|
||||
UNIFORM(float, sim_time)
|
||||
UNIFORM(vec2, translation)
|
||||
|
||||
UNIFORM(vec3, fogColor)
|
||||
UNIFORM(vec2, fogParams)
|
||||
UNIFORM(vec2, losTransform)
|
||||
#if USE_SHADOW
|
||||
SHADOWS_UNIFORMS
|
||||
#endif
|
||||
END_MATERIAL_UNIFORMS
|
||||
|
||||
VERTEX_OUTPUT(0, vec4, worldPos);
|
||||
VERTEX_OUTPUT(1, vec4, v_tex);
|
||||
#if !IGNORE_LOS
|
||||
VERTEX_OUTPUT(2, vec2, v_los);
|
||||
#endif
|
||||
#if USE_SHADOW
|
||||
SHADOWS_VERTEX_OUTPUTS(3)
|
||||
#endif
|
@ -1,25 +1,13 @@
|
||||
#version 120
|
||||
|
||||
#include "model_water.h"
|
||||
|
||||
#include "common/los_vertex.h"
|
||||
#include "common/shadows_vertex.h"
|
||||
#include "common/vertex.h"
|
||||
|
||||
uniform mat4 transform;
|
||||
uniform vec3 cameraPos;
|
||||
uniform vec3 sunDir;
|
||||
uniform vec3 sunColor;
|
||||
uniform mat4 instancingTransform;
|
||||
|
||||
uniform float sim_time;
|
||||
uniform vec2 translation;
|
||||
|
||||
VERTEX_INPUT_ATTRIBUTE(0, vec3, a_vertex);
|
||||
VERTEX_INPUT_ATTRIBUTE(1, vec3, a_normal);
|
||||
VERTEX_INPUT_ATTRIBUTE(2, vec2, a_uv0);
|
||||
VERTEX_INPUT_ATTRIBUTE(3, vec2, a_uv1);
|
||||
|
||||
varying vec4 worldPos;
|
||||
varying vec4 v_tex;
|
||||
|
||||
vec4 fakeCos(vec4 x)
|
||||
{
|
||||
@ -37,7 +25,9 @@ void main()
|
||||
|
||||
calculatePositionInShadowSpace(worldPos);
|
||||
|
||||
calculateLOSCoordinates(worldPos.xz);
|
||||
#if !IGNORE_LOS
|
||||
v_los = calculateLOSCoordinates(worldPos.xz, losTransform);
|
||||
#endif
|
||||
|
||||
OUTPUT_VERTEX_POSITION(transform * worldPos);
|
||||
}
|
||||
|
@ -3,9 +3,7 @@
|
||||
|
||||
<vertex file="glsl/model_water.vs">
|
||||
<stream name="pos" attribute="a_vertex"/>
|
||||
<stream name="normal" attribute="a_normal"/>
|
||||
<stream name="uv0" attribute="a_uv0"/>
|
||||
<stream name="uv1" attribute="a_uv1" if="USE_AO"/>
|
||||
</vertex>
|
||||
|
||||
<fragment file="glsl/model_water.fs"/>
|
||||
|
@ -1,31 +1,16 @@
|
||||
#version 120
|
||||
|
||||
#include "model_waterfall.h"
|
||||
|
||||
#include "common/debug_fragment.h"
|
||||
#include "common/fragment.h"
|
||||
#include "common/los_fragment.h"
|
||||
#include "common/shadows_fragment.h"
|
||||
|
||||
uniform sampler2D baseTex;
|
||||
|
||||
uniform vec3 shadingColor;
|
||||
uniform vec3 ambient;
|
||||
uniform vec3 sunColor;
|
||||
uniform vec3 sunDir;
|
||||
uniform vec3 cameraPos;
|
||||
|
||||
uniform float specularPower;
|
||||
uniform vec3 specularColor;
|
||||
|
||||
varying vec4 v_tex;
|
||||
varying vec3 v_half;
|
||||
varying vec3 v_normal;
|
||||
varying float v_transp;
|
||||
varying vec3 v_lighting;
|
||||
|
||||
void main()
|
||||
{
|
||||
//vec4 texdiffuse = textureGrad(baseTex, vec3(fract(v_tex.xy), v_tex.z), dFdx(v_tex.xy), dFdy(v_tex.xy));
|
||||
vec4 texdiffuse = texture2D(baseTex, fract(v_tex.xy));
|
||||
vec4 texdiffuse = SAMPLE_2D(GET_DRAW_TEXTURE_2D(baseTex), fract(v_tex.xy));
|
||||
|
||||
if (texdiffuse.a < 0.25)
|
||||
discard;
|
||||
@ -37,7 +22,9 @@ void main()
|
||||
vec3 color = (texdiffuse.rgb * v_lighting + specular) * getShadowOnLandscape();
|
||||
color += texdiffuse.rgb * ambient;
|
||||
|
||||
color *= getLOS();
|
||||
#if !IGNORE_LOS
|
||||
color *= getLOS(GET_DRAW_TEXTURE_2D(losTex), v_los);
|
||||
#endif
|
||||
|
||||
OUTPUT_FRAGMENT_SINGLE_COLOR(vec4(applyDebugColor(color, 1.0, texdiffuse.a, 0.0), texdiffuse.a));
|
||||
}
|
||||
|
51
binaries/data/mods/public/shaders/glsl/model_waterfall.h
Normal file
51
binaries/data/mods/public/shaders/glsl/model_waterfall.h
Normal file
@ -0,0 +1,51 @@
|
||||
#include "common/shadows.h"
|
||||
#include "common/stage.h"
|
||||
|
||||
BEGIN_DRAW_TEXTURES
|
||||
TEXTURE_2D(0, baseTex)
|
||||
#if !IGNORE_LOS
|
||||
TEXTURE_2D(1, losTex)
|
||||
#endif
|
||||
#if USE_SHADOW
|
||||
SHADOWS_TEXTURES(2)
|
||||
#endif
|
||||
END_DRAW_TEXTURES
|
||||
|
||||
BEGIN_DRAW_UNIFORMS
|
||||
UNIFORM(mat4, instancingTransform)
|
||||
END_DRAW_UNIFORMS
|
||||
|
||||
BEGIN_MATERIAL_UNIFORMS
|
||||
UNIFORM(vec3, shadingColor)
|
||||
UNIFORM(vec3, ambient)
|
||||
|
||||
UNIFORM(float, specularPower)
|
||||
UNIFORM(vec3, specularColor)
|
||||
|
||||
UNIFORM(mat4, transform)
|
||||
UNIFORM(vec3, cameraPos)
|
||||
UNIFORM(vec3, sunDir)
|
||||
UNIFORM(vec3, sunColor)
|
||||
|
||||
UNIFORM(float, sim_time)
|
||||
UNIFORM(vec2, translation)
|
||||
|
||||
UNIFORM(vec3, fogColor)
|
||||
UNIFORM(vec2, fogParams)
|
||||
UNIFORM(vec2, losTransform)
|
||||
#if USE_SHADOW
|
||||
SHADOWS_UNIFORMS
|
||||
#endif
|
||||
END_MATERIAL_UNIFORMS
|
||||
|
||||
VERTEX_OUTPUT(0, vec4, v_tex);
|
||||
VERTEX_OUTPUT(1, vec3, v_half);
|
||||
VERTEX_OUTPUT(2, vec3, v_normal);
|
||||
VERTEX_OUTPUT(3, float, v_transp);
|
||||
VERTEX_OUTPUT(4, vec3, v_lighting);
|
||||
#if !IGNORE_LOS
|
||||
VERTEX_OUTPUT(5, vec2, v_los);
|
||||
#endif
|
||||
#if USE_SHADOW
|
||||
SHADOWS_VERTEX_OUTPUTS(6)
|
||||
#endif
|
@ -1,40 +1,28 @@
|
||||
#version 120
|
||||
|
||||
#include "model_waterfall.h"
|
||||
|
||||
#include "common/los_vertex.h"
|
||||
#include "common/shadows_vertex.h"
|
||||
#include "common/vertex.h"
|
||||
|
||||
uniform mat4 transform;
|
||||
uniform vec3 cameraPos;
|
||||
uniform vec3 sunDir;
|
||||
uniform vec3 sunColor;
|
||||
uniform mat4 instancingTransform;
|
||||
|
||||
uniform float sim_time;
|
||||
uniform vec2 translation;
|
||||
|
||||
VERTEX_INPUT_ATTRIBUTE(0, vec3, a_vertex);
|
||||
VERTEX_INPUT_ATTRIBUTE(1, vec3, a_normal);
|
||||
VERTEX_INPUT_ATTRIBUTE(2, vec2, a_uv0);
|
||||
VERTEX_INPUT_ATTRIBUTE(3, vec2, a_uv1);
|
||||
|
||||
varying vec4 worldPos;
|
||||
varying vec4 v_tex;
|
||||
varying vec3 v_half;
|
||||
varying vec3 v_normal;
|
||||
varying float v_transp;
|
||||
varying vec3 v_lighting;
|
||||
|
||||
void main()
|
||||
{
|
||||
worldPos = instancingTransform * vec4(a_vertex, 1.0);
|
||||
vec4 worldPos = instancingTransform * vec4(a_vertex, 1.0);
|
||||
|
||||
v_tex.xy = a_uv0 + sim_time * translation;
|
||||
v_transp = a_uv1.x;
|
||||
|
||||
calculatePositionInShadowSpace(worldPos);
|
||||
|
||||
calculateLOSCoordinates(worldPos.xz);
|
||||
#if !IGNORE_LOS
|
||||
v_los = calculateLOSCoordinates(worldPos.xz, losTransform);
|
||||
#endif
|
||||
|
||||
vec3 eyeVec = cameraPos.xyz - worldPos.xyz;
|
||||
vec3 sunVec = -sunDir;
|
||||
|
@ -1,8 +1,8 @@
|
||||
#version 120
|
||||
|
||||
#include "common/fragment.h"
|
||||
#include "overlay_solid.h"
|
||||
|
||||
uniform vec4 color;
|
||||
#include "common/fragment.h"
|
||||
|
||||
void main()
|
||||
{
|
||||
|
15
binaries/data/mods/public/shaders/glsl/overlay_solid.h
Normal file
15
binaries/data/mods/public/shaders/glsl/overlay_solid.h
Normal file
@ -0,0 +1,15 @@
|
||||
#include "common/stage.h"
|
||||
|
||||
BEGIN_DRAW_TEXTURES
|
||||
NO_DRAW_TEXTURES
|
||||
END_DRAW_TEXTURES
|
||||
|
||||
BEGIN_DRAW_UNIFORMS
|
||||
UNIFORM(mat4, transform)
|
||||
UNIFORM(vec4, instancingTransform)
|
||||
UNIFORM(vec4, color)
|
||||
END_DRAW_UNIFORMS
|
||||
|
||||
uniform mat4 transform;
|
||||
uniform vec4 instancingTransform;
|
||||
uniform vec4 color;
|
@ -1,9 +1,8 @@
|
||||
#version 120
|
||||
|
||||
#include "common/vertex.h"
|
||||
#include "overlay_solid.h"
|
||||
|
||||
uniform mat4 transform;
|
||||
uniform vec4 instancingTransform;
|
||||
#include "common/vertex.h"
|
||||
|
||||
VERTEX_INPUT_ATTRIBUTE(0, vec3, a_vertex);
|
||||
|
||||
|
@ -1,20 +1,11 @@
|
||||
#version 120
|
||||
|
||||
#include "overlayline.h"
|
||||
|
||||
#include "common/debug_fragment.h"
|
||||
#include "common/fragment.h"
|
||||
#include "common/los_fragment.h"
|
||||
|
||||
uniform sampler2D baseTex;
|
||||
uniform sampler2D maskTex;
|
||||
|
||||
#if USE_OBJECTCOLOR
|
||||
uniform vec4 objectColor;
|
||||
#else
|
||||
varying vec4 v_color;
|
||||
#endif
|
||||
|
||||
varying vec2 v_tex;
|
||||
|
||||
void main()
|
||||
{
|
||||
#if USE_OBJECTCOLOR
|
||||
@ -25,11 +16,13 @@ void main()
|
||||
float alpha = v_color.a;
|
||||
#endif
|
||||
|
||||
vec4 base = texture2D(baseTex, v_tex);
|
||||
vec4 mask = texture2D(maskTex, v_tex);
|
||||
vec4 base = SAMPLE_2D(GET_DRAW_TEXTURE_2D(baseTex), v_tex);
|
||||
vec4 mask = SAMPLE_2D(GET_DRAW_TEXTURE_2D(maskTex), v_tex);
|
||||
color = mix(base.rgb, color, mask.r);
|
||||
|
||||
color *= getLOS();
|
||||
#if !IGNORE_LOS
|
||||
color *= getLOS(GET_DRAW_TEXTURE_2D(losTex), v_los);
|
||||
#endif
|
||||
|
||||
OUTPUT_FRAGMENT_SINGLE_COLOR(vec4(applyDebugColor(color, 1.0, alpha * base.a, 0.0), alpha * base.a));
|
||||
}
|
||||
|
25
binaries/data/mods/public/shaders/glsl/overlayline.h
Normal file
25
binaries/data/mods/public/shaders/glsl/overlayline.h
Normal file
@ -0,0 +1,25 @@
|
||||
#include "common/stage.h"
|
||||
|
||||
BEGIN_DRAW_TEXTURES
|
||||
TEXTURE_2D(0, baseTex)
|
||||
TEXTURE_2D(1, maskTex)
|
||||
#if !IGNORE_LOS
|
||||
TEXTURE_2D(2, losTex)
|
||||
#endif
|
||||
END_DRAW_TEXTURES
|
||||
|
||||
BEGIN_DRAW_UNIFORMS
|
||||
UNIFORM(mat4, transform)
|
||||
#if USE_OBJECTCOLOR
|
||||
UNIFORM(vec4, objectColor)
|
||||
#endif
|
||||
UNIFORM(vec2, losTransform)
|
||||
END_DRAW_UNIFORMS
|
||||
|
||||
VERTEX_OUTPUT(0, vec2, v_tex);
|
||||
#if !USE_OBJECTCOLOR
|
||||
VERTEX_OUTPUT(1, vec4, v_color);
|
||||
#endif
|
||||
#if !IGNORE_LOS
|
||||
VERTEX_OUTPUT(2, vec2, v_los);
|
||||
#endif
|
@ -1,24 +1,22 @@
|
||||
#version 120
|
||||
|
||||
#include "overlayline.h"
|
||||
|
||||
#include "common/los_vertex.h"
|
||||
#include "common/vertex.h"
|
||||
|
||||
uniform mat4 transform;
|
||||
|
||||
VERTEX_INPUT_ATTRIBUTE(0, vec3, a_vertex);
|
||||
VERTEX_INPUT_ATTRIBUTE(1, vec2, a_uv0);
|
||||
|
||||
#if !USE_OBJECTCOLOR
|
||||
VERTEX_INPUT_ATTRIBUTE(2, vec4, a_color);
|
||||
varying vec4 v_color;
|
||||
#endif
|
||||
|
||||
varying vec2 v_tex;
|
||||
|
||||
void main()
|
||||
{
|
||||
v_tex = a_uv0;
|
||||
calculateLOSCoordinates(a_vertex.xz);
|
||||
#if !IGNORE_LOS
|
||||
v_los = calculateLOSCoordinates(a_vertex.xz, losTransform);
|
||||
#endif
|
||||
#if !USE_OBJECTCOLOR
|
||||
v_color = a_color;
|
||||
#endif
|
||||
|
@ -1,22 +1,19 @@
|
||||
#version 110
|
||||
|
||||
#include "particle.h"
|
||||
|
||||
#include "common/fog.h"
|
||||
#include "common/fragment.h"
|
||||
#include "common/los_fragment.h"
|
||||
|
||||
uniform sampler2D baseTex;
|
||||
|
||||
varying vec2 v_tex;
|
||||
varying vec4 v_color;
|
||||
|
||||
uniform vec3 sunColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color = texture2D(baseTex, v_tex) * vec4((v_color.rgb + sunColor)/2.0,v_color.a);
|
||||
vec4 color = SAMPLE_2D(GET_DRAW_TEXTURE_2D(baseTex), v_tex) * vec4((v_color.rgb + sunColor) / 2.0, v_color.a);
|
||||
|
||||
color.rgb = applyFog(color.rgb);
|
||||
color.rgb *= getLOS();
|
||||
color.rgb = applyFog(color.rgb, fogColor, fogParams);
|
||||
#if !IGNORE_LOS
|
||||
color.rgb *= getLOS(GET_DRAW_TEXTURE_2D(losTex), v_los);
|
||||
#endif
|
||||
|
||||
OUTPUT_FRAGMENT_SINGLE_COLOR(color);
|
||||
}
|
||||
|
27
binaries/data/mods/public/shaders/glsl/particle.h
Normal file
27
binaries/data/mods/public/shaders/glsl/particle.h
Normal file
@ -0,0 +1,27 @@
|
||||
#include "common/stage.h"
|
||||
|
||||
BEGIN_DRAW_TEXTURES
|
||||
TEXTURE_2D(0, baseTex)
|
||||
#if !IGNORE_LOS
|
||||
TEXTURE_2D(1, losTex)
|
||||
#endif
|
||||
END_DRAW_TEXTURES
|
||||
|
||||
BEGIN_DRAW_UNIFORMS
|
||||
UNIFORM(mat4, modelViewMatrix)
|
||||
END_DRAW_UNIFORMS
|
||||
|
||||
BEGIN_MATERIAL_UNIFORMS
|
||||
UNIFORM(mat4, transform)
|
||||
UNIFORM(vec3, sunColor)
|
||||
UNIFORM(vec3, fogColor)
|
||||
UNIFORM(vec2, fogParams)
|
||||
UNIFORM(vec2, losTransform)
|
||||
END_MATERIAL_UNIFORMS
|
||||
|
||||
VERTEX_OUTPUT(0, vec2, v_tex);
|
||||
VERTEX_OUTPUT(1, vec4, v_color);
|
||||
|
||||
#if !IGNORE_LOS
|
||||
VERTEX_OUTPUT(2, vec2, v_los);
|
||||
#endif
|
@ -1,14 +1,10 @@
|
||||
#version 110
|
||||
|
||||
#include "particle.h"
|
||||
|
||||
#include "common/los_vertex.h"
|
||||
#include "common/vertex.h"
|
||||
|
||||
uniform mat4 transform;
|
||||
uniform mat4 modelViewMatrix;
|
||||
|
||||
varying vec2 v_tex;
|
||||
varying vec4 v_color;
|
||||
|
||||
VERTEX_INPUT_ATTRIBUTE(0, vec3, a_vertex);
|
||||
VERTEX_INPUT_ATTRIBUTE(1, vec4, a_color);
|
||||
VERTEX_INPUT_ATTRIBUTE(2, vec2, a_uv0);
|
||||
@ -24,8 +20,9 @@ void main()
|
||||
|
||||
OUTPUT_VERTEX_POSITION(transform * vec4(position, 1.0));
|
||||
|
||||
calculateLOSCoordinates(position.xz);
|
||||
|
||||
v_tex = a_uv0;
|
||||
v_color = a_color;
|
||||
#if !IGNORE_LOS
|
||||
v_los = calculateLOSCoordinates(position.xz, losTransform);
|
||||
#endif
|
||||
}
|
||||
|
@ -1,13 +1,12 @@
|
||||
#version 110
|
||||
|
||||
#include "sky.h"
|
||||
|
||||
#include "common/fragment.h"
|
||||
|
||||
uniform samplerCube baseTex;
|
||||
varying vec3 v_tex;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 tex = textureCube(baseTex, v_tex);
|
||||
vec4 tex = SAMPLE_CUBE(GET_DRAW_TEXTURE_CUBE(baseTex), v_tex);
|
||||
|
||||
float m = (1.0 - v_tex.y) - 0.75;
|
||||
m *= 4.0;
|
||||
|
11
binaries/data/mods/public/shaders/glsl/sky.h
Normal file
11
binaries/data/mods/public/shaders/glsl/sky.h
Normal file
@ -0,0 +1,11 @@
|
||||
#include "common/stage.h"
|
||||
|
||||
BEGIN_DRAW_TEXTURES
|
||||
TEXTURE_CUBE(0, baseTex)
|
||||
END_DRAW_TEXTURES
|
||||
|
||||
BEGIN_DRAW_UNIFORMS
|
||||
UNIFORM(mat4, transform)
|
||||
END_DRAW_UNIFORMS
|
||||
|
||||
VERTEX_OUTPUT(0, vec3, v_tex);
|
@ -1,14 +1,12 @@
|
||||
#version 110
|
||||
|
||||
#include "sky.h"
|
||||
|
||||
#include "common/vertex.h"
|
||||
|
||||
varying vec3 v_tex;
|
||||
|
||||
VERTEX_INPUT_ATTRIBUTE(0, vec3, a_vertex);
|
||||
VERTEX_INPUT_ATTRIBUTE(1, vec3, a_uv0);
|
||||
|
||||
uniform mat4 transform;
|
||||
|
||||
void main()
|
||||
{
|
||||
OUTPUT_VERTEX_POSITION(transform * vec4(a_vertex, 1.0));
|
||||
|
@ -1,8 +1,8 @@
|
||||
#version 110
|
||||
|
||||
#include "common/fragment.h"
|
||||
#include "solid.h"
|
||||
|
||||
uniform vec4 color;
|
||||
#include "common/fragment.h"
|
||||
|
||||
void main()
|
||||
{
|
||||
|
10
binaries/data/mods/public/shaders/glsl/solid.h
Normal file
10
binaries/data/mods/public/shaders/glsl/solid.h
Normal file
@ -0,0 +1,10 @@
|
||||
#include "common/stage.h"
|
||||
|
||||
BEGIN_DRAW_TEXTURES
|
||||
NO_DRAW_TEXTURES
|
||||
END_DRAW_TEXTURES
|
||||
|
||||
BEGIN_DRAW_UNIFORMS
|
||||
UNIFORM(mat4, transform)
|
||||
UNIFORM(vec4, color)
|
||||
END_DRAW_UNIFORMS
|
@ -1,8 +1,8 @@
|
||||
#version 110
|
||||
|
||||
#include "common/vertex.h"
|
||||
#include "solid.h"
|
||||
|
||||
uniform mat4 transform;
|
||||
#include "common/vertex.h"
|
||||
|
||||
VERTEX_INPUT_ATTRIBUTE(0, vec3, a_vertex);
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
<vertex file="glsl/terrain_common.vs">
|
||||
<stream name="pos" attribute="a_vertex"/>
|
||||
<stream name="normal" attribute="a_normal"/>
|
||||
<stream name="uv0" attribute="a_uv0"/>
|
||||
<stream name="uv0" attribute="a_uv0" if="DECAL"/>
|
||||
<stream name="uv1" attribute="a_uv1" if="BLEND"/>
|
||||
</vertex>
|
||||
|
||||
|
@ -1,56 +1,15 @@
|
||||
#version 120
|
||||
|
||||
#include "terrain_common.h"
|
||||
|
||||
#include "common/debug_fragment.h"
|
||||
#include "common/fog.h"
|
||||
#include "common/fragment.h"
|
||||
#include "common/los_fragment.h"
|
||||
#include "common/shadows_fragment.h"
|
||||
|
||||
uniform sampler2D baseTex;
|
||||
uniform sampler2D blendTex;
|
||||
uniform sampler2D normTex;
|
||||
uniform sampler2D specTex;
|
||||
|
||||
uniform vec3 shadingColor;
|
||||
uniform vec3 ambient;
|
||||
uniform vec3 sunColor;
|
||||
uniform vec3 sunDir;
|
||||
|
||||
uniform vec2 textureTransform;
|
||||
|
||||
varying vec3 v_lighting;
|
||||
|
||||
varying vec2 v_blend;
|
||||
|
||||
#if USE_TRIPLANAR
|
||||
varying vec3 v_tex;
|
||||
#else
|
||||
varying vec2 v_tex;
|
||||
#endif
|
||||
|
||||
#if USE_SPECULAR
|
||||
uniform float specularPower;
|
||||
uniform vec3 specularColor;
|
||||
#endif
|
||||
|
||||
#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_AO
|
||||
uniform vec4 effectSettings;
|
||||
#endif
|
||||
|
||||
varying vec3 v_normal;
|
||||
|
||||
#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP
|
||||
#if USE_NORMAL_MAP
|
||||
varying vec4 v_tangent;
|
||||
varying vec3 v_bitangent;
|
||||
#endif
|
||||
#if USE_SPECULAR || USE_SPECULAR_MAP
|
||||
varying vec3 v_half;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if USE_TRIPLANAR
|
||||
vec4 triplanar(sampler2D sampler, vec3 wpos)
|
||||
vec4 triplanar(sampler2D tex, vec3 wpos)
|
||||
{
|
||||
float tighten = 0.4679;
|
||||
|
||||
@ -64,16 +23,16 @@ vec4 triplanar(sampler2D sampler, vec3 wpos)
|
||||
vec3 coords = wpos;
|
||||
coords.xyz /= 32.0; // Ugh.
|
||||
|
||||
vec4 col1 = texture2D(sampler, coords.yz);
|
||||
vec4 col2 = texture2D(sampler, coords.zx);
|
||||
vec4 col3 = texture2D(sampler, coords.yx);
|
||||
vec4 col1 = SAMPLE_2D(tex, coords.yz);
|
||||
vec4 col2 = SAMPLE_2D(tex, coords.zx);
|
||||
vec4 col3 = SAMPLE_2D(tex, coords.yx);
|
||||
|
||||
vec4 colBlended = col1 * blending.x + col2 * blending.y + col3 * blending.z;
|
||||
|
||||
return colBlended;
|
||||
}
|
||||
|
||||
vec4 triplanarNormals(sampler2D sampler, vec3 wpos)
|
||||
vec4 triplanarNormals(sampler2D tex, vec3 wpos)
|
||||
{
|
||||
float tighten = 0.4679;
|
||||
|
||||
@ -87,11 +46,11 @@ vec4 triplanarNormals(sampler2D sampler, vec3 wpos)
|
||||
vec3 coords = wpos;
|
||||
coords.xyz /= 32.0; // Ugh.
|
||||
|
||||
vec4 col1 = texture2D(sampler, coords.yz).xyzw;
|
||||
vec4 col1 = SAMPLE_2D(tex, coords.yz).xyzw;
|
||||
col1.y = 1.0 - col1.y;
|
||||
vec4 col2 = texture2D(sampler, coords.zx).yxzw;
|
||||
vec4 col2 = SAMPLE_2D(tex, coords.zx).yxzw;
|
||||
col2.y = 1.0 - col2.y;
|
||||
vec4 col3 = texture2D(sampler, coords.yx).yxzw;
|
||||
vec4 col3 = SAMPLE_2D(tex, coords.yx).yxzw;
|
||||
col3.y = 1.0 - col3.y;
|
||||
|
||||
vec4 colBlended = col1 * blending.x + col2 * blending.y + col3 * blending.z;
|
||||
@ -106,15 +65,15 @@ void main()
|
||||
|
||||
#if BLEND
|
||||
// Use alpha from blend texture
|
||||
alpha = 1.0 - texture2D(blendTex, v_blend).a;
|
||||
alpha = 1.0 - SAMPLE_2D(GET_DRAW_TEXTURE_2D(blendTex), v_blend).a;
|
||||
#else
|
||||
alpha = 1.0;
|
||||
#endif
|
||||
|
||||
#if USE_TRIPLANAR
|
||||
vec4 tex = triplanar(baseTex, v_tex);
|
||||
vec4 tex = triplanar(GET_DRAW_TEXTURE_2D(baseTex), v_tex);
|
||||
#else
|
||||
vec4 tex = texture2D(baseTex, v_tex.xy);
|
||||
vec4 tex = SAMPLE_2D(GET_DRAW_TEXTURE_2D(baseTex), v_tex.xy);
|
||||
#endif
|
||||
|
||||
#if DECAL
|
||||
@ -132,9 +91,9 @@ void main()
|
||||
float sign = v_tangent.w;
|
||||
mat3 tbn = mat3(v_tangent.xyz, v_bitangent * -sign, v_normal);
|
||||
#if USE_TRIPLANAR
|
||||
vec3 ntex = triplanarNormals(normTex, v_tex).rgb * 2.0 - 1.0;
|
||||
vec3 ntex = triplanarNormals(GET_DRAW_TEXTURE_2D(normTex), v_tex).rgb * 2.0 - 1.0;
|
||||
#else
|
||||
vec3 ntex = texture2D(normTex, v_tex).rgb * 2.0 - 1.0;
|
||||
vec3 ntex = SAMPLE_2D(GET_DRAW_TEXTURE_2D(normTex), v_tex).rgb * 2.0 - 1.0;
|
||||
#endif
|
||||
normal = normalize(tbn * ntex);
|
||||
vec3 bumplight = max(dot(-sunDir, normal), 0.0) * sunColor;
|
||||
@ -149,9 +108,9 @@ void main()
|
||||
float specPow;
|
||||
#if USE_SPECULAR_MAP
|
||||
#if USE_TRIPLANAR
|
||||
vec4 s = triplanar(specTex, v_tex);
|
||||
vec4 s = triplanar(GET_DRAW_TEXTURE_2D(specTex), v_tex);
|
||||
#else
|
||||
vec4 s = texture2D(specTex, v_tex);
|
||||
vec4 s = SAMPLE_2D(GET_DRAW_TEXTURE_2D(specTex), v_tex);
|
||||
#endif
|
||||
specCol = s.rgb;
|
||||
specular.a = s.a;
|
||||
@ -169,9 +128,11 @@ void main()
|
||||
color = mix(texdiffuse, color, specular.a);
|
||||
#endif
|
||||
|
||||
color = applyFog(color);
|
||||
color = applyFog(color, fogColor, fogParams);
|
||||
|
||||
color *= getLOS();
|
||||
#if !IGNORE_LOS
|
||||
color *= getLOS(GET_DRAW_TEXTURE_2D(losTex), v_los);
|
||||
#endif
|
||||
|
||||
#if DECAL
|
||||
color *= shadingColor;
|
||||
|
69
binaries/data/mods/public/shaders/glsl/terrain_common.h
Normal file
69
binaries/data/mods/public/shaders/glsl/terrain_common.h
Normal file
@ -0,0 +1,69 @@
|
||||
#include "common/shadows.h"
|
||||
#include "common/stage.h"
|
||||
|
||||
BEGIN_DRAW_TEXTURES
|
||||
TEXTURE_2D(0, baseTex)
|
||||
TEXTURE_2D(1, blendTex)
|
||||
TEXTURE_2D(2, normTex)
|
||||
TEXTURE_2D(3, specTex)
|
||||
#if !IGNORE_LOS
|
||||
TEXTURE_2D(4, losTex)
|
||||
#endif
|
||||
#if USE_SHADOW
|
||||
SHADOWS_TEXTURES(5)
|
||||
#endif
|
||||
END_DRAW_TEXTURES
|
||||
|
||||
BEGIN_DRAW_UNIFORMS
|
||||
UNIFORM(vec3, shadingColor)
|
||||
UNIFORM(vec2, textureTransform)
|
||||
#if USE_SPECULAR
|
||||
UNIFORM(float, specularPower)
|
||||
UNIFORM(vec3, specularColor)
|
||||
#endif
|
||||
#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_AO
|
||||
UNIFORM(vec4, effectSettings)
|
||||
#endif
|
||||
END_DRAW_UNIFORMS
|
||||
|
||||
BEGIN_MATERIAL_UNIFORMS
|
||||
UNIFORM(vec3, ambient)
|
||||
UNIFORM(mat4, transform)
|
||||
UNIFORM(vec3, cameraPos)
|
||||
UNIFORM(vec3, sunDir)
|
||||
UNIFORM(vec3, sunColor)
|
||||
UNIFORM(vec3, fogColor)
|
||||
UNIFORM(vec2, fogParams)
|
||||
UNIFORM(vec2, losTransform)
|
||||
#if USE_SHADOW
|
||||
SHADOWS_UNIFORMS
|
||||
#endif
|
||||
END_MATERIAL_UNIFORMS
|
||||
|
||||
#if USE_SPECULAR || USE_SPECULAR_MAP || USE_NORMAL_MAP || USE_TRIPLANAR
|
||||
VERTEX_OUTPUT(0, vec3, v_normal);
|
||||
#endif
|
||||
VERTEX_OUTPUT(1, vec3, v_lighting);
|
||||
#if BLEND
|
||||
VERTEX_OUTPUT(2, vec2, v_blend);
|
||||
#endif
|
||||
#if USE_TRIPLANAR
|
||||
VERTEX_OUTPUT(3, vec3, v_tex);
|
||||
#else
|
||||
VERTEX_OUTPUT(3, vec2, v_tex);
|
||||
#endif
|
||||
#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP
|
||||
#if USE_NORMAL_MAP
|
||||
VERTEX_OUTPUT(4, vec4, v_tangent);
|
||||
VERTEX_OUTPUT(5, vec3, v_bitangent);
|
||||
#endif
|
||||
#if USE_SPECULAR || USE_SPECULAR_MAP
|
||||
VERTEX_OUTPUT(6, vec3, v_half);
|
||||
#endif
|
||||
#endif
|
||||
#if !IGNORE_LOS
|
||||
VERTEX_OUTPUT(7, vec2, v_los);
|
||||
#endif
|
||||
#if USE_SHADOW
|
||||
SHADOWS_VERTEX_OUTPUTS(8)
|
||||
#endif
|
@ -1,46 +1,19 @@
|
||||
#version 120
|
||||
|
||||
#include "terrain_common.h"
|
||||
|
||||
#include "common/los_vertex.h"
|
||||
#include "common/shadows_vertex.h"
|
||||
#include "common/vertex.h"
|
||||
|
||||
uniform mat4 transform;
|
||||
uniform vec3 cameraPos;
|
||||
#ifdef GL_ES
|
||||
uniform mediump vec3 sunDir;
|
||||
uniform mediump vec3 sunColor;
|
||||
#else
|
||||
uniform vec3 sunDir;
|
||||
uniform vec3 sunColor;
|
||||
#endif
|
||||
uniform vec2 textureTransform;
|
||||
|
||||
varying vec3 v_lighting;
|
||||
|
||||
varying vec2 v_blend;
|
||||
|
||||
#if USE_TRIPLANAR
|
||||
varying vec3 v_tex;
|
||||
#else
|
||||
varying vec2 v_tex;
|
||||
#endif
|
||||
|
||||
varying vec3 v_normal;
|
||||
|
||||
#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP
|
||||
#if USE_NORMAL_MAP
|
||||
varying vec4 v_tangent;
|
||||
varying vec3 v_bitangent;
|
||||
#endif
|
||||
#if USE_SPECULAR || USE_SPECULAR_MAP
|
||||
varying vec3 v_half;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
VERTEX_INPUT_ATTRIBUTE(0, vec3, a_vertex);
|
||||
VERTEX_INPUT_ATTRIBUTE(1, vec3, a_normal);
|
||||
#if DECAL
|
||||
VERTEX_INPUT_ATTRIBUTE(2, vec2, a_uv0);
|
||||
#endif
|
||||
#if BLEND
|
||||
VERTEX_INPUT_ATTRIBUTE(3, vec2, a_uv1);
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
@ -78,8 +51,9 @@ void main()
|
||||
#endif
|
||||
|
||||
calculatePositionInShadowSpace(vec4(a_vertex, 1.0));
|
||||
|
||||
#if USE_SPECULAR || USE_SPECULAR_MAP || USE_NORMAL_MAP || USE_TRIPLANAR
|
||||
v_normal = a_normal;
|
||||
#endif
|
||||
|
||||
#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_TRIPLANAR
|
||||
#if USE_NORMAL_MAP
|
||||
@ -98,5 +72,7 @@ void main()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
calculateLOSCoordinates(a_vertex.xz);
|
||||
#if !IGNORE_LOS
|
||||
v_los = calculateLOSCoordinates(a_vertex.xz, losTransform);
|
||||
#endif
|
||||
}
|
||||
|
@ -1,69 +1,13 @@
|
||||
#version 110
|
||||
|
||||
#include "water_high.h"
|
||||
|
||||
#include "common/debug_fragment.h"
|
||||
#include "common/fog.h"
|
||||
#include "common/fragment.h"
|
||||
#include "common/los_fragment.h"
|
||||
#include "common/shadows_fragment.h"
|
||||
|
||||
// Environment settings
|
||||
uniform vec3 ambient;
|
||||
uniform vec3 sunDir;
|
||||
uniform vec3 sunColor;
|
||||
uniform mat4 skyBoxRot;
|
||||
|
||||
uniform float waviness; // "Wildness" of the reflections and refractions; choose based on texture
|
||||
uniform vec3 color; // color of the water
|
||||
uniform vec3 tint; // Tint for refraction (used to simulate particles in water)
|
||||
uniform float murkiness; // Amount of tint to blend in with the refracted color
|
||||
|
||||
uniform float windAngle;
|
||||
varying vec2 WindCosSin;
|
||||
|
||||
uniform vec2 screenSize;
|
||||
varying float moddedTime;
|
||||
|
||||
varying vec3 worldPos;
|
||||
varying float waterDepth;
|
||||
varying vec2 waterInfo;
|
||||
|
||||
varying vec3 v_eyeVec;
|
||||
|
||||
varying vec4 normalCoords;
|
||||
#if USE_REFLECTION
|
||||
varying vec3 reflectionCoords;
|
||||
#endif
|
||||
#if USE_REFRACTION
|
||||
varying vec3 refractionCoords;
|
||||
#endif
|
||||
|
||||
varying float fwaviness;
|
||||
|
||||
uniform samplerCube skyCube;
|
||||
|
||||
uniform sampler2D normalMap;
|
||||
uniform sampler2D normalMap2;
|
||||
|
||||
#if USE_FANCY_EFFECTS
|
||||
uniform sampler2D waterEffectsTex;
|
||||
#endif
|
||||
|
||||
uniform vec4 waveParams1; // wavyEffect, BaseScale, Flattenism, Basebump
|
||||
uniform vec4 waveParams2; // Smallintensity, Smallbase, Bigmovement, Smallmovement
|
||||
|
||||
#if USE_REFLECTION
|
||||
uniform sampler2D reflectionMap;
|
||||
#endif
|
||||
|
||||
#if USE_REFRACTION
|
||||
uniform sampler2D refractionMap;
|
||||
#if USE_REAL_DEPTH
|
||||
uniform sampler2D depthTex;
|
||||
uniform mat4 projInvTransform;
|
||||
uniform mat4 viewInvTransform;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
vec3 getNormal(vec4 fancyeffects)
|
||||
{
|
||||
float wavyEffect = waveParams1.r;
|
||||
@ -74,12 +18,12 @@ vec3 getNormal(vec4 fancyeffects)
|
||||
|
||||
// This method uses 60 animated water frames. We're blending between each two frames
|
||||
// Scale the normal textures by waviness so that big waviness means bigger waves.
|
||||
vec3 ww1 = texture2D(normalMap, (normalCoords.st + normalCoords.zw * BigMovement * waviness / 10.0) * (baseScale - waviness / wavyEffect)).xzy;
|
||||
vec3 ww2 = texture2D(normalMap2, (normalCoords.st + normalCoords.zw * BigMovement * waviness / 10.0) * (baseScale - waviness / wavyEffect)).xzy;
|
||||
vec3 ww1 = SAMPLE_2D(GET_DRAW_TEXTURE_2D(normalMap), (normalCoords.st + normalCoords.zw * BigMovement * waviness / 10.0) * (baseScale - waviness / wavyEffect)).xzy;
|
||||
vec3 ww2 = SAMPLE_2D(GET_DRAW_TEXTURE_2D(normalMap2), (normalCoords.st + normalCoords.zw * BigMovement * waviness / 10.0) * (baseScale - waviness / wavyEffect)).xzy;
|
||||
vec3 wwInterp = mix(ww1, ww2, moddedTime) - vec3(0.5, 0.0, 0.5);
|
||||
|
||||
ww1.x = wwInterp.x * WindCosSin.x - wwInterp.z * WindCosSin.y;
|
||||
ww1.z = wwInterp.x * WindCosSin.y + wwInterp.z * WindCosSin.x;
|
||||
ww1.x = wwInterp.x * windCosSin.x - wwInterp.z * windCosSin.y;
|
||||
ww1.z = wwInterp.x * windCosSin.y + wwInterp.z * windCosSin.x;
|
||||
ww1.y = wwInterp.y;
|
||||
|
||||
// Flatten them based on waviness.
|
||||
@ -123,19 +67,19 @@ vec4 getReflection(vec3 normal, vec3 eyeVec)
|
||||
|
||||
// Distort the reflection coords based on waves.
|
||||
vec2 reflCoords = (0.5 * reflectionCoords.xy - 15.0 * normal.zx / refVY) / reflectionCoords.z + 0.5;
|
||||
vec4 refTex = texture2D(reflectionMap, reflCoords);
|
||||
vec4 refTex = SAMPLE_2D(GET_DRAW_TEXTURE_2D(reflectionMap), reflCoords);
|
||||
|
||||
vec3 reflColor = refTex.rgb;
|
||||
|
||||
// Interpolate between the sky color and nearby objects.
|
||||
// Only do this when alpha is rather low, or transparent leaves show up as extremely white.
|
||||
if (refTex.a < 0.4)
|
||||
reflColor = mix(textureCube(skyCube, (vec4(eye, 0.0) * skyBoxRot).xyz).rgb, refTex.rgb, refTex.a);
|
||||
reflColor = mix(SAMPLE_CUBE(GET_DRAW_TEXTURE_CUBE(skyCube), (vec4(eye, 0.0) * skyBoxRot).xyz).rgb, refTex.rgb, refTex.a);
|
||||
|
||||
// Let actual objects be reflected fully.
|
||||
reflMod = max(refTex.a, 0.75);
|
||||
#else
|
||||
vec3 reflColor = textureCube(skyCube, (vec4(eye, 0.0) * skyBoxRot).xyz).rgb;
|
||||
vec3 reflColor = SAMPLE_CUBE(GET_DRAW_TEXTURE_CUBE(skyCube), (vec4(eye, 0.0) * skyBoxRot).xyz).rgb;
|
||||
#endif
|
||||
|
||||
return vec4(reflColor, reflMod);
|
||||
@ -144,7 +88,7 @@ vec4 getReflection(vec3 normal, vec3 eyeVec)
|
||||
#if USE_REFRACTION && USE_REAL_DEPTH
|
||||
vec3 getWorldPositionFromRefractionDepth(vec2 uv)
|
||||
{
|
||||
float depth = texture2D(depthTex, uv).x;
|
||||
float depth = SAMPLE_2D(GET_DRAW_TEXTURE_2D(depthTex), uv).x;
|
||||
vec4 viewPosition = projInvTransform * (vec4((uv - vec2(0.5)) * 2.0, depth * 2.0 - 1.0, 1.0));
|
||||
viewPosition /= viewPosition.w;
|
||||
vec3 refrWorldPos = (viewInvTransform * viewPosition).xyz;
|
||||
@ -198,7 +142,7 @@ vec4 getRefraction(vec3 normal, vec3 eyeVec, float depthLimit)
|
||||
|
||||
// Distort the texture coords under where the water is to simulate refraction.
|
||||
vec2 refrCoords = (0.5 * refractionCoords.xy - normal.xz * distoFactor) / refractionCoords.z + 0.5;
|
||||
vec3 refColor = texture2D(refractionMap, refrCoords).rgb;
|
||||
vec3 refColor = SAMPLE_2D(GET_DRAW_TEXTURE_2D(refractionMap), refrCoords).rgb;
|
||||
|
||||
// Note, the refraction map is cleared using (255, 0, 0), so pixels outside of the water plane are pure red.
|
||||
// If we get a pure red fragment, use an undistorted/less distorted coord instead.
|
||||
@ -208,13 +152,13 @@ vec4 getRefraction(vec3 normal, vec3 eyeVec, float depthLimit)
|
||||
|
||||
vec4 blurColor = vec4(refColor, 1.0);
|
||||
|
||||
vec4 tex = texture2D(refractionMap, refrCoords + vec2(blur + normal.x, blur + normal.z));
|
||||
vec4 tex = SAMPLE_2D(GET_DRAW_TEXTURE_2D(refractionMap), refrCoords + vec2(blur + normal.x, blur + normal.z));
|
||||
blurColor += vec4(tex.rgb * tex.a, tex.a);
|
||||
tex = texture2D(refractionMap, refrCoords + vec2(-blur, blur + normal.z));
|
||||
tex = SAMPLE_2D(GET_DRAW_TEXTURE_2D(refractionMap), refrCoords + vec2(-blur, blur + normal.z));
|
||||
blurColor += vec4(tex.rgb * tex.a, tex.a);
|
||||
tex = texture2D(refractionMap, refrCoords + vec2(-blur, -blur + normal.x));
|
||||
tex = SAMPLE_2D(GET_DRAW_TEXTURE_2D(refractionMap), refrCoords + vec2(-blur, -blur + normal.x));
|
||||
blurColor += vec4(tex.rgb * tex.a, tex.a);
|
||||
tex = texture2D(refractionMap, refrCoords + vec2(blur + normal.z, -blur));
|
||||
tex = SAMPLE_2D(GET_DRAW_TEXTURE_2D(refractionMap), refrCoords + vec2(blur + normal.z, -blur));
|
||||
blurColor += vec4(tex.rgb * tex.a, tex.a);
|
||||
blurColor /= blurColor.a;
|
||||
float blurFactor = (distoFactor / 7.0);
|
||||
@ -254,14 +198,14 @@ vec4 getFoam(vec4 fancyeffects, float shadow)
|
||||
float wavyEffect = waveParams1.r;
|
||||
float baseScale = waveParams1.g;
|
||||
float BigMovement = waveParams2.b;
|
||||
vec3 foam1 = texture2D(normalMap, (normalCoords.st + normalCoords.zw * BigMovement * waviness / 10.0) * (baseScale - waviness / wavyEffect)).aaa;
|
||||
vec3 foam2 = texture2D(normalMap2, (normalCoords.st + normalCoords.zw * BigMovement * waviness / 10.0) * (baseScale - waviness / wavyEffect)).aaa;
|
||||
vec3 foam3 = texture2D(normalMap, normalCoords.st / 6.0 - normalCoords.zw * 0.02).aaa;
|
||||
vec3 foam4 = texture2D(normalMap2, normalCoords.st / 6.0 - normalCoords.zw * 0.02).aaa;
|
||||
vec3 foam1 = SAMPLE_2D(GET_DRAW_TEXTURE_2D(normalMap), (normalCoords.st + normalCoords.zw * BigMovement * waviness / 10.0) * (baseScale - waviness / wavyEffect)).aaa;
|
||||
vec3 foam2 = SAMPLE_2D(GET_DRAW_TEXTURE_2D(normalMap2), (normalCoords.st + normalCoords.zw * BigMovement * waviness / 10.0) * (baseScale - waviness / wavyEffect)).aaa;
|
||||
vec3 foam3 = SAMPLE_2D(GET_DRAW_TEXTURE_2D(normalMap), normalCoords.st / 6.0 - normalCoords.zw * 0.02).aaa;
|
||||
vec3 foam4 = SAMPLE_2D(GET_DRAW_TEXTURE_2D(normalMap2), normalCoords.st / 6.0 - normalCoords.zw * 0.02).aaa;
|
||||
vec3 foaminterp = mix(foam1, foam2, moddedTime);
|
||||
foaminterp *= mix(foam3, foam4, moddedTime);
|
||||
|
||||
foam1.x = abs(foaminterp.x * WindCosSin.x) + abs(foaminterp.z * WindCosSin.y);
|
||||
foam1.x = abs(foaminterp.x * windCosSin.x) + abs(foaminterp.z * windCosSin.y);
|
||||
|
||||
float alpha = (fancyeffects.g + pow(foam1.x * (3.0 + waviness), 2.6 - waviness / 5.5)) * 2.0;
|
||||
return vec4(sunColor * shadow + ambient, clamp(alpha, 0.0, 1.0));
|
||||
@ -272,7 +216,9 @@ vec4 getFoam(vec4 fancyeffects, float shadow)
|
||||
|
||||
void main()
|
||||
{
|
||||
float los = getLOS();
|
||||
#if !IGNORE_LOS
|
||||
float los = getLOS(GET_DRAW_TEXTURE_2D(losTex), v_los);
|
||||
#endif
|
||||
// We don't need to render a water fragment if it's invisible.
|
||||
if (los < 0.001)
|
||||
{
|
||||
@ -281,7 +227,7 @@ void main()
|
||||
}
|
||||
|
||||
#if USE_FANCY_EFFECTS
|
||||
vec4 fancyeffects = texture2D(waterEffectsTex, gl_FragCoord.xy / screenSize);
|
||||
vec4 fancyeffects = SAMPLE_2D(GET_DRAW_TEXTURE_2D(waterEffectsTex), gl_FragCoord.xy / screenSize);
|
||||
#else
|
||||
vec4 fancyeffects = vec4(0.0);
|
||||
#endif
|
||||
@ -313,7 +259,7 @@ void main()
|
||||
vec4 foam = getFoam(fancyeffects, shadow);
|
||||
color = clamp(mix(color, foam.rgb, foam.a), 0.0, 1.0);
|
||||
|
||||
color = applyFog(color);
|
||||
color = applyFog(color, fogColor, fogParams);
|
||||
|
||||
OUTPUT_FRAGMENT_SINGLE_COLOR(vec4(applyDebugColor(color * los, 1.0, refrColor.a, 0.0), refrColor.a));
|
||||
}
|
||||
|
86
binaries/data/mods/public/shaders/glsl/water_high.h
Normal file
86
binaries/data/mods/public/shaders/glsl/water_high.h
Normal file
@ -0,0 +1,86 @@
|
||||
#include "common/shadows.h"
|
||||
#include "common/stage.h"
|
||||
|
||||
BEGIN_DRAW_TEXTURES
|
||||
TEXTURE_CUBE(0, skyCube)
|
||||
TEXTURE_2D(1, normalMap)
|
||||
TEXTURE_2D(2, normalMap2)
|
||||
#if USE_FANCY_EFFECTS
|
||||
TEXTURE_2D(3, waterEffectsTex)
|
||||
#endif
|
||||
#if USE_REFLECTION
|
||||
TEXTURE_2D(4, reflectionMap)
|
||||
#endif
|
||||
#if USE_REFRACTION
|
||||
TEXTURE_2D(5, refractionMap)
|
||||
#if USE_REAL_DEPTH
|
||||
TEXTURE_2D(6, depthTex)
|
||||
#endif
|
||||
#endif
|
||||
#if !IGNORE_LOS
|
||||
TEXTURE_2D(4, losTex)
|
||||
#endif
|
||||
#if USE_SHADOW
|
||||
SHADOWS_TEXTURES(5)
|
||||
#endif
|
||||
END_DRAW_TEXTURES
|
||||
|
||||
BEGIN_DRAW_UNIFORMS
|
||||
UNIFORM(mat4, transform)
|
||||
END_DRAW_UNIFORMS
|
||||
|
||||
BEGIN_MATERIAL_UNIFORMS
|
||||
UNIFORM(mat4, reflectionMatrix)
|
||||
UNIFORM(mat4, refractionMatrix)
|
||||
#if USE_REFRACTION && USE_REAL_DEPTH
|
||||
UNIFORM(mat4, projInvTransform)
|
||||
UNIFORM(mat4, viewInvTransform)
|
||||
#endif
|
||||
UNIFORM(float, time)
|
||||
UNIFORM(float, repeatScale)
|
||||
UNIFORM(vec2, screenSize)
|
||||
UNIFORM(vec3, cameraPos)
|
||||
|
||||
UNIFORM(float, waviness) // "Wildness" of the reflections and refractions; choose based on texture
|
||||
UNIFORM(vec3, color) // color of the water
|
||||
UNIFORM(vec3, tint) // Tint for refraction (used to simulate particles in water)
|
||||
UNIFORM(float, murkiness) // Amount of tint to blend in with the refracted color
|
||||
UNIFORM(float, windAngle)
|
||||
|
||||
UNIFORM(vec4, waveParams1) // wavyEffect, BaseScale, Flattenism, Basebump
|
||||
UNIFORM(vec4, waveParams2) // Smallintensity, Smallbase, Bigmovement, Smallmovement
|
||||
|
||||
// Environment settings
|
||||
UNIFORM(vec3, ambient)
|
||||
UNIFORM(vec3, sunDir)
|
||||
UNIFORM(vec3, sunColor)
|
||||
UNIFORM(mat4, skyBoxRot)
|
||||
|
||||
UNIFORM(vec3, fogColor)
|
||||
UNIFORM(vec2, fogParams)
|
||||
UNIFORM(vec2, losTransform)
|
||||
#if USE_SHADOW
|
||||
SHADOWS_UNIFORMS
|
||||
#endif
|
||||
END_MATERIAL_UNIFORMS
|
||||
|
||||
VERTEX_OUTPUT(0, vec3, worldPos);
|
||||
VERTEX_OUTPUT(1, float, waterDepth);
|
||||
VERTEX_OUTPUT(2, vec2, waterInfo);
|
||||
VERTEX_OUTPUT(3, float, fwaviness);
|
||||
VERTEX_OUTPUT(4, float, moddedTime);
|
||||
VERTEX_OUTPUT(5, vec2, windCosSin);
|
||||
VERTEX_OUTPUT(6, vec3, v_eyeVec);
|
||||
VERTEX_OUTPUT(7, vec4, normalCoords);
|
||||
#if USE_REFLECTION
|
||||
VERTEX_OUTPUT(8, vec3, reflectionCoords);
|
||||
#endif
|
||||
#if USE_REFRACTION
|
||||
VERTEX_OUTPUT(9, vec3, refractionCoords);
|
||||
#endif
|
||||
#if !IGNORE_LOS
|
||||
VERTEX_OUTPUT(10, vec2, v_los);
|
||||
#endif
|
||||
#if USE_SHADOW
|
||||
SHADOWS_VERTEX_OUTPUTS(11)
|
||||
#endif
|
@ -1,40 +1,11 @@
|
||||
#version 110
|
||||
|
||||
#include "water_high.h"
|
||||
|
||||
#include "common/los_vertex.h"
|
||||
#include "common/shadows_vertex.h"
|
||||
#include "common/vertex.h"
|
||||
|
||||
uniform mat4 reflectionMatrix;
|
||||
uniform mat4 refractionMatrix;
|
||||
uniform float repeatScale;
|
||||
uniform float windAngle;
|
||||
// "Wildness" of the reflections and refractions; choose based on texture
|
||||
uniform float waviness;
|
||||
|
||||
uniform float time;
|
||||
|
||||
uniform mat4 transform;
|
||||
uniform vec3 cameraPos;
|
||||
|
||||
varying float moddedTime;
|
||||
|
||||
varying vec3 worldPos;
|
||||
varying float waterDepth;
|
||||
varying vec2 waterInfo;
|
||||
|
||||
varying vec3 v_eyeVec;
|
||||
|
||||
varying vec4 normalCoords;
|
||||
#if USE_REFLECTION
|
||||
varying vec3 reflectionCoords;
|
||||
#endif
|
||||
#if USE_REFRACTION
|
||||
varying vec3 refractionCoords;
|
||||
#endif
|
||||
|
||||
varying float fwaviness;
|
||||
varying vec2 WindCosSin;
|
||||
|
||||
VERTEX_INPUT_ATTRIBUTE(0, vec3, a_vertex);
|
||||
VERTEX_INPUT_ATTRIBUTE(1, vec2, a_waterInfo);
|
||||
|
||||
@ -44,10 +15,10 @@ void main()
|
||||
waterInfo = a_waterInfo;
|
||||
waterDepth = a_waterInfo.g;
|
||||
|
||||
WindCosSin = vec2(cos(-windAngle), sin(-windAngle));
|
||||
windCosSin = vec2(cos(-windAngle), sin(-windAngle));
|
||||
|
||||
float newX = a_vertex.x * WindCosSin.x - a_vertex.z * WindCosSin.y;
|
||||
float newY = a_vertex.x * WindCosSin.y + a_vertex.z * WindCosSin.x;
|
||||
float newX = a_vertex.x * windCosSin.x - a_vertex.z * windCosSin.y;
|
||||
float newY = a_vertex.x * windCosSin.y + a_vertex.z * windCosSin.x;
|
||||
|
||||
normalCoords = vec4(newX, newY, time, 0.0);
|
||||
normalCoords.xy *= repeatScale;
|
||||
@ -58,7 +29,10 @@ void main()
|
||||
#if USE_REFRACTION
|
||||
refractionCoords = (refractionMatrix * vec4(a_vertex, 1.0)).rga;
|
||||
#endif
|
||||
calculateLOSCoordinates(a_vertex.xz);
|
||||
|
||||
#if !IGNORE_LOS
|
||||
v_los = calculateLOSCoordinates(a_vertex.xz, losTransform);
|
||||
#endif
|
||||
|
||||
calculatePositionInShadowSpace(vec4(a_vertex, 1.0));
|
||||
|
||||
|
@ -1,14 +1,18 @@
|
||||
#version 110
|
||||
|
||||
#include "water_simple.h"
|
||||
|
||||
#include "common/fog.h"
|
||||
#include "common/fragment.h"
|
||||
#include "common/los_fragment.h"
|
||||
|
||||
uniform sampler2D baseTex;
|
||||
uniform vec3 color;
|
||||
|
||||
varying vec2 v_coords;
|
||||
|
||||
void main()
|
||||
{
|
||||
OUTPUT_FRAGMENT_SINGLE_COLOR(vec4(texture2D(baseTex, v_coords).rgb * color * getLOS(), 1.0));
|
||||
vec3 waterColor = SAMPLE_2D(GET_DRAW_TEXTURE_2D(baseTex), v_coords).rgb;
|
||||
waterColor *= color;
|
||||
waterColor = applyFog(waterColor, fogColor, fogParams);
|
||||
#if !IGNORE_LOS
|
||||
waterColor *= getLOS(GET_DRAW_TEXTURE_2D(losTex), v_los);
|
||||
#endif
|
||||
OUTPUT_FRAGMENT_SINGLE_COLOR(vec4(waterColor, 1.0));
|
||||
}
|
||||
|
25
binaries/data/mods/public/shaders/glsl/water_simple.h
Normal file
25
binaries/data/mods/public/shaders/glsl/water_simple.h
Normal file
@ -0,0 +1,25 @@
|
||||
#include "common/stage.h"
|
||||
|
||||
BEGIN_DRAW_TEXTURES
|
||||
TEXTURE_2D(0, baseTex)
|
||||
#if !IGNORE_LOS
|
||||
TEXTURE_2D(1, losTex)
|
||||
#endif
|
||||
END_DRAW_TEXTURES
|
||||
|
||||
BEGIN_DRAW_UNIFORMS
|
||||
UNIFORM(mat4, transform)
|
||||
UNIFORM(float, time)
|
||||
UNIFORM(vec3, color)
|
||||
END_DRAW_UNIFORMS
|
||||
|
||||
BEGIN_MATERIAL_UNIFORMS
|
||||
UNIFORM(vec3, fogColor)
|
||||
UNIFORM(vec2, fogParams)
|
||||
UNIFORM(vec2, losTransform)
|
||||
END_MATERIAL_UNIFORMS
|
||||
|
||||
VERTEX_OUTPUT(0, vec2, v_coords);
|
||||
#if !IGNORE_LOS
|
||||
VERTEX_OUTPUT(1, vec2, v_los);
|
||||
#endif
|
@ -1,15 +1,12 @@
|
||||
#version 110
|
||||
|
||||
#include "water_simple.h"
|
||||
|
||||
#include "common/los_vertex.h"
|
||||
#include "common/vertex.h"
|
||||
|
||||
VERTEX_INPUT_ATTRIBUTE(0, vec3, a_vertex);
|
||||
|
||||
uniform mat4 transform;
|
||||
uniform float time;
|
||||
|
||||
varying vec2 v_coords;
|
||||
|
||||
void main()
|
||||
{
|
||||
// Shift the texture coordinates by these amounts to make the water "flow"
|
||||
@ -18,6 +15,8 @@ void main()
|
||||
float repeatPeriod = 16.0;
|
||||
|
||||
v_coords = a_vertex.xz / repeatPeriod + vec2(tx, tz);
|
||||
calculateLOSCoordinates(a_vertex.xz);
|
||||
#if !IGNORE_LOS
|
||||
v_los = calculateLOSCoordinates(a_vertex.xz, losTransform);
|
||||
#endif
|
||||
OUTPUT_VERTEX_POSITION(transform * vec4(a_vertex, 1.0));
|
||||
}
|
||||
|
@ -1,20 +1,12 @@
|
||||
#version 110
|
||||
|
||||
#include "waves.h"
|
||||
|
||||
#include "common/fragment.h"
|
||||
|
||||
uniform sampler2D waveTex;
|
||||
uniform sampler2D foamTex;
|
||||
|
||||
uniform float translation;
|
||||
uniform float width;
|
||||
|
||||
varying float ttime;
|
||||
varying vec2 normal;
|
||||
varying vec2 v_tex;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 Tex = texture2D(waveTex, -v_tex.xy/8.0).rbga;
|
||||
vec4 Tex = SAMPLE_2D(GET_DRAW_TEXTURE_2D(waveTex), -v_tex.xy/8.0).rbga;
|
||||
|
||||
Tex.rgb -= vec3(0.5,0.0,0.5);
|
||||
Tex.rb *= -1.0;
|
||||
@ -37,8 +29,8 @@ void main()
|
||||
Tex.r = norm.x * normal.x - norm.y * normal.x;
|
||||
Tex.b = norm.x * normal.y + norm.y * normal.y;
|
||||
|
||||
vec3 foam = texture2D(foamTex, -v_tex.xy/vec2(2.5,7.0) + vec2(0.05,-0.3)*-cos(ttime/2.0)).rbg;
|
||||
foam *= texture2D(foamTex, -v_tex.xy/5.0 + vec2(0.8,-0.8) + vec2(-0.05,-0.25)*-cos(ttime/2.0)*1.2).rbg;
|
||||
vec3 foam = SAMPLE_2D(GET_DRAW_TEXTURE_2D(foamTex), -v_tex.xy/vec2(2.5,7.0) + vec2(0.05,-0.3)*-cos(ttime/2.0)).rbg;
|
||||
foam *= SAMPLE_2D(GET_DRAW_TEXTURE_2D(foamTex), -v_tex.xy/5.0 + vec2(0.8,-0.8) + vec2(-0.05,-0.25)*-cos(ttime/2.0)*1.2).rbg;
|
||||
Tex.g = foamAlpha * clamp(foam.r * 3.0, 0.0, 1.0) * 0.4;
|
||||
|
||||
OUTPUT_FRAGMENT_SINGLE_COLOR(Tex);
|
||||
|
17
binaries/data/mods/public/shaders/glsl/waves.h
Normal file
17
binaries/data/mods/public/shaders/glsl/waves.h
Normal file
@ -0,0 +1,17 @@
|
||||
#include "common/stage.h"
|
||||
|
||||
BEGIN_DRAW_TEXTURES
|
||||
TEXTURE_2D(0, waveTex)
|
||||
TEXTURE_2D(1, foamTex)
|
||||
END_DRAW_TEXTURES
|
||||
|
||||
BEGIN_DRAW_UNIFORMS
|
||||
UNIFORM(float, translation)
|
||||
UNIFORM(float, width)
|
||||
UNIFORM(float, time)
|
||||
UNIFORM(mat4, transform)
|
||||
END_DRAW_UNIFORMS
|
||||
|
||||
VERTEX_OUTPUT(0, float, ttime);
|
||||
VERTEX_OUTPUT(1, vec2, normal);
|
||||
VERTEX_OUTPUT(2, vec2, v_tex);
|
@ -1,5 +1,7 @@
|
||||
#version 110
|
||||
|
||||
#include "waves.h"
|
||||
|
||||
#include "common/vertex.h"
|
||||
|
||||
VERTEX_INPUT_ATTRIBUTE(0, vec3, a_basePosition);
|
||||
@ -9,16 +11,6 @@ VERTEX_INPUT_ATTRIBUTE(3, vec3, a_retreatPosition);
|
||||
VERTEX_INPUT_ATTRIBUTE(4, vec2, a_normal);
|
||||
VERTEX_INPUT_ATTRIBUTE(5, vec2, a_uv0);
|
||||
|
||||
uniform float time;
|
||||
uniform float translation;
|
||||
uniform float width;
|
||||
|
||||
uniform mat4 transform;
|
||||
|
||||
varying float ttime;
|
||||
varying vec2 normal;
|
||||
varying vec2 v_tex;
|
||||
|
||||
void main()
|
||||
{
|
||||
normal = a_normal;
|
||||
|
@ -173,7 +173,7 @@ int GetAttributeLocationFromStream(
|
||||
}
|
||||
|
||||
bool PreprocessShaderFile(
|
||||
bool arb, const CShaderDefines& defines, const VfsPath& path,
|
||||
bool arb, const CShaderDefines& defines, const VfsPath& path, const char* stage,
|
||||
CStr& source, std::vector<VfsPath>& fileDependencies)
|
||||
{
|
||||
CVFSFile file;
|
||||
@ -201,6 +201,8 @@ bool PreprocessShaderFile(
|
||||
return true;
|
||||
});
|
||||
preprocessor.AddDefines(defines);
|
||||
if (!arb)
|
||||
preprocessor.AddDefine(stage, "1");
|
||||
|
||||
#if CONFIG2_GLES
|
||||
if (!arb)
|
||||
@ -284,10 +286,10 @@ public:
|
||||
std::vector<VfsPath> newFileDependencies = {path, vertexFilePath, fragmentFilePath};
|
||||
|
||||
CStr vertexCode;
|
||||
if (!PreprocessShaderFile(true, defines, vertexFilePath, vertexCode, newFileDependencies))
|
||||
if (!PreprocessShaderFile(true, defines, vertexFilePath, "STAGE_VERTEX", vertexCode, newFileDependencies))
|
||||
return;
|
||||
CStr fragmentCode;
|
||||
if (!PreprocessShaderFile(true, defines, fragmentFilePath, fragmentCode, newFileDependencies))
|
||||
if (!PreprocessShaderFile(true, defines, fragmentFilePath, "STAGE_FRAGMENT", fragmentCode, newFileDependencies))
|
||||
return;
|
||||
|
||||
m_FileDependencies = std::move(newFileDependencies);
|
||||
@ -614,10 +616,10 @@ public:
|
||||
std::vector<VfsPath> newFileDependencies = {path, vertexFilePath, fragmentFilePath};
|
||||
|
||||
CStr vertexCode;
|
||||
if (!PreprocessShaderFile(false, defines, vertexFilePath, vertexCode, newFileDependencies))
|
||||
if (!PreprocessShaderFile(false, defines, vertexFilePath, "STAGE_VERTEX", vertexCode, newFileDependencies))
|
||||
return;
|
||||
CStr fragmentCode;
|
||||
if (!PreprocessShaderFile(false, defines, fragmentFilePath, fragmentCode, newFileDependencies))
|
||||
if (!PreprocessShaderFile(false, defines, fragmentFilePath, "STAGE_FRAGMENT", fragmentCode, newFileDependencies))
|
||||
return;
|
||||
|
||||
m_FileDependencies = std::move(newFileDependencies);
|
||||
|
Loading…
Reference in New Issue
Block a user