//**************************************************************************/ // Copyright (c) 2008 Autodesk, Inc. // All rights reserved. // // These coded instructions, statements, and computer programs contain // unpublished proprietary information written by Autodesk, Inc., and are // protected by Federal copyright law. They may not be disclosed to third // parties or copied or duplicated in any form, in whole or in part, without // the prior written consent of Autodesk, Inc. //**************************************************************************/ // DESCRIPTION: Screen space ambient occlusion - common definitions. // AUTHOR: Mauricio Vives, converted to OGSFX by Eric Haines, July 2013 // CREATED: October 2008 //**************************************************************************/ #ifndef _SSAO_COMMON_MD_FXH_ #define _SSAO_COMMON_MD_FXH_ // The offset of the current tile, relative to the full image. This is (0.0, 0.0) when not tiling. uniform vec2 gTileOffset : TileOffset; // The scale of the current tile, relative to the full image. This is (1.0, 1.0) when not tiling. uniform vec2 gTileScale : TileScale; // Screen size, in pixels. uniform vec2 gScreenSize : ViewportPixelSize ; // World transformation. uniform mat4 gWXf[64] : WorldMD; // World-view-projection transformation. uniform mat4 gWVPXf[64] : WorldViewProjMD; // World-view transformation. uniform mat4 gWVXf[64] : WorldViewMD; // World-view transformation, inverse transpose. uniform mat4 gWVITXf[64] : WorldViewITMD; // Projection transformation and view scale, i.e. view-space size at a distance of one. // NOTE: This need to be the projection transformation of the scene, not the screen quad used for // post-processing. In general, the SSAO effect is split into multiple independent passes, so the // "Projection" semantic is not appropriate and the value must be set manually. For FX Composer, // the SSAO effect is a set of *related* passes in a central technique using SAS scripting, which // include the scene passes, so the "Projection" semantic can be used. // NOTE: The matrix elements used here could be negative, e.g. in a right-handed coordinate system, // so the absolute value is used to get a positive scale. uniform mat4 gProjection; // Whether a perspective view is being used. uniform bool gPerspectiveFlag = false; // The radius of the SSAO samples, as a fracttion of the screen width. uniform float gSampleRadius = 0.1; //////////////////////////////////////////////////////////////////////////////////////////////////// // Screen Quad Vertex Shader //////////////////////////////////////////////////////////////////////////////////////////////////// // Vertex shader input structure. attribute VS_INPUT_ScreenQuad { vec3 Pos : POSITION; vec2 UV : TEXCOORD0; } // Vertex shader output structure. attribute VS_TO_PS_ScreenQuad { vec2 VSUV : TEXCOORD0; vec2 VSUVTile : TEXCOORD1; } attribute pixelOut { vec4 colorOut:COLOR0; } // Vertex shader. // VS_TO_PS_ScreenQuad VS_ScreenQuad(VS_INPUT_ScreenQuad In) GLSLShader VS_ScreenQuad { void main() { // If the origin is the bottom, adjust the tile offset to be relative to the bottom (instead of // the top, which it normally is. vec2 localTileOffset = gTileOffset; #ifdef UV_ORIGIN_BOTTOM // note: GLSL does not allow reassignment of uniform values, so we need a local here localTileOffset.y = 1.0 - gTileOffset.y - gTileScale.y; #endif // Output the position in clip space, and the texture coordinates modified by the tile offset // the scale. The "UV" texture coordinates are thus relative to the *full* image, not the tile. // Also output the unmodified texture coordinates as "UVTile" (the tile texture coordinates). gl_Position = gWVPXf[gl_DrawIDARB]*vec4(Pos, 1.0); VSUV = (UV * gTileScale) + localTileOffset; VSUVTile = UV; } } #endif //_SSAO_COMMON_FXH