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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#ifndef _MATERIAL_DATA_FRAG_
#define _MATERIAL_DATA_FRAG_

#include "utility.frag"

//Ref: https://github.com/urho3d/Urho3D/blob/master/bin/CoreData/Shaders/GLSL/PBRLitSolid.glsl
#if defined(USE_OPACITY_DIFFUSE) || defined(USE_OPACITY_MAP) || defined(USE_OPACITY_DIFFUSE_MAP)
#   define HAS_TRANSPARENCY
#endif

#if !defined(SKIP_TEXTURES)
layout(binding = TEXTURE_UNIT0) uniform sampler2D texDiffuse0;
layout(binding = TEXTURE_UNIT1) uniform sampler2D texDiffuse1;
#endif

layout(binding = TEXTURE_REFLECTION) uniform samplerCubeArray texEnvironmentCube;

//Normal or BumpMap
#if defined(COMPUTE_TBN)
layout(binding = TEXTURE_NORMALMAP) uniform sampler2D texNormalMap;
#endif

//Specular and opacity maps are available even for non-textured geometry
#if defined(USE_OPACITY_MAP)
layout(binding = TEXTURE_OPACITY) uniform sampler2D texOpacityMap;
#endif

#if defined(USE_SPECULAR_MAP)
layout(binding = TEXTURE_SPECULAR) uniform sampler2D texSpecularMap;
#endif

// Debug toggles
#if defined(_DEBUG)
uniform bool dvd_LightingOnly = false;
uniform bool dvd_NormalsOnly = false;
#endif

vec3 private_processedNormal = vec3(0.0, 0.0, 1.0);

vec3 getProcessedNormal() {
    return private_processedNormal;
}

void setProcessedNormal(vec3 normal) {
    private_processedNormal = normal;
}

float Gloss(in vec3 bump, in vec2 texCoord)
{
    #if defined(USE_TOKSVIG)
        // Compute the "Toksvig Factor"
        float rlen = 1.0/saturate(length(bump));
        return 1.0/(1.0 + power*(rlen - 1.0));
    #elif defined(USE_TOKSVIG_MAP)
        float baked_power = 100.0;
        // Fetch pre-computed "Toksvig Factor"
        // and adjust for specified power
        float gloss = texture2D(texSpecularMap, texCoord).r;
        gloss /= mix(power/baked_power, 1.0, gloss);
        return gloss;
    #else
        return 1.0;
    #endif
}

#if !defined(SKIP_TEXTURES)
vec4 getTextureColour(in vec2 uv) {
    #define TEX_NONE 0
    #define TEX_MODULATE 1
    #define TEX_ADD  2
    #define TEX_SUBTRACT  3
    #define TEX_DIVIDE  4
    #define TEX_SMOOTH_ADD  5
    #define TEX_SIGNED_ADD  6
    #define TEX_DECAL  7
    #define TEX_REPLACE  8

#if defined(DEPTH_PASS)
    vec4 colour;
    if (dvd_customData > 0.5) {
        colour = texture(texDiffuse1, uv);
    } else {
        colour = texture(texDiffuse0, uv);
    }
#else
    vec4 colour = texture(texDiffuse0, uv);

    if (dvd_texOperation == TEX_NONE) {
        return colour;
    }

    vec4 colour2 = texture(texDiffuse1, uv);

    // Read from the texture
    switch (dvd_texOperation) {
        default             : colour = vec4(0.7743, 0.3188, 0.5465, 1.0);   break; // <hot pink to easily spot it in a crowd
        case TEX_MODULATE   : colour *= colour2;       break;
        case TEX_REPLACE    : colour  = colour2;       break;
        case TEX_SIGNED_ADD : colour += colour2 - 0.5; break;
        case TEX_DIVIDE     : colour /= colour2;          break;
        case TEX_SUBTRACT   : colour -= colour2;          break;
        case TEX_DECAL      : colour = vec4(mix(colour.rgb, colour2.rgb, colour2.a), colour.a); break;
        case TEX_ADD        : {
            colour.rgb += colour2.rgb;
            colour.a   *= colour2.a;
        }break;
        case TEX_SMOOTH_ADD : {
            colour = (colour + colour2) - (colour * colour2);
        }break;
    }
    
#endif

    return saturate(colour);
}
#endif

float private_getOpacity();
vec4 private_getAlbedo();
vec3 private_getEmissive();
vec3 private_getSpecular();
float private_getShininess();

#if !defined(CUSTOM_MATERIAL_DATA)
float getOpacity() {
    return private_getOpacity();
}

vec4 getAlbedo() {
    return private_getAlbedo();
}
vec3 getEmissive() {
    return private_getEmissive();
}

vec3 getSpecular() {
    return private_getSpecular();
}

float getShininess() {
    return private_getShininess();
}
#else
float getOpacity();
vec4 getAlbedo();
vec3 getEmissive();
vec3 getSpecular();
float getShininess();
#endif

float getRoughness() {
    return 1.0 - saturate(getShininess() / 255.0);
}

float getReflectivity() {
#if defined(USE_SHADING_PHONG) || defined (USE_SHADING_BLINN_PHONG)
    return getShininess();
#elif defined(USE_SHADING_TOON)
    // ToDo - will cause compile error
#else //if defined(USE_SHADING_COOK_TORRANCE) || defined(USE_SHADING_OREN_NAYAR)
    float roughness = getRoughness();
    return roughness * roughness;
#endif
}

vec4 private_getDiffuseColour() {

#   if defined(SKIP_TEXTURES)
        return dvd_Matrices[VAR.dvd_drawID]._colourMatrix[0];
#   else
        return getTextureColour(VAR._texCoord);
#       endif

    return vec4(1.0);
}

#if defined(USE_OPACITY_DIFFUSE_MAP)
float private_pixel_opacity = -1.0;
#endif


float private_getOpacity() {
#if defined(HAS_TRANSPARENCY)

#   if defined(USE_OPACITY_DIFFUSE)
    return dvd_Matrices[VAR.dvd_drawID]._colourMatrix[0].a;
#   endif

#   if defined(USE_OPACITY_MAP)
    vec4 opacityMap = texture(texOpacityMap, VAR._texCoord);
    return max(min(opacityMap.r, opacityMap.g), min(opacityMap.b, opacityMap.a));
#   endif

#   if defined(USE_OPACITY_DIFFUSE_MAP)
    if (private_pixel_opacity < 0) {
        private_pixel_opacity = private_getDiffuseColour().a;
    }

    return private_pixel_opacity;
#   endif

#   endif

    return 1.0;
}

vec4 private_getAlbedo() {
    vec4 albedo = private_getDiffuseColour();

#   if defined(USE_OPACITY_DIFFUSE_MAP)
        private_pixel_opacity = albedo.a;
#   endif

#   if defined(_DEBUG)
        if (dvd_LightingOnly) {
            albedo = vec4(0.0);
        }
#   endif

    albedo.a = getOpacity();

    return albedo;
}

vec3 private_getEmissive() {
    return dvd_Matrices[VAR.dvd_drawID]._colourMatrix[2].rgb;
}

vec3 private_getSpecular() {
#if defined(USE_SPECULAR_MAP)
    return texture(texSpecularMap, VAR._texCoord).rgb;
#else
    return dvd_Matrices[VAR.dvd_drawID]._colourMatrix[1].rgb;
#endif
}

float private_getShininess() {
    return dvd_Matrices[VAR.dvd_drawID]._colourMatrix[2].w;
}

#endif //_MATERIAL_DATA_FRAG_

Commits for Divide-Framework/trunk/assets/shaders/GLSL/fragmentAtoms/materialData.frag

Diff revisions: vs.
Revision Author Commited Message
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

810 Diff Diff IonutCava picture IonutCava Tue 10 Jan, 2017 23:05:48 +0000

[IonutCava]
- Further improve velocity buffer computation
- Fix depth pass texture-transparency issue

756 Diff Diff IonutCava picture IonutCava Fri 29 Jul, 2016 16:09:29 +0000

[IonutCava]
- Cleaned up material shader:
— Add explicit functions for material colour properties
— Separate Phong from PBR
— Remove texture count variable and use TEX_OPERATION_NONE for single texture
- Added a Shader compute queue that all materials share. This allows better frame time allocation for shader compilation
- Attempt to fix Task and TaskPool race conditions

721 Diff Diff IonutCava picture IonutCava Wed 08 Jun, 2016 15:47:49 +0000

[IonutCava]
- Spelling: change all references from our code of “color” to the PROPER British version of “colour” because it sounds 100x better

626 Diff Diff IonutCava picture IonutCava Tue 19 Jan, 2016 17:12:16 +0000

[IonutCava]
- All visual entities have a reflection texture by default and it becomes visible above a certain shininess threshold
- More profile-guided optimizations

621 Diff Diff IonutCava picture IonutCava Tue 12 Jan, 2016 16:39:50 +0000

[IonutCava]
- Terrain rendering updates
- Framebuffer optimizations

583 Diff Diff IonutCava picture IonutCava Tue 24 Nov, 2015 17:13:25 +0000

[IonutCava]
- Shader cleanups:
— Either use opacity map or albedo for transparency. Not both
— Remove material and light property structs. Use function calls.
— Implement emissive color
- Remove pruning of NOP draw commands. OpenGL driver handles that just fine with no (real) overhead.

572 Diff Diff IonutCava picture IonutCava Wed 18 Nov, 2015 17:15:43 +0000

[Ionut]
- Attempt to pack all shadowmaps in Shadowmap arrays
- Cleanup lighting and material info
- Fix light impostor rendering

425 Diff Diff IonutCava picture IonutCava Thu 07 May, 2015 16:03:29 +0000

[Ionut]
- Profile guided optimizations:
— Removed the need for a temporary mat4 in operator*= body
— Optimized addition, subtraction and scalar multiplication for mat4
— Added the possibility to reserve memory for GLIM vectors when BeginBatch is called (reducing the number of mem allocs needed for each vertex specified)
— Transform class' dirty flags moved before locking the mutex to reduce lock duration (dirty flags are atomic booleans anyway)
— GraphPlots can now be created with a name instead of just specifying one later on (avoids useless string allocations)
- Added a Quaternion.inl file to hold actual Quaternion implementation details

420 IonutCava picture IonutCava Mon 04 May, 2015 16:30:23 +0000

[Ionut]
- Bug fixes:
— Upload bone buffers for every rendering stage (not just display). Solves bad shadow pass skinning when the node hasn’t entered the display pass view frustum yet
— Fix translucency check logic in Material and avoid creating an opacity map if it uses the same texture as the albedo map. Transparency will be automatically picked up from the albedo map. Solves transparent materials not discarding the needed pixels.
— Fix camera world matrix retrieval. Solves bad shadow camera computations if the main scene camera isn’t wasn’t moved often.
— Removed DSA_EXT texture update methods and replaced them with normal bind->edit methods. DSA_EXT is still buggy on AMD with Catalyst 15.4b