//**************************************************************************/ // Copyright (c) 2015 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 Ambien Occlution --random sphere samples. // The large array data struct is slower than texture accessing, especially OpenGL core profile. // Normally, DX11 & OpenGL array accessing has the same performance with texture accessing. // We can define the macro "USE_ARRAY_LOOK_UP" to try it out. // By default we get the random sphere samples from texture sampling. #ifndef _SSAO_SAMPLES_OGSFH_ #define _SSAO_SAMPLES_OGSFH_ #if USE_ARRAY_LOOK_UP GLSLShader SSAO_Sample { vec3 GetOffset(int id) { // The array of sampling offsets, which are the random vector(locations) inside the unit sphere. vec3 gOffsets[64] = vec3[64] ( vec3(0.0792077, 0.0144504, 0.0277842), vec3(0.097627, 0.185689, 0.430379), vec3(0.089766, 0.694503, -0.152690), vec3(0.247127, 0.291788, -0.231237), vec3(-0.124826, -0.404931, 0.783546), vec3(0.363641, -0.100100, -0.280984), vec3(0.226127, -0.125936, 0.804697), vec3(0.152315, -0.207803, 0.184084), vec3(0.360111, -0.105749, -0.101605), vec3(0.627596, -0.176360, -0.206989), vec3(0.287980, -0.210261, -0.152290), vec3(0.432149, 0.320347, -0.424018), vec3(0.181746, 0.103633, 0.148651), vec3(-0.264876, -0.805480, -0.128270), vec3(-0.253419, -0.092915, -0.159849), vec3(0.459981, 0.499998, -0.656741), vec3(-0.321192, 0.042073, -0.020902), vec3(0.587395, -0.073098, -0.552151), vec3(-0.376110, 0.108485, -0.203558), vec3(-0.575219, -0.580312, -0.555114), vec3(-0.092606, 0.354163, 0.073158), vec3(0.214090, 0.793343, 0.429394), vec3(0.291569, 0.176634, -0.350634), vec3(0.662097, 0.039422, 0.257964), vec3(0.408949, -0.207881, -0.073700), vec3(0.130843, 0.680857, -0.633440), vec3(0.024787, -0.028745, 0.160894), vec3(0.212951, -0.323682, -0.563194), vec3(-0.027681, 0.260896, 0.417096), vec3(0.748576, -0.003720, -0.413959), vec3(-0.281457, -0.333710, -0.201002), vec3(-0.837797, -0.396338, -0.185518), vec3(-0.047046, -0.396803, -0.024131), vec3(0.391251, 0.705270, -0.432962), vec3(-0.083722, 0.006855, 0.181968), vec3(0.243357, 0.151502, 0.726045), vec3(-0.289262, -0.112243, -0.286586), vec3(-0.216451, -0.967343, 0.063698), vec3(-0.151822, -0.004644, 0.109376), vec3(-0.144331, -0.425897, 0.645119), vec3(0.476781, 0.004779, 0.110723), vec3(0.097038, 0.734579, 0.039286), vec3(0.361029, 0.060178, 0.244769), vec3(-0.590153, 0.354229, -0.316604), vec3(0.278055, 0.352485, 0.096723), vec3(0.758470, -0.454634, 0.087356), vec3(0.370184, 0.019614, 0.297197), vec3(-0.115929, 0.982283, 0.039905), vec3(0.430416, 0.057880, 0.046013), vec3(-0.650683, 0.327732, -0.344024), vec3(-0.381497, -0.044707, -0.193564), vec3(-0.432000, 0.266124, -0.523173), vec3(0.184161, -0.325045, -0.136430), vec3(-0.290988, -0.806392, 0.314040), vec3(-0.313217, 0.304618, 0.182054), vec3(0.643437, 0.318353, -0.194466), vec3(-0.457773, -0.058758, -0.053620), vec3(-0.768332, -0.040492, -0.085882), vec3(0.278374, -0.237206, -0.201678), vec3(-0.956053, -0.136480, -0.250495), vec3(0.425854, -0.134032, -0.146113), vec3(0.056468, -0.396615, -0.301119), vec3(-0.270911, -0.088203, 0.002126), vec3(0.284703, -0.247222, -0.491950) ); return gOffsets[id].xyz; } } // Use texture lookup #else // SSAO sample texture is a 64x1 texture which stores the random sphere samples uniform texture2D gSSAOSampleTex < string UIName = "SSAO Sample Texture"; string ResourceName = "SSAOSample.bmp"; >; // The random texture2D sampler. uniform sampler2D gSSAOSampleSamp = sampler_state { Texture = ; }; GLSLShader SSAO_Sample { vec3 GetOffset(int id) { #if GL_ES vec3 raw = texture2D(gSSAOSampleSamp, vec2((float(id)+0.5)/64.0,0.5)).rgb; #else vec3 raw = texelFetch(gSSAOSampleSamp, ivec2(id,0), 0).rgb; #endif return raw*2.0 - 1.0; } } #endif #endif //_SSAO_SAMPLES_OGSFH_