Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
-- Vertex

#include "vbInputData.vert"
#include "lightingDefaults.vert"

out flat int _underwater;
out vec3 _pixToEye;
out vec4 _vertexWVP;

void main(void)
{
    computeData();
    
    computeLightVectors();

    _pixToEye  = -VAR._vertexWV.xyz;
    _vertexWVP = dvd_ViewProjectionMatrix * VAR._vertexW;
    _underwater = dvd_cameraPosition.y < VAR._vertexW.y ? 1 : 0;

    gl_Position = _vertexWVP;
}

-- Fragment

in flat int _underwater;
in vec3 _pixToEye;
in vec4 _vertexWVP;

layout(location = 0) out vec4 _colourOut;
layout(location = 1) out vec2 _normalOut;
layout(location = 2) out vec2 _velocityOut;

uniform vec2 _noiseTile;
uniform vec2 _noiseFactor;
uniform float _waterShininess;

#include "lightInput.cmn"
#include "materialData.frag"
#include "shadowMapping.frag"
#include "velocityCalc.frag"

float Fresnel(in vec3 viewDir, in vec3 normal) {
    return _underwater == 1 ? 1.0 : 1.0 / pow(1.0 + dot(viewDir, normal), 5);
}

void main (void)
{  
#   define texWaterReflection texReflectPlanar
#   define texWaterRefraction texRefractPlanar
#   define texWaterNoiseNM texDiffuse0
#   define texWaterNoiseDUDV texDiffuse1

    _noiseFactor = vec2(0.0, 0.0);

    dvd_private_light = dvd_LightSource[0];
    float time2 = float(dvd_time) * 0.00001;
    const float kDistortion = 1.0;// 0.015;
    vec4 distOffset = texture(texWaterNoiseDUDV, VAR._texCoord + vec2(time2)) * kDistortion;

    vec4 uvReflection = _vertexWVP / _vertexWVP.w;
    uvReflection += vec4(1.0);
    uvReflection *= vec4(0.5);
    uvReflection = clamp(uvReflection, vec4(0.001), vec4(0.999));

    vec3 normal = texture(texWaterNoiseNM, vec2(VAR._texCoord + distOffset.xy)).rgb;
    normal = normalize(normal * 2.0 - 1.0);

    vec2 uvFinalReflect = uvReflection.xy + _noiseFactor * normal.xy;
    vec2 uvFinalRefract = uvReflection.xy + _noiseFactor * normal.xy;

    vec3 N = normalize(dvd_NormalMatrixWV(VAR.dvd_instanceID) * normal);
    vec3 L = normalize(-(dvd_private_light._positionWV.xyz));
    vec3 V = normalize(_pixToEye);

    float iSpecular = pow(clamp(dot(normalize(reflect(-L, N)), V), 0.0, 1.0), _waterShininess);

    // add Diffuse
    _colourOut.rgb = mix(texture(texWaterReflection, uvFinalRefract).rgb, 
                         texture(texWaterRefraction, uvFinalReflect).rgb,
                         vec3(clamp(Fresnel(V, normalize(VAR._normalWV)), 0.0, 1.0)));

    // add Specular
    _colourOut.rgb = clamp(_colourOut.rgb + dvd_private_light._colour.rgb * getSpecular() * iSpecular, vec3(0.0), vec3(1.0));
    _normalOut = packNormal(N);
    _velocityOut = velocityCalc(dvd_InvProjectionMatrix, getScreenPositionNormalised());
}

Commits for Divide-Framework/trunk/assets/shaders/GLSL/water.glsl

Diff revisions: vs.
Revision Author Commited Message
926 Diff Diff IonutCava picture IonutCava Fri 04 Aug, 2017 14:06:17 +0000

[Ionut]
- Rename material custom textures to external textures and make sure we properly provide all needed textures for depth stages

899 Diff Diff IonutCava picture IonutCava Fri 23 Jun, 2017 15:37:44 +0000

[IonutCava]
- Move sRGB conversion and fog calculation to post-processing stages (fog in postProcessing using the depth buffer and sRGB in the presentToScreen step)
- Split the bloom.glsl file into multiple shaders: bloom, tonemap and luminanceCalc for ease of use purposes
- Rework RenderBin sorting: sort translucent/transparent nodes by material in depth passes
- Sort order is no longer part of RenderBin for better control

889 Diff Diff IonutCava picture IonutCava Tue 04 Apr, 2017 16:01:34 +0000

[IonutCava]
- Rework uniform passing/caching to better work with shader recompilation
- Cleanup shaders a bit for better performance

880 Diff Diff IonutCava picture IonutCava Mon 20 Mar, 2017 17:27:13 +0000

[IonutCava]
- New tessellated terrain system based on this: http://victorbush.com/2015/01/tessellated-terrain/
— Work in progress: hardcoded values, new code is in Test namespace
- Split terrain geometry in two:
— tessellated rendering data
— physics verts + indices (used for collisions, vegetation, etc)
- Old Chunk system is used only for culling objects and speeding up collision detection

877 Diff Diff IonutCava picture IonutCava Thu 16 Mar, 2017 21:55:59 +0000

[IonutCava]
- Reflection updates
- Sky parallax fixes
- Initial support for Tessellation patches (used by the new terrain system – W.I.P.)

853 Diff Diff IonutCava picture IonutCava Tue 07 Feb, 2017 21:43:58 +0000

[IonutCava]
- More work on water rendering.

850 Diff Diff IonutCava picture IonutCava Mon 06 Feb, 2017 17:04:39 +0000

[IonutCava]
- More code rot fixes
- Separate Planar reflectors/refractors from Cube R/R
- Now passing detail levels to shaders

847 Diff Diff IonutCava picture IonutCava Sun 05 Feb, 2017 21:16:24 +0000

[IonutCava]
- Code rot fixes:
— Terrain loading (8 bit heightmap only for now)
— Terrain rendering
— Water Plane loading and rendering
— Reflection and Refraction rendering passes (hack for now: need environment cubemaps as separate from reflect/refract maps for planar rendering)
-— ToDo: Separate Reflection / Refraction render targets to Planar R/R and Cube R/R. Environment probes should use Cube Reflections, Water should use planar reflection targets.
- Added a way to register debug views: texture, shader and params. Viewports get automatically scaled and positioned
— ToDo: Add a hover-preview feature
— ToDo: Add a click-lock preview feature

791 Diff Diff IonutCava picture IonutCava Thu 17 Nov, 2016 16:46:19 +0000

[IonutCava]
- Reworked PostFX filter list to allow multiple enable calls to the same effect (stack based)
- Added noise, vignette and underwater effects to the filter list available for PostFX
- Added better underwater camera detection

758 IonutCava picture IonutCava Tue 02 Aug, 2016 16:05:09 +0000

[IonutCava]
- Added a cross platform method of naming threads (helps with debugging)
- Reduced dependency on VAR.dvd_drawID in shaders.
- Work on Single/Multi thread toggle for GFX resource loading (crashes, bugs, etc)
- Fix a bug in TaskPool where task states were never actually updated properly
- Change threadpool implementation to use std::thread instead of boost::thread