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
#ifndef _LIGHTING_DEFAULTS_FRAG_
#define _LIGHTING_DEFAULTS_FRAG_

#include "nodeBufferedInput.cmn"

uniform float projectedTextureMixWeight;

layout(binding = TEXTURE_DEPTH_MAP) uniform sampler2D texDepthMap;
layout(binding = TEXTURE_PROJECTION) uniform sampler2D texDiffuseProjected;

#define PRECISION 0.000001

float DIST_TO_ZERO(float val) {
    return 1.0 - (step(-PRECISION, val) * (1.0 - step(PRECISION, val)));
}

float saturate(float v) { return clamp(v, 0.0, 1.0); }
vec2  saturate(vec2 v)  { return clamp(v, 0.0, 1.0); }
vec3  saturate(vec3 v)  { return clamp(v, 0.0, 1.0); }
vec4  saturate(vec4 v)  { return clamp(v, 0.0, 1.0); }

float maxComponent(vec2 v) { return max(v.x, v.y); }
float maxComponent(vec3 v) { return max(maxComponent(v.xy), v.z); }
float maxComponent(vec4 v) { return max(maxComponent(v.xyz), v.w); }

float ToLinearDepth(in float depthIn);

float overlay(float x, float y)
{
    if (x < 0.5)
        return 2.0*x*y;
    else
        return 1.0 - 2.0*(1.0 - x)*(1.0 - y);
}

void projectTexture(in vec3 PoxPosInMap, inout vec4 targetTexture){
    vec4 projectedTex = texture(texDiffuseProjected, vec2(PoxPosInMap.s, 1.0-PoxPosInMap.t));
    targetTexture.xyz = mix(targetTexture.xyz, projectedTex.xyz, projectedTextureMixWeight);
}

bool isSamplerSet(sampler2D sampler) {
    return textureSize(sampler, 0).x > 0;
}

vec2 scaledTextureCoords(in vec2 texCoord, in vec2 scaleFactor) {
    return vec2(.5, .5) + ((texCoord - vec2(.5, .5)) * scaleFactor);
}

vec2 scaledTextureCoords(in vec2 texCoord, in float scaleFactor) {
    return scaledTextureCoords(texCoord, vec2(scaleFactor));
}

//Box Projected Cube Environment Mapping by Bartosz Czuba
vec3 bpcem(in vec3 v, vec3 Emax, vec3 Emin, vec3 Epos)
{
    vec3 pos = vec3(1.0);
    //e.g.: vec3 rVec = bpcem(reflect(vVec,nVec),EnvBoxMax,EnvBoxMin,EnvBoxPos); //bpcem-izing reflection coordinates
    //      vec3 env = textureCube(envMap, rVec).rgb;
    vec3 nrdir = normalize(v);
    vec3 rbmax = (Emax - pos) / nrdir;
    vec3 rbmin = (Emin - pos) / nrdir;

    vec3 rbminmax;
    rbminmax.x = (nrdir.x>0.0) ? rbmax.x : rbmin.x;
    rbminmax.y = (nrdir.y>0.0) ? rbmax.y : rbmin.y;
    rbminmax.z = (nrdir.z>0.0) ? rbmax.z : rbmin.z;
    float fa = min(min(rbminmax.x, rbminmax.y), rbminmax.z);
    vec3 posonbox = pos + nrdir * fa;
    return posonbox - Epos;
}

vec3 applyFogColour(in float depth, in vec3 colour){
    const float LOG2 = 1.442695;
    float zDepth = ToLinearDepth(depth);
    return mix(dvd_fogColour, colour, clamp(exp2(-dvd_fogDensity * dvd_fogDensity * zDepth * zDepth * LOG2), 0.0, 1.0));
}

vec4 applyFog(in float depth, in vec4 colour) {
    return vec4(mix(applyFogColour(depth, colour.rgb), colour.rgb, dvd_fogDensity), colour.a);
}

float ToLinearDepth(in float depthIn) {
#if defined(USE_SCENE_ZPLANES)
    float n = dvd_ZPlanesCombined.z;
    float f = dvd_ZPlanesCombined.w * 0.5;
#else
    float n = dvd_ZPlanesCombined.x;
    float f = dvd_ZPlanesCombined.y * 0.5;
#endif

    return (2 * n) / (f + n - (depthIn) * (f - n));
}

float ToLinearDepth(in float depthIn, in mat4 projMatrix) {
    return projMatrix[3][2] / (depthIn - projMatrix[2][2]);
}

bool InRangeExclusive(in float value, in float min, in float max) {
    return value > min && value < max;
}

float luminance(in vec3 rgb) {
    const vec3 kLum = vec3(0.299, 0.587, 0.114);
    return max(dot(rgb, kLum), 0.0001); // prevent zero result
}

const float gamma = 2.2;
const float invGamma = 1.0 / gamma;
const vec3 invGammaVec = vec3(invGamma);
const vec3 gammaVec = vec3(gamma);

float ToLinear(float v) { return pow(v, gamma); }
vec3  ToLinear(vec3 v)  { return pow(v, gammaVec); }
vec4  ToLinear(vec4 v)  { return vec4(pow(v.rgb, gammaVec), v.a); }

float ToSRGB(float v) { return pow(v, invGamma); }
vec3  ToSRGB(vec3 v)  { return pow(v, invGammaVec); }
vec4  ToSRGB(vec4 v)  { return vec4(pow(v.rgb, invGammaVec), v.a);}


vec3 unpackNormal(vec2 packedNormal)
{
    vec3 normal;
    normal.xy = packedNormal.xy * (255.0 / 128.0) - 1.0;
    normal.z = sqrt(1 - normal.x*normal.x - normal.y * normal.y);
    return normal;
}

vec2 packNormal(vec3 normal)
{
    return vec2(normal.xy * 0.5 + 0.5);
}

float Gloss(vec3 bump)
{
    float gloss = 1.0;

    /*if (do_toksvig)
    {
        // Compute the "Toksvig Factor"
        float rlen = 1.0 / saturate(length(bump));
        gloss = 1.0 / (1.0 + power*(rlen - 1.0));
    }

    if (do_toksmap)
    {
        // Fetch pre-computed "Toksvig Factor"
        // and adjust for specified power
        gloss = texture2D(gloss_map, texcoord).r;
        gloss /= mix(power / baked_power, 1.0, gloss);
    }
    */
    return gloss;
}

vec2 getScreenPositionNormalised() {
    return gl_FragCoord.xy * dvd_invScreenDimensions();
}

float private_depth = -1.0;
float getDepthValue(vec2 screenNormalisedPos) {
    if (private_depth < 0.0) {
        private_depth = textureLod(texDepthMap, screenNormalisedPos, 0).r;
    }

    return private_depth;
}
#endif //_LIGHTING_DEFAULTS_FRAG_

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

Diff revisions: vs.
Revision Author Commited Message
912 Diff Diff IonutCava picture IonutCava Sun 02 Jul, 2017 23:42:39 +0000

[Ionut]
- Add experimental Weighted Blended Order Independed Transparency (ref: http://casual-effects.blogspot.co.uk/2015/03/implemented-weighted-blended-order.html)
— Add per drawbuffer blend
— All translucent renderbin items go via the new OIT 2-step rendering: accumulation and composition
- Make sure we have proper blend enabled for text rendering
- Add a primitive form of PushConstants (unused yet. Emulated via Uniform calls)
- Fix bug with XMLParser not using case insensitive key lookups

901 Diff Diff IonutCava picture IonutCava Fri 23 Jun, 2017 20:20:21 +0000

[Ionut]
- Fix shader issues in previous commit
- Fix splash screen gamma issue

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

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

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

809 Diff Diff IonutCava picture IonutCava Tue 10 Jan, 2017 17:16:26 +0000

[IonutCava]
- Move velocity calc to the normal colour pass.
- Optimise glFramebuffer and cleanup RTAttachment class

800 Diff Diff IonutCava picture IonutCava Fri 25 Nov, 2016 17:04:02 +0000

[IonutCava]
- More profile-guided optimizations
- Added GLSL normal map blending methods from: http://blog.selfshadow.com/sandbox/normals.html
- Added more profile timers

770 Diff Diff 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)

756 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