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

#include "nodeBufferedInput.cmn"

uniform float projectedTextureMixWeight;
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); }
vec3  saturate(vec3 v)  { return clamp(v, 0.0, 1.0); }
vec4  saturate(vec4 v)  { return clamp(v, 0.0, 1.0); }

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);
}

vec3 applyFogColour(in vec3 colour){
    const float LOG2 = 1.442695;
    float zDepth = gl_FragCoord.z / gl_FragCoord.w;
    return mix(dvd_fogColour, colour, clamp(exp2(-dvd_fogDensity * dvd_fogDensity * zDepth * zDepth * LOG2), 0.0, 1.0));
}

vec4 applyFog(in vec4 colour) { 
    return vec4(mix(applyFogColour(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;
}

vec4 positionFromDepth(in float depth,
                       in mat4 invProjectionMatrix,
                       in vec2 uv) {

    vec4 pos = vec4(2.0 * uv.x - 1.0,
                    2.0 * uv.y - 1.0,
                    2.0 * depth - 1.0,
                    1.0);

    pos = invProjectionMatrix * pos;
    pos /= pos.w;

    return pos;
}

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);}


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;
}

#endif //_LIGHTING_DEFAULTS_FRAG_

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

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

673 Diff Diff IonutCava picture IonutCava Sun 10 Apr, 2016 19:26:18 +0000

[IonutCava]
- Use stl_allocator with hashmap
- Various memory allocation tweaks and bug fixes
- Initial Toksvig specular-AA shader code (from http://www.selfshadow.com/sandbox/gloss.html)

614 Diff Diff IonutCava picture IonutCava Mon 21 Dec, 2015 17:07:48 +0000

[IonutCava]
- Framebuffer attachment corrections
- SSAO corrections

609 Diff Diff IonutCava picture IonutCava Fri 18 Dec, 2015 13:05:06 +0000

[IonutCava]
- Postprocessing improvements
- Shadowmapping warning fix (non-depth texture bound to depth sampler)

608 Diff Diff IonutCava picture IonutCava Thu 17 Dec, 2015 17:09:51 +0000

[IonutCava]
- More work on SSAO
- Each render target stores the settings that were used when it was rendered to (fov, projection mat, etc).

606 Diff Diff IonutCava picture IonutCava Tue 15 Dec, 2015 17:16:59 +0000

[IonutCava]
- More post-processing work:
— Average luminance calculation and tonemapping are no longer optional
— Split HDR and LDR based operators into their respective batches
- Allow disabling of specific Framebuffer render targets if needed

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.

576 Diff Diff IonutCava picture IonutCava Fri 20 Nov, 2015 11:54:22 +0000

[IonutCava]
- C++ based Interface block generation for GLSL

566 Diff Diff IonutCava picture IonutCava Sat 14 Nov, 2015 18:34:27 +0000

[IonutCava]
- Cleanup GLSL UBO variables
- Cleanup mat4 class
- Fixed fog rendering
- Disable useless environment mipmap generation step

559 IonutCava picture IonutCava Tue 10 Nov, 2015 16:34:26 +0000

[IonutCava]
- Uniform cleanup:
— Grab most shader uniform calls and batch the data in a scene global shader buffer
- Fix a crash related to environment maps:
— Material instance does not own the REFLECTION texture (unlike the other texture types). Increase the incoming texture’s reference count instead