Watergit push!

This commit is contained in:
2025-09-07 21:15:00 +03:00
parent 92ec3e9497
commit d42cf2854a
11 changed files with 388 additions and 44 deletions

View File

@@ -9,6 +9,7 @@ IN(vec4 position, POSITION)
IN(vec3 positionWS, TEXCOORD0)
MAIN_DECLARATION
{
vec4 depth = vec4(length(positionWS - cameraPosition), 0.0, 0.0, 1.0);
gl_FragColor = depth;
highp float depth = length(positionWS - cameraPosition);
vec4 depthv = vec4(depth / 256.0, depth / 500.0, depth / 1000.0, 1.0);
gl_FragColor = depthv;
}

View File

@@ -1,12 +1,29 @@
OGRE_NATIVE_GLSL_VERSION_DIRECTIVE
#include <OgreUnifiedShader.h>
// SAMPLER2D(noiseMap, 0);
SAMPLER2D(reflectMap, 0);
SAMPLER2D(noiseMap, 1);
// SAMPLER2D(refractMap, 1);
#if NEW_WATER_SHADER
MAIN_PARAMETERS
IN(vec4 clipSpace, TEXCOORD0)
MAIN_DECLARATION
{
// vec2 ndc = gl_FragCoord.xy / viewportSize.xy;
vec2 ndc = clipSpace.xy / clipSpace.w / 2.0 + vec2(0.5, 0.5);
vec2 reflectionUV = vec2(ndc.x, 1.0 - ndc.y) * 0.5;
vec2 refractionUV = vec2(ndc.x, 1.0 - ndc.y) * 0.5 + vec2(0.5, 0.0);
vec4 reflectionColour = texture2D(reflectMap, reflectionUV);
vec4 refractionColour = texture2D(reflectMap, refractionUV);
gl_FragColor = mix(reflectionColour, refractionColour, 0.5);
}
#else
OGRE_UNIFORMS(
uniform float renderTargetFlipping;
uniform vec4 viewportSize;
uniform f32vec4 cameraPosition;
uniform mat4 viewProj2;
uniform float time2;
uniform vec4 materialVariables;
)
float rand(float n){return fract(sin(n) * 43758.5453123);}
float rand2(vec2 n) {
@@ -26,6 +43,11 @@ float noise(vec2 n) {
MAIN_PARAMETERS
IN(f32vec3 positionWS, TEXCOORD0)
IN(f32vec3 vnormal, TEXCOORD1)
IN(f32vec3 viewDirection, TEXCOORD2)
IN(f32vec3 viewDirectionTS, TEXCOORD3)
IN(f32vec3 olightDirection, TEXCOORD4)
IN(f32vec3 lightDirectionTS, TEXCOORD5)
IN(vec2 bumpCoord0, TEXCOORD6)
MAIN_DECLARATION
{
float flip = -renderTargetFlipping;
@@ -37,14 +59,68 @@ MAIN_DECLARATION
screenUV.y = screenUV.y * 0.6 + 0.2;
#endif
vec2 texCoord = 0.001 * positionWS.xz;
vec3 normal = vec3_splat(0.0);
float time = time2 * 0.01;
f32vec2 muv = screenUV * 1.1 + vec2(-0.1, -0.1);
normal += normalize(2.0 * texture2D(noiseMap, vec2(texCoord.x, texCoord.y - 5.0 * time)).rgb - 1.0);
normal += normalize(2.0 * texture2D(noiseMap, vec2(texCoord.y, 1.0 - texCoord.x - 5.0 * time)).rgb - 1.0);
normal += normalize(2.0 * texture2D(noiseMap, vec2(1.0 - texCoord.x, 1.0 - texCoord.y - 5.0 * time)).rgb - 1.0);
normal += normalize(2.0 * texture2D(noiseMap, vec2(1.0 - texCoord.y, texCoord.x - 5.0 * time)).rgb - 1.0);
normal = normalize(normal);
float reflectionDepth = 0.08;
float refractionDepth = 1.05;
vec2 reflectionTexCoord = screenUV + (normal.xy * reflectionDepth) / length(positionWS - cameraPosition.xyz);
vec2 refractionTexCoord = screenUV + normal.xy * refractionDepth;
float depth = saturate(length(positionWS - cameraPosition.xyz) * 0.01);
float nx = sin(noise(vec2(1300.0 + screenUV.x * 48.11, 1100.0 + screenUV.y)));
float ny = sin(noise(vec2(100.0 + screenUV.y * 72.2, 1500.0 + screenUV.x)));
vec4 reflectionColour = texture2D(reflectMap, vec2(nx, ny) + screenUV * vec2(0.5, 1.0));
vec4 refractionColour = texture2D(reflectMap, vec2(nx, ny) + screenUV * vec2(0.5, 1.0) + vec2(0.5, 0.0));
vec4 t0 = texture2D(noiseMap, bumpCoord0) * 2.0 - 1.0;
vec4 t1 = texture2D(noiseMap, bumpCoord0 + vec2(0.75, 0.02)) * 2.0 - 1.0;
vec4 t2 = texture2D(noiseMap, bumpCoord0 + vec2(0.33, 0.11)) * 2.0 - 1.0;
vec4 N = vec4(t0.xyz + t1.xyz + t2.xyz, 1);
N = normalize(viewProj2 * N) * 0.1;
vec4 mrow = vec4(screenUV.x, 0, screenUV.y, 1);
vec4 mrowt = mul(viewProj2, mrow);
f32vec2 e = vec2(0, 0);
float min_speed = 16.0;
float max_ax = 0.01;
float max_ay = 0.005;
float px = noise(vec2(screenUV.x * 13123.0, screenUV.y * 1121.0));
float py = noise(vec2(screenUV.y * 15123.0, screenUV.x * 1421.0));
float offsetx = 0.0;
float offsety = 0.0;
float l = length(positionWS - cameraPosition.xyz);
for (int i = 0; i < 4; i++) {
e.x += sin(mrow.z * min_speed + offsetx + time2 * 0.01) * max_ax * (1.0 + 1.0 / (1.0 + l * 30.0));
e.y += cos(mrow.x * min_speed + offsety + time2 * 0.01) * max_ay;
offsetx += 113.0;
offsety += 78.0;
min_speed *= 2.45;
max_ax *= 0.9;
max_ay *= 0.9;
}
f32vec2 reflectUV = /* screenUV + e */ reflectionTexCoord;
f32vec2 refractUV = /* screenUV + e */ refractionTexCoord;
reflectUV.x = (reflectUV.x < 0.05 ) ? 0.05 : reflectUV.x;
reflectUV.x = (reflectUV.x > 0.95 ) ? 0.95 : reflectUV.x;
f32vec2 uv_mul = vec2(0.5, 1.0);
f32vec2 uv_offset = vec2(0.5, 0.0);
vec4 reflectionColour = texture2D(reflectMap, reflectUV * uv_mul);
vec4 refractionColour = texture2D(reflectMap, refractUV * uv_mul + uv_offset);
if (reflectionColour.a == 0.0) {
reflectionColour = texture2D(reflectMap, screenUV * uv_mul);
}
if (refractionColour.a == 0.0) {
refractionColour = texture2D(reflectMap, screenUV * uv_mul + uv_offset);
}
vec4 result = mix(mix(reflectionColour, refractionColour, 0.5), vec4(0.0, 1.0, 1.0, 1.0), depth);
float mul = dot(vec3(0.0, 1.0, 0.0), vnormal);
result = result * mul;
result.a = 1.0;
gl_FragColor = result;
}
#endif

View File

@@ -58,10 +58,29 @@ material Water/Below
}
}
rtshader_system
{
{
// Override lighting stage with per pixel lighting.
lighting_stage per_pixel
}
}
}
*/
material Water/Depth
{
technique
{
pass
{
cull_hardware none
alpha_rejection greater_equal 0.5
vertex_program_ref Water/depth_vp
{
param_named_auto world world_matrix
param_named_auto worldViewProj worldviewproj_matrix
}
fragment_program_ref Water/depth_fp
{
param_named_auto cameraPosition camera_position
}
}
}
}

View File

@@ -17,6 +17,7 @@ fragment_program Water/depth_fp glsl glsles glslang hlsl
}
}
/*
fragment_program Water/water_fp glsl glsles glslang hlsl
{
source water.frag
@@ -24,10 +25,12 @@ fragment_program Water/water_fp glsl glsles glslang hlsl
{
param_named_auto renderTargetFlipping render_target_flipping
param_named_auto cameraPosition camera_position
param_named_auto viewProj2 viewproj_matrix
// param_named_auto ambient surface_ambient_colour
// param_named_auto diffuse surface_diffuse_colour
param_named_auto viewportSize viewport_size
//// param_named_auto time time
// param_named_auto time2 time
param_named_auto time2 time_0_x 100.0
//// param_named NormalMap int 0
//// param_named EnvironmentMap int 1
// param_named deepColor float4 0 0.2 0.5 1.0
@@ -47,9 +50,11 @@ fragment_program Water/water_fp glsl glsles glslang hlsl
// param_named hdrMultiplier float 0.471
// param_named tintColour float4 0 0.05 0.05 1
// param_named noiseScale float 0.03
//// param_named noiseMap int 0
param_named reflectMap int 0
param_named noiseMap int 1
//// param_named refractMap int 1
param_named_auto materialVariables custom 1
preprocessor_defines NEW_WATER_SHADER
}
}
@@ -68,12 +73,36 @@ vertex_program Water/water_vp glsl glsles glslang hlsl
param_named BumpScale float 0.2
param_named textureScale float2 25 26
param_named bumpSpeed float2 0.015 0.005
param_named_auto time time_0_x 100.0
param_named_auto time time_0_x 100.0
param_named waveFreq float 0.5
param_named waveAmp float 1.0
param_named_auto cameraPositionOS camera_position_object_space
param_named_auto lightDirection light_direction_object_space 0
param_named scroll float 1
param_named scale float 1
param_named noise float 1
preprocessor_defines NEW_WATER_SHADER
}
}
*/
fragment_program Water/water_fp glsl glsles glslang hlsl
{
source water.frag
default_params
{
}
preprocessor_defines NEW_WATER_SHADER
}
vertex_program Water/water_vp glsl glsles glslang hlsl
{
source water.vert
default_params
{
param_named_auto projectionMatrix projection_matrix
param_named_auto viewMatrix view_matrix
param_named_auto modelMatrix world_matrix
}
preprocessor_defines NEW_WATER_SHADER
}

View File

@@ -22,6 +22,22 @@ Comments:
OGRE_NATIVE_GLSL_VERSION_DIRECTIVE
#include <OgreUnifiedShader.h>
#if NEW_WATER_SHADER
OGRE_UNIFORMS(
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform mat4 modelMatrix;
)
MAIN_PARAMETERS
IN(vec4 position, POSITION)
OUT(vec4 clipSpace, TEXCOORD0)
MAIN_DECLARATION
{
clipSpace = projectionMatrix * viewMatrix * modelMatrix * vec4(position.xyz, 1.0);
gl_Position = clipSpace;
}
#else
OGRE_UNIFORMS(
uniform vec3 eyePosition;
uniform float BumpScale;
@@ -30,12 +46,14 @@ uniform vec2 bumpSpeed;
uniform highp float time;
uniform float waveFreq;
uniform float waveAmp;
uniform vec4 cameraPositionOS;
uniform mat4 world;
uniform mat4 viewProj;
uniform mat4 worldView;
uniform mat4 worldViewProj;
uniform mat4 textureProjMatrix;
uniform mat3 normalMatrix;
uniform vec3 lightDirection;
uniform float scale; // the amount to scale the noise texture by
uniform float scroll; // the amount by which to scroll the noise
uniform float noise; // the noise perturb as a factor of the time
@@ -89,30 +107,46 @@ vec4 wave2(vec4 parameter, vec2 position, float t, inout vec3 tangent, inout vec
MAIN_PARAMETERS
IN(vec4 vertex, POSITION)
IN(vec3 normal, NORMAL)
IN(vec3 tangent, TANGENT)
IN(vec4 uv0, TEXCOORD0)
OUT(f32vec3 positionWS, TEXCOORD0)
OUT(f32vec3 vnormal, TEXCOORD1)
OUT(f32vec3 vbinormal, TEXCOORD2)
OUT(f32vec3 vtangent, TEXCOORD3)
OUT(float vertex_height, TEXCOORD4)
OUT(f32vec3 viewDirection, TEXCOORD2)
OUT(f32vec3 viewDirectionTS, TEXCOORD3)
OUT(f32vec3 olightDirection, TEXCOORD4)
// OUT(f32vec3 vbinormal, TEXCOORD2)
// OUT(f32vec3 vtangent, TEXCOORD3)
// OUT(float vertex_height, TEXCOORD4)
OUT(f32vec3 lightDirectionTS, TEXCOORD5)
OUT(f32vec2 bumpCoord0, TEXCOORD6)
MAIN_DECLARATION
{
float textureScale = 0.6;
float bumpSpeed = 0.8;
f32vec4 position = vec4(mul(world, vertex).xyz, 1.0);
f32vec3 vertex_position = position.xyz;
f32vec3 tang = vec3(0.0, 0.0, 0.0);
f32vec3 bin = vec3(0.0, 0.0, 0.0);
f32vec3 tang = tangent;
f32vec3 bin = cross(tangent, normal);
position += wave(wave_a, vertex_position.xz, time, tang, bin);
position += wave(wave_b, vertex_position.xz, time, tang, bin);
position += wave(wave_c, vertex_position.xz, time, tang, bin);
position += wave(wave_d, vertex_position.xz, time, tang, bin);
vtangent = tang;
vbinormal = bin;
vertex_position = position.xyz;
// vtangent = tang;
// vbinormal = bin;
// vertex_position = position.xyz;
// vnormal = normalize(mul(mat3(world), cross(vbinormal, vtangent)));
vnormal = normalize(cross(vbinormal, vtangent));
vnormal = normalize(cross(bin, tang));
mat3 TBN = mtxFromRows(tang, bin, vnormal);
// vnormal = normalize(vec3(0.0, 1.0, 0.0));
// gl_Position = mul(worldViewProj, vertex);
viewDirection = vertex.xyz - cameraPositionOS.xyz;
viewDirectionTS = mul(TBN, viewDirection);
olightDirection = lightDirection;
lightDirectionTS = mul(TBN, lightDirection);
gl_Position = mul(viewProj, position);
positionWS = mul(world, vertex).xyz;
bumpCoord0.xy = uv0.xy * textureScale + time * bumpSpeed;
}
#endif