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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
-- Vertex

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

uniform vec3 bbox_min;
uniform vec3 bbox_extent;

out vec4 _scrollingUV;
smooth out float distance;

smooth out float _waterDepth;

void main(void){

    computeData();

    VAR._texCoord = vec3((VAR._vertexW.xyz - bbox_min) / bbox_extent).sp;

    float minHeight = (worldMat * vec4(0.0, TERRAIN_MIN_HEIGHT, 0.0, 1.0)).y;
    _waterDepth = clamp(1.0 - (dvd_waterPositionsW.y - VAR[index]._vertexW.y) / (dvd_waterPositionsW.y - minHeight), 0.0, 1.0);

    computeLightVectors();

    float time2 = float(dvd_time) * 0.0001;
    vec2 noiseUV = VAR._texCoord * UNDERWATER_DIFFUSE_SCALE;
    _scrollingUV.st = noiseUV;
    _scrollingUV.pq = noiseUV + time2;
    _scrollingUV.s -= time2;

    distance = gl_ClipDistance[0];
    gl_Position = dvd_ViewProjectionMatrix * VAR._vertexW;
}

-- Fragment

#define CUSTOM_MATERIAL_DATA

#include "BRDF.frag"
#include "terrainSplatting.frag"
#include "velocityCalc.frag"

float getOpacity() {
    return 1.0;
}

vec4 private_albedo = vec4(1.0);
void setAlbedo(in vec4 albedo) {
    private_albedo = albedo;
}

vec4 getAlbedo() {
    return private_albedo;
}

vec3 getEmissive() {
    return private_getEmissive();
}

vec3 getSpecular() {
    return private_getSpecular();
}

float getShininess() {
    return private_getShininess();
}

in vec4 _scrollingUV;
smooth in float distance;
smooth in float _waterDepth;

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

vec4 CausticsColour() {
    setProcessedNormal(VAR._normalWV);

    setAlbedo((texture(texWaterCaustics, _scrollingUV.st) +
               texture(texWaterCaustics, _scrollingUV.pq)) * 0.5);

    return getPixelColour(VAR._texCoord);
}

vec4 UnderwaterColour() {

    vec2 coords = VAR._texCoord * UNDERWATER_DIFFUSE_SCALE;
    setAlbedo(texture(texUnderwaterAlbedo, coords));

    vec3 tbn = normalize(2.0 * texture(texUnderwaterDetail, coords).rgb - 1.0);
    setProcessedNormal(getTBNMatrix() * tbn);

    return getPixelColour(VAR._texCoord);
}

vec4 UnderwaterMappingRoutine(){
    return mix(CausticsColour(), UnderwaterColour(), _waterDepth);
}

vec4 TerrainMappingRoutine(){ // -- HACK - Ionut
    setAlbedo(getTerrainAlbedo());

    if (dvd_lodLevel(VAR.dvd_instanceID) == 0 && dvd_renderDetailLevel() > DETAIL_LOW) {
        setProcessedNormal(getTerrainNormal());
    } else {
        setProcessedNormal(VAR._normalWV);
    }

    return getPixelColour(VAR._texCoord);
}

void main(void) {
    bumpInit();

   _colourOut = ToSRGB(applyFog(mix(TerrainMappingRoutine(), UnderwaterMappingRoutine(), min(distance, 0.0))));

   _normalOut = packNormal(getProcessedNormal());
   _velocityOut = velocityCalc(dvd_InvProjectionMatrix, getScreenPositionNormalised());
}

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

Diff revisions: vs.
Revision Author Commited Message
888 Diff Diff IonutCava picture IonutCava Mon 03 Apr, 2017 20:04:19 +0000

[IonutCava]
- Terrain <-> Water body collision checking for caustics

884 Diff Diff IonutCava picture IonutCava Mon 27 Mar, 2017 15:32:26 +0000

[Ionut]
- More terrain work

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

875 Diff Diff IonutCava picture IonutCava Tue 14 Mar, 2017 16:59:38 +0000

[IonutCava]
- Cleanup and optimizations

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

812 Diff Diff IonutCava picture IonutCava Wed 11 Jan, 2017 21:38:18 +0000

[IonutCava]
- Finish terrain shader fixes (AMD GPU related issues)

811 Diff Diff IonutCava picture IonutCava Wed 11 Jan, 2017 17:26:49 +0000

[IonutCava]
- Fix some threadpool cleanup bugs
- Fix terrain rendering (except underwater caustics)
- Fix terrain loading
- Fix terrain unloading

806 Diff Diff IonutCava picture IonutCava Sun 08 Jan, 2017 22:00:48 +0000

[IonutCava]
- Finish implementing per-fragment velocity computation using a compute shader
— Further tuning still needed
- Add VS2017 build targets

770 IonutCava picture IonutCava Tue 20 Sep, 2016 16:12:27 +0000

[IonutCava]
- Prepare velocity map calculation (later used for temporal AA and motion blur):
— Add a previous depth buffer render target that blits the main depth buffer at the end of the frame
— Add a new render target to the screen FBO: velocity map
- Store normals as RG instead of RGB and pack/unpack in shaders. (compute >>>> bandwith)
- Rename Forward+ renderer to something more descriptive

(Requires deletion of all parsed & cached data)