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
--Vertex

void main(void)
{
}

--Geometry

layout(points) in;
layout(triangle_strip, max_vertices = 4) out;

out vec2 _texCoord;

void main() {
    gl_Position = vec4(1.0, 1.0, 0.0, 1.0);
    _texCoord = vec2(1.0, 1.0);
    EmitVertex();

    gl_Position = vec4(-1.0, 1.0, 0.0, 1.0);
    _texCoord = vec2(0.0, 1.0);
    EmitVertex();

    gl_Position = vec4(1.0, -1.0, 0.0, 1.0);
    _texCoord = vec2(1.0, 0.0);
    EmitVertex();

    gl_Position = vec4(-1.0, -1.0, 0.0, 1.0);
    _texCoord = vec2(0.0, 0.0);
    EmitVertex();

    EndPrimitive();
}

-- Fragment

/****************************************************************************/
/* Copyright (c) 2011, Ola Olsson, Ulf Assarsson
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
/****************************************************************************/
uniform mat4 dvd_ProjectionMatrixInverse;
uniform vec2 dvd_invScreenDimension;
uniform sampler2D depthTex;

out vec2 resultMinMax;

vec3 unProject(vec2 fragmentPos, float fragmentDepth)
{
  vec4 pt = dvd_ProjectionMatrixInverse * 
            vec4(fragmentPos.x * 2.0 - 1.0, 
                 fragmentPos.y * 2.0 - 1.0, 
                 2.0 * fragmentDepth - 1.0, 
                 1.0);

  return vec3(pt.x, pt.y, pt.z) / pt.w;
}


vec3 fetchPosition(vec2 p, float d)
{
  vec2 fragmentPos = vec2(p.x * dvd_invScreenDimension.x, p.y * dvd_invScreenDimension.y);
  return unProject(fragmentPos, d);
}

void main()
{
    vec2 minMax = vec2(1.0f, -1.0f);
    ivec2 offset = ivec2(gl_FragCoord.xy) * ivec2(LIGHT_GRID_TILE_DIM_X, LIGHT_GRID_TILE_DIM_Y);
    ivec2 end = min(ivec2(dvd_ViewPort.z, dvd_ViewPort.w), offset + ivec2(LIGHT_GRID_TILE_DIM_X, LIGHT_GRID_TILE_DIM_Y));

    // Note: with large tiles and many samples this shader makes very poor use of 
    // graphics hardware paralellism. A few shader threads will perform a lot of sequential 
    // work, and on top of this, access memory in a fairly nasty pattern. 
    for (int j = offset.y; j < end.y; ++j)
    {
        for (int i = offset.x; i < end.x; ++i)
        {
          float d = texelFetch(depthTex, ivec2(i,j), 0).x;
            if (d < 1.0)
            {
                minMax.x = min(minMax.x, d);
                minMax.y = max(minMax.y, d);
            }
        }
    }

    // somewhat roundabout way to get to view space depth (note: this is NOT the dodgy part of this process 
    // see above... :).
    minMax = vec2(fetchPosition(vec2(0.0, 0.0), minMax.x).z, fetchPosition(vec2(0.0, 0.0), minMax.y).z);
    resultMinMax = minMax;
}

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

Diff revisions: vs.
Revision Author Commited Message
331 Diff Diff IonutCava picture IonutCava Sat 06 Dec, 2014 20:53:45 +0000

[Ionut]
- Limited line length to 132 characters to improve readability and diff-comparisons
- Refactored memory allocation/deallocation functions
- Fixed a few compatibility issues with HashMap.h
- Fixed a bug in GPU Skinning shaders (cast a float to int)

329 Diff Diff IonutCava picture IonutCava Tue 07 Oct, 2014 12:51:37 +0000

[Ionut]
- Modified material class and shaders to support multiple BRDFs (currently, only Flat, Phong and Blinn-Phong supported with Cook-Torrance and Oren-Nayar in future commits)
- Optimized transform updates and queries
- Fixed an indirect draw command (no buffer was bound to GL_DRAW_INDIRECT_BUFFER, violating a core requirement)

327 Diff Diff IonutCava picture IonutCava Thu 02 Oct, 2014 12:32:15 +0000

[Ionut]
- Removed specular color from lights (specular color should be identical to light’s diffuse color anyway)
- Doublesided materials use their own shader defines now
- Fixed a bug in the particle shader related to screen dimensions never being passed
- Disabled material loading from XML for Primitive type geometry

277 Diff Diff IonutCava picture IonutCava Tue 17 Jun, 2014 19:27:29 +0000

[Ionut] [[BR]]
- Change PostFX shader to be subroutine-based (instead of using if-else statements) [[BR]]

272 IonutCava picture IonutCava Wed 11 Jun, 2014 11:30:51 +0000

[Ionut] [[BR]]
- Added initial code for Forward+ rendering (grid based light culling) [[BR]]
- Simplified Light class [[BR]]
- Moved more light uniform data to ShaderBuffers [[BR]]
- Double buffered grass rendering [[BR]]
- Added a better attribute interface to GenericVertexData [[BR]]
- Fixed screenshot capture [[BR]]
- Fixed texture double-bind checks [[BR]]