Commit 266f3f65 authored by Dario Seyb's avatar Dario Seyb

improved vignette

parent 97259a3e

Too many changes to show.

To preserve performance only 104 of 104+ files are displayed.
......@@ -23,6 +23,27 @@ vec3 Uncharted2Tonemap(vec3 x)
return ((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F))-E/F;
}
//RADIUS of our vignette, where 0.5 results in a circle fitting the screen
const float RADIUS = 0.65;
//softness of our vignette, between 0.0 and 1.0
const float SOFTNESS = 0.35;
vec3 Vignette(vec3 color) {
//determine center position
vec2 position = vTexCoord - vec2(0.5);
//determine the vector length of the center position
float len = length(position);
//use smoothstep to create a smooth vignette
float vignette = smoothstep(RADIUS, RADIUS-SOFTNESS, len);
//apply the vignette with 50% opacity
return mix(color, color * vignette, 0.8);
}
void main()
{
......@@ -36,8 +57,8 @@ void main()
vec3 whiteScale = vec3(1.0f)/Uncharted2Tonemap(vec3(W));
color = curr*whiteScale;
vec2 centerDist = abs(vTexCoord * 2.0 - 1.0);
color *= length(vec2(1.0) - centerDist);
color = Vignette(color);
vec3 retColor = pow(color, vec3(1.0/2.2));
retColor += vec3(rand(gl_FragCoord.xy) * 1.0/255 - 0.5/255);
......
/*
Original code by Lee Thomason (www.grinninglizard.com)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
#include "tinyxml2.h"
#include <new> // yes, this one new style header, is in the Android SDK.
# ifdef ANDROID_NDK
# include <stddef.h>
#else
# include <cstddef>
#endif
static const char LINE_FEED = (char)0x0a; // all line endings are normalized to LF
static const char LF = LINE_FEED;
static const char CARRIAGE_RETURN = (char)0x0d; // CR gets filtered out
static const char CR = CARRIAGE_RETURN;
static const char SINGLE_QUOTE = '\'';
static const char DOUBLE_QUOTE = '\"';
// Bunch of unicode info at:
// http://www.unicode.org/faq/utf_bom.html
// ef bb bf (Microsoft "lead bytes") - designates UTF-8
static const unsigned char TIXML_UTF_LEAD_0 = 0xefU;
static const unsigned char TIXML_UTF_LEAD_1 = 0xbbU;
static const unsigned char TIXML_UTF_LEAD_2 = 0xbfU;
#define DELETE_NODE( node ) { \
if ( node ) { \
MemPool* pool = node->_memPool; \
node->~XMLNode(); \
pool->Free( node ); \
} \
}
#define DELETE_ATTRIBUTE( attrib ) { \
if ( attrib ) { \
MemPool* pool = attrib->_memPool; \
attrib->~XMLAttribute(); \
pool->Free( attrib ); \
} \
}
namespace tinyxml2
{
struct Entity {
const char* pattern;
int length;
char value;
};
static const int NUM_ENTITIES = 5;
static const Entity entities[NUM_ENTITIES] = {
{ "quot", 4, DOUBLE_QUOTE },
{ "amp", 3, '&' },
{ "apos", 4, SINGLE_QUOTE },
{ "lt", 2, '<' },
{ "gt", 2, '>' }
};
StrPair::~StrPair()
{
Reset();
}
void StrPair::Reset()
{
if ( _flags & NEEDS_DELETE ) {
delete [] _start;
}
_flags = 0;
_start = 0;
_end = 0;
}
void StrPair::SetStr( const char* str, int flags )
{
Reset();
size_t len = strlen( str );
_start = new char[ len+1 ];
memcpy( _start, str, len+1 );
_end = _start + len;
_flags = flags | NEEDS_DELETE;
}
char* StrPair::ParseText( char* p, const char* endTag, int strFlags )
{
TIXMLASSERT( endTag && *endTag );
char* start = p; // fixme: hides a member
char endChar = *endTag;
size_t length = strlen( endTag );
// Inner loop of text parsing.
while ( *p ) {
if ( *p == endChar && strncmp( p, endTag, length ) == 0 ) {
Set( start, p, strFlags );
return p + length;
}
++p;
}
return 0;
}
char* StrPair::ParseName( char* p )
{
char* start = p;
if ( !start || !(*start) ) {
return 0;
}
while( *p && (
XMLUtil::IsAlphaNum( (unsigned char) *p )
|| *p == '_'
|| *p == ':'
|| (*p == '-' && p>start ) // can be in a name, but not lead it.
|| (*p == '.' && p>start ) )) { // can be in a name, but not lead it.
++p;
}
if ( p > start ) {
Set( start, p, 0 );
return p;
}
return 0;
}
void StrPair::CollapseWhitespace()
{
// Trim leading space.
_start = XMLUtil::SkipWhiteSpace( _start );
if ( _start && *_start ) {
char* p = _start; // the read pointer
char* q = _start; // the write pointer
while( *p ) {
if ( XMLUtil::IsWhiteSpace( *p )) {
p = XMLUtil::SkipWhiteSpace( p );
if ( *p == 0 ) {
break; // don't write to q; this trims the trailing space.
}
*q = ' ';
++q;
}
*q = *p;
++q;
++p;
}
*q = 0;
}
}
const char* StrPair::GetStr()
{
if ( _flags & NEEDS_FLUSH ) {
*_end = 0;
_flags ^= NEEDS_FLUSH;
if ( _flags ) {
char* p = _start; // the read pointer
char* q = _start; // the write pointer
while( p < _end ) {
if ( (_flags & NEEDS_NEWLINE_NORMALIZATION) && *p == CR ) {
// CR-LF pair becomes LF
// CR alone becomes LF
// LF-CR becomes LF
if ( *(p+1) == LF ) {
p += 2;
}
else {
++p;
}
*q++ = LF;
}
else if ( (_flags & NEEDS_NEWLINE_NORMALIZATION) && *p == LF ) {
if ( *(p+1) == CR ) {
p += 2;
}
else {
++p;
}
*q++ = LF;
}
else if ( (_flags & NEEDS_ENTITY_PROCESSING) && *p == '&' ) {
// Entities handled by tinyXML2:
// - special entities in the entity table [in/out]
// - numeric character reference [in]
// &#20013; or &#x4e2d;
if ( *(p+1) == '#' ) {
char buf[10] = { 0 };
int len;
p = const_cast<char*>( XMLUtil::GetCharacterRef( p, buf, &len ) );
for( int i=0; i<len; ++i ) {
*q++ = buf[i];
}
TIXMLASSERT( q <= p );
}
else {
int i=0;
for(; i<NUM_ENTITIES; ++i ) {
if ( strncmp( p+1, entities[i].pattern, entities[i].length ) == 0
&& *(p+entities[i].length+1) == ';' ) {
// Found an entity convert;
*q = entities[i].value;
++q;
p += entities[i].length + 2;
break;
}
}
if ( i == NUM_ENTITIES ) {
// fixme: treat as error?
++p;
++q;
}
}
}
else {
*q = *p;
++p;
++q;
}
}
*q = 0;
}
// The loop below has plenty going on, and this
// is a less useful mode. Break it out.
if ( _flags & COLLAPSE_WHITESPACE ) {
CollapseWhitespace();
}
_flags = (_flags & NEEDS_DELETE);
}
return _start;
}
// --------- XMLUtil ----------- //
const char* XMLUtil::ReadBOM( const char* p, bool* bom )
{
*bom = false;
const unsigned char* pu = reinterpret_cast<const unsigned char*>(p);
// Check for BOM:
if ( *(pu+0) == TIXML_UTF_LEAD_0
&& *(pu+1) == TIXML_UTF_LEAD_1
&& *(pu+2) == TIXML_UTF_LEAD_2 ) {
*bom = true;
p += 3;
}
return p;
}
void XMLUtil::ConvertUTF32ToUTF8( unsigned long input, char* output, int* length )
{
const unsigned long BYTE_MASK = 0xBF;
const unsigned long BYTE_MARK = 0x80;
const unsigned long FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
if (input < 0x80) {
*length = 1;
}
else if ( input < 0x800 ) {
*length = 2;
}
else if ( input < 0x10000 ) {
*length = 3;
}
else if ( input < 0x200000 ) {
*length = 4;
}
else {
*length = 0; // This code won't covert this correctly anyway.
return;
}
output += *length;
// Scary scary fall throughs.
switch (*length) {
case 4:
--output;
*output = (char)((input | BYTE_MARK) & BYTE_MASK);
input >>= 6;
case 3:
--output;
*output = (char)((input | BYTE_MARK) & BYTE_MASK);
input >>= 6;
case 2:
--output;
*output = (char)((input | BYTE_MARK) & BYTE_MASK);
input >>= 6;
case 1:
--output;
*output = (char)(input | FIRST_BYTE_MARK[*length]);
default:
break;
}
}
const char* XMLUtil::GetCharacterRef( const char* p, char* value, int* length )
{
// Presume an entity, and pull it out.
*length = 0;
if ( *(p+1) == '#' && *(p+2) ) {
unsigned long ucs = 0;
ptrdiff_t delta = 0;
unsigned mult = 1;
if ( *(p+2) == 'x' ) {
// Hexadecimal.
if ( !*(p+3) ) {
return 0;
}
const char* q = p+3;
q = strchr( q, ';' );
if ( !q || !*q ) {
return 0;
}
delta = q-p;
--q;
while ( *q != 'x' ) {
if ( *q >= '0' && *q <= '9' ) {
ucs += mult * (*q - '0');
}
else if ( *q >= 'a' && *q <= 'f' ) {
ucs += mult * (*q - 'a' + 10);
}
else if ( *q >= 'A' && *q <= 'F' ) {
ucs += mult * (*q - 'A' + 10 );
}
else {
return 0;
}
mult *= 16;
--q;
}
}
else {
// Decimal.
if ( !*(p+2) ) {
return 0;
}
const char* q = p+2;
q = strchr( q, ';' );
if ( !q || !*q ) {
return 0;
}
delta = q-p;
--q;
while ( *q != '#' ) {
if ( *q >= '0' && *q <= '9' ) {
ucs += mult * (*q - '0');
}
else {
return 0;
}
mult *= 10;
--q;
}
}
// convert the UCS to UTF-8
ConvertUTF32ToUTF8( ucs, value, length );
return p + delta + 1;
}
return p+1;
}
void XMLUtil::ToStr( int v, char* buffer, int bufferSize )
{
TIXML_SNPRINTF( buffer, bufferSize, "%d", v );
}
void XMLUtil::ToStr( unsigned v, char* buffer, int bufferSize )
{
TIXML_SNPRINTF( buffer, bufferSize, "%u", v );
}
void XMLUtil::ToStr( bool v, char* buffer, int bufferSize )
{
TIXML_SNPRINTF( buffer, bufferSize, "%d", v ? 1 : 0 );
}
void XMLUtil::ToStr( float v, char* buffer, int bufferSize )
{
TIXML_SNPRINTF( buffer, bufferSize, "%g", v );
}
void XMLUtil::ToStr( double v, char* buffer, int bufferSize )
{
TIXML_SNPRINTF( buffer, bufferSize, "%g", v );
}
bool XMLUtil::ToInt( const char* str, int* value )
{
if ( TIXML_SSCANF( str, "%d", value ) == 1 ) {
return true;
}
return false;
}
bool XMLUtil::ToUnsigned( const char* str, unsigned *value )
{
if ( TIXML_SSCANF( str, "%u", value ) == 1 ) {
return true;
}
return false;
}
bool XMLUtil::ToBool( const char* str, bool* value )
{
int ival = 0;
if ( ToInt( str, &ival )) {
*value = (ival==0) ? false : true;
return true;
}
if ( StringEqual( str, "true" ) ) {
*value = true;
return true;
}
else if ( StringEqual( str, "false" ) ) {
*value = false;
return true;
}
return false;
}
bool XMLUtil::ToFloat( const char* str, float* value )
{
if ( TIXML_SSCANF( str, "%f", value ) == 1 ) {
return true;
}
return false;
}
bool XMLUtil::ToDouble( const char* str, double* value )
{
if ( TIXML_SSCANF( str, "%lf", value ) == 1 ) {
return true;
}
return false;
}
char* XMLDocument::Identify( char* p, XMLNode** node )
{
XMLNode* returnNode = 0;
char* start = p;
p = XMLUtil::SkipWhiteSpace( p );
if( !p || !*p ) {
return p;
}
// What is this thing?
// - Elements start with a letter or underscore, but xml is reserved.
// - Comments: <!--
// - Decleration: <?
// - Everthing else is unknown to tinyxml.
//
static const char* xmlHeader = { "<?" };
static const char* commentHeader = { "<!--" };
static const char* dtdHeader = { "<!" };
static const char* cdataHeader = { "<![CDATA[" };
static const char* elementHeader = { "<" }; // and a header for everything else; check last.
static const int xmlHeaderLen = 2;
static const int commentHeaderLen = 4;
static const int dtdHeaderLen = 2;
static const int cdataHeaderLen = 9;
static const int elementHeaderLen = 1;
#if defined(_MSC_VER)