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
/****************************************************************************/
/* Copyright (c) 2011, Ola Olsson
*
* 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.
*/
/****************************************************************************/
/**
* Derived / Ported from hlsl code included with the Intel 2010 talk
* 'Deferred Rendering for Current and Future Rendering Pipelines'
* http://visual-computing.intel-research.net/art/publications/deferred_rendering/
*/
// Original copyright notice:

// Copyright 2010 Intel Corporation
// All Rights Reserved
//
// Permission is granted to use, copy, distribute and prepare derivative works of this
// software for any purpose and without fee, provided, that the above copyright notice
// and this statement appear in all copies.  Intel makes no representations about the
// suitability of this software for any purpose.  THIS SOFTWARE IS PROVIDED "AS IS."
// INTEL SPECIFICALLY DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, AND ALL LIABILITY,
// INCLUDING CONSEQUENTIAL AND OTHER INDIRECT DAMAGES, FOR THE USE OF THIS SOFTWARE,
// INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PROPRIETARY RIGHTS, AND INCLUDING THE
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  Intel does not
// assume any responsibility for any errors which may appear in this software nor any
// responsibility to update it.

#ifndef _ClipRegion_h_
#define _ClipRegion_h_

#include "Core/Math/Headers/MathClasses.h"

namespace Divide {

//--------------------------------------------------------------------------------------
// Bounds computation utilities, similar to PointLightBounds.cpp
void updateClipRegionRoot(F32 nc,          // Tangent plane x/y normal coordinate (view space)
                          F32 lc,          // Light x/y coordinate (view space)
                          F32 lz,          // Light z coordinate (view space)
                          F32 lightRadius,
                          F32 cameraScale, // Project scale for coordinate (_11 or _22 for x/y respectively)
                          F32 &clipMin,
                          F32 &clipMax)
{
    F32 nz = (lightRadius - nc * lc) / lz;
    F32 pz = (lc * lc + lz * lz - lightRadius * lightRadius) / (lz - (nz / nc) * lc);

    if (pz < 0.0f) {
        F32 c = -nz * cameraScale / nc;
        if (nc < 0.0f) {
            // Left side boundary
            clipMin = std::max(clipMin, c);
        } else {                          // Right side boundary
            clipMax = std::min(clipMax, c);
        }
    }
}

void updateClipRegion(F32 lc,          // Light x/y coordinate (view space)
                      F32 lz,          // Light z coordinate (view space)
                      F32 lightRadius,
                      F32 cameraScale, // Project scale for coordinate (_11 or _22 for x/y respectively)
                      F32 &clipMin,
                      F32 &clipMax)
{
    F32 rSq = lightRadius * lightRadius;
    F32 lcSqPluslzSq = lc * lc + lz * lz;
    F32 d = rSq * lc * lc - lcSqPluslzSq * (rSq - lz * lz);

    if (d >= 0.0f) {
        F32 a = lightRadius * lc;
        F32 b = sqrt(d);
        F32 nx0 = (a + b) / lcSqPluslzSq;
        F32 nx1 = (a - b) / lcSqPluslzSq;

        updateClipRegionRoot(nx0, lc, lz, lightRadius, cameraScale, clipMin, clipMax);
        updateClipRegionRoot(nx1, lc, lz, lightRadius, cameraScale, clipMin, clipMax);
    }
}

// Returns bounding box [min.xy, max.xy] in clip [-1, 1] space.
vec4<F32> computeClipRegion(const vec3<F32>& lightPosView,
                            F32 lightRadius,
                            F32 cameraNear, 
                            const mat4<F32> &projection) {
    // Early out with empty rectangle if the light is too far behind the view frustum
    vec4<F32> clipRegion(1.0f, 1.0f, -1.0f, -1.0f);
    if (lightPosView.z - lightRadius <= -cameraNear) {
        vec2<F32> clipMin(-1.0f, -1.0f);
        vec2<F32> clipMax(1.0f, 1.0f);

        updateClipRegion(lightPosView.x, 
                         lightPosView.z, 
                         lightRadius, 
                         projection.element(1, 1),
                         clipMin.x, 
                         clipMax.x);

        updateClipRegion(lightPosView.y, 
                         lightPosView.z, 
                         lightRadius, 
                         projection.element(2, 2), 
                         clipMin.y,
                         clipMax.y);

        clipRegion.set(clipMin, clipMax);
    }

    return clipRegion;
}

};
#endif // _ClipRegion_h_

Commits for Divide-Framework/trunk/Source Code/Rendering/Headers/ClipRegion.h

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)

318 Diff Diff IonutCava picture IonutCava Sat 30 Aug, 2014 17:35:53 +0000

[Ionut]
- Wrapped the entire code in a “Divide” namespace
- VertexBuffers now call “shrink_to_fit” on all internal data storage
- Improved some vector performance by preferring “emplace_back” instead of “push_back” + proepr usage of reserve / resize
- Wrapped OIS specific types and classes in Divide::Input namespace
- Added the messageBox.layout file (forgot it in the previous few commits)

273 IonutCava picture IonutCava Wed 11 Jun, 2014 20:34:00 +0000

[Ionut] [[BR]]
- Improved batching part2: [[BR]]
— Moved all bone transformation matrices upload from uniform functions in SceneNode to Shader Storage Buffers in AnimationController class with updates controlled by SceneGraphNode’s AnimationComponent [[BR]]
-— No double-buffering or efficient mapping of data yet. Just raw buffer updates [[BR]]
— Replaced all RenderStateBlock* pointers with I64 hash values [[BR]]
-— Will be used later in draw commands as per-shader state hash [[BR]]
— Moved getShaderProgram from Material to Material::ShaderInfo [[BR]]
-— Improved redundant uniform checks [[BR]]
— Improved texture unit changing in case of redundant texture bind case (i.e. skip changing the texture unit) [[BR]]
[[BR]]
- Improved float and double comparison functions using algorithms described in http://randomascii.wordpress.com/2012/02/13/dont-store-that-in-a-float/ [[BR]]
- Added a new utility function, DIVIDE_ASSERT, to more easily bind an assert check with a specific message [[BR]]
- Added missing files from Forward+ renderer’s initial code [[BR]]