Skip to content
Snippets Groups Projects
Commit 3fe7f8e1 authored by Stefano Nardo's avatar Stefano Nardo Committed by Sandro Weber
Browse files

Merged in NRRPLT-7975-add-missing-gazebo-materials (pull request #40)

[NRRPLT-7975] Add gazebo materials

* [NRRPLT-7975] Add gazebo materials

* [NRRPLT-7975] add gazebo material

* [NRRPLT-7975] Add textures

* [NRRPLT-7975] Fix folders

Approved-by: Sandro Weber
Approved-by: Manos Angelidis
parent 0f45dc18
No related branches found
No related tags found
No related merge requests found
Showing
with 836 additions and 0 deletions
// Simple vertex shader; just setting things up for the real work to be done in
// camera_distortion_fs.glsl.
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0;
}
// This fragment shader will add Gaussian noise to a rendered image. It's
// intended to be instantiated via Ogre's Compositor framework so that we're
// operating on a previously rendered image. We're doing it a shader for
// efficiency: a naive CPU implementation slows camera rates from 30Hz to 10Hz,
// while this GPU implementation has no noticable effect on performance.
//
// We're applying additive amplifier noise, as described at:
// http://en.wikipedia.org/wiki/Image_noise#Amplifier_noise_.28Gaussian_noise.29
// This is uncorrelated Gaussian noise added to each pixel. For each pixel, we
// want to sample a new value from a Gaussian distribution and add it to each
// channel in the input image.
//
// There isn't (as far as I can tell) a way to generate random values in GLSL.
// The GPU vendors apparently don't implement the noise[1-4]() functions that
// are described in the documentation. What we do have is a deterministic
// function that does a decent job of appoximating a uniform distribution
// on [0,1]. But it requires a 2-D vector as input.
//
// So we're doing something mildly complicated:
//
// 1. On the CPU, before each call to this shader, generate 3 random numbers
// that are uniformly distributed on [0,1.0] and pass them here,
// in the `offsets` parameter.
//
// 2. Each time we need a random number here, add one of the CPU-provided
// offsets to our current pixel coordinates and give the resulting vector to our
// pseudo-random number generator.
//
// 3. Implement the Box-Muller method to sample from a Gaussian distribution.
// Normally each iteration of this method requires 2 uniform inputs and
// gives 2 Gaussian outputs. We're using 3 uniform inputs, with the 3rd
// being used to select randomly between the 2 Gaussian outputs.
//
// 4. Having produced a Gaussian sample, we add this value to each channel of
// the input image.
// The input texture, which is set up by the Ogre Compositor infrastructure.
uniform sampler2D RT;
// Other parameters are set in C++, via
// Ogre::GpuProgramParameters::setNamedConstant()
// Random values sampled on the CPU, which we'll use as offsets into our 2-D
// pseudo-random sampler here.
uniform vec3 offsets;
// Mean of the Gaussian distribution that we want to sample from.
uniform float mean;
// Standard deviation of the Gaussian distribution that we want to sample from.
uniform float stddev;
#define PI 3.14159265358979323846264
float rand(vec2 co)
{
// This one-liner can be found in many places, including:
// http://stackoverflow.com/questions/4200224/random-noise-functions-for-glsl
// I can't find any explanation for it, but experimentally it does seem to
// produce approximately uniformly distributed values in the interval [0,1].
float r = fract(sin(dot(co.xy, vec2(12.9898,78.233))) * 43758.5453);
// Make sure that we don't return 0.0
if(r == 0.0)
return 0.000000000001;
else
return r;
}
vec4 gaussrand(vec2 co)
{
// Box-Muller method for sampling from the normal distribution
// http://en.wikipedia.org/wiki/Normal_distribution#Generating_values_from_normal_distribution
// This method requires 2 uniform random inputs and produces 2
// Gaussian random outputs. We'll take a 3rd random variable and use it to
// switch between the two outputs.
float U, V, R, Z;
// Add in the CPU-supplied random offsets to generate the 3 random values that
// we'll use.
U = rand(co + vec2(offsets.x, offsets.x));
V = rand(co + vec2(offsets.y, offsets.y));
R = rand(co + vec2(offsets.z, offsets.z));
// Switch between the two random outputs.
if(R < 0.5)
Z = sqrt(-2.0 * log(U)) * sin(2.0 * PI * V);
else
Z = sqrt(-2.0 * log(U)) * cos(2.0 * PI * V);
// Apply the stddev and mean.
Z = Z * stddev + mean;
// Return it as a vec4, to be added to the input ("true") color.
return vec4(Z, Z, Z, 0.0);
}
void main()
{
// Add the sampled noise to the input color and clamp the result to a valid
// range.
gl_FragColor = clamp(texture2D(RT, gl_TexCoord[0].xy) +
gaussrand(gl_TexCoord[0].xy), 0.0, 1.0);
}
// Simple vertex shader; just setting things up for the real work to be done in
// camera_noise_gaussian_fs.glsl.
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0;
}
// This fragment shader will add Gaussian noise to a rendered image. It's
// intended to be instantiated via Ogre's Compositor framework so that we're
// operating on a previously rendered image. We're doing it a shader for
// efficiency: a naive CPU implementation slows camera rates from 30Hz to 10Hz,
// while this GPU implementation has no noticable effect on performance.
//
// We're applying additive amplifier noise, as described at:
// http://en.wikipedia.org/wiki/Image_noise#Amplifier_noise_.28Gaussian_noise.29
// This is uncorrelated Gaussian noise added to each pixel. For each pixel, we
// want to sample a new value from a Gaussian distribution and add it to each
// channel in the input image.
//
// There isn't (as far as I can tell) a way to generate random values in GLSL.
// The GPU vendors apparently don't implement the noise[1-4]() functions that
// are described in the documentation. What we do have is a deterministic
// function that does a decent job of appoximating a uniform distribution
// on [0,1]. But it requires a 2-D vector as input.
//
// So we're doing something mildly complicated:
//
// 1. On the CPU, before each call to this shader, generate 3 random numbers
// that are uniformly distributed on [0,1.0] and pass them here,
// in the `offsets` parameter.
//
// 2. Each time we need a random number here, add one of the CPU-provided
// offsets to our current pixel coordinates and give the resulting vector to our
// pseudo-random number generator.
//
// 3. Implement the Box-Muller method to sample from a Gaussian distribution.
// Normally each iteration of this method requires 2 uniform inputs and
// gives 2 Gaussian outputs. We're using 3 uniform inputs, with the 3rd
// being used to select randomly between the 2 Gaussian outputs.
//
// 4. Having produced a Gaussian sample, we add this value to each channel of
// the input image.
// The input texture, which is set up by the Ogre Compositor infrastructure.
uniform sampler2D RT;
// Other parameters are set in C++, via
// Ogre::GpuProgramParameters::setNamedConstant()
// Random values sampled on the CPU, which we'll use as offsets into our 2-D
// pseudo-random sampler here.
uniform vec3 offsets;
// Mean of the Gaussian distribution that we want to sample from.
uniform float mean;
// Standard deviation of the Gaussian distribution that we want to sample from.
uniform float stddev;
#define PI 3.14159265358979323846264
float rand(vec2 co)
{
// This one-liner can be found in many places, including:
// http://stackoverflow.com/questions/4200224/random-noise-functions-for-glsl
// I can't find any explanation for it, but experimentally it does seem to
// produce approximately uniformly distributed values in the interval [0,1].
float r = fract(sin(dot(co.xy, vec2(12.9898,78.233))) * 43758.5453);
// Make sure that we don't return 0.0
if(r == 0.0)
return 0.000000000001;
else
return r;
}
vec4 gaussrand(vec2 co)
{
// Box-Muller method for sampling from the normal distribution
// http://en.wikipedia.org/wiki/Normal_distribution#Generating_values_from_normal_distribution
// This method requires 2 uniform random inputs and produces 2
// Gaussian random outputs. We'll take a 3rd random variable and use it to
// switch between the two outputs.
float U, V, R, Z;
// Add in the CPU-supplied random offsets to generate the 3 random values that
// we'll use.
U = rand(co + vec2(offsets.x, offsets.x));
V = rand(co + vec2(offsets.y, offsets.y));
R = rand(co + vec2(offsets.z, offsets.z));
// Switch between the two random outputs.
if(R < 0.5)
Z = sqrt(-2.0 * log(U)) * sin(2.0 * PI * V);
else
Z = sqrt(-2.0 * log(U)) * cos(2.0 * PI * V);
// Apply the stddev and mean.
Z = Z * stddev + mean;
// Return it as a vec4, to be added to the input ("true") color.
return vec4(Z, Z, Z, 0.0);
}
void main()
{
// Add the sampled noise to the input color and clamp the result to a valid
// range.
gl_FragColor = clamp(texture2D(RT, gl_TexCoord[0].xy) +
gaussrand(gl_TexCoord[0].xy), 0.0, 1.0);
}
// Simple vertex shader; just setting things up for the real work to be done in
// camera_noise_generic_fs.glsl.
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0;
}
#version 130
uniform sampler2D diffuse;
uniform vec3 spotParams;
uniform float farDistance;
in vec3 oViewPos;
in vec3 oNormal;
in vec3 oWorldPos;
in vec3 oProjPos;
in vec2 oTexcoord;
out vec4 fragColor;
vec4 packData(vec3 position, vec3 normal, vec3 flux, float depth)
{
return vec4(
depth,
normal.x, //store x
normal.y + 2.0 * float(normal.z > 0.0), //store y and z's sign
trunc(flux.x * 255.0) * 255.0 + trunc(flux.y * 255.0) + flux.z
);
}
void main()
{
float depth = oProjPos.z;
vec3 normal = normalize(oNormal);
vec3 flux;
#ifdef DIRECTIONAL
flux = texture2D(diffuse, oTexcoord).xyz;
#else
// // #ifdef SPOT
// // half spotlightAngle = clamp(dot(vec3(0.0, 0.0, 1.0), oViewPos), 0.0, 1.0);
// // half spotFalloff = saturate((spotlightAngle - spotParams.x) / (spotParams.y - spotParams.x));
// // flux = cLightColor;//vec3(1-spotFalloff);
// // flux.b = 1;
#endif
// #endif
fragColor = packData(oWorldPos, normal, flux, depth);
}
#version 130
uniform mat4 worldViewProj;
uniform mat4 worldView;
uniform mat4 worldMatrix;
in vec4 iPosition;
in vec3 iNormal;
in vec2 iTexCoord;
out vec3 oViewPos;
out vec3 oNormal;
out vec3 oWorldPos;
out vec3 oProjPos;
out vec2 oTexcoord;
void main()
{
gl_Position = worldViewProj * iPosition;
oViewPos = (worldView * iPosition).xyz;
oNormal = (worldMatrix * vec4(iNormal, 0.0)).xyz;
oWorldPos = (worldMatrix * iPosition).xyz;
//vec4 prPos = worldViewProj * iPosition;
//prPos.xyz /= prPos.w;
//oProjPos = prPos.xyz;
oProjPos = (gl_Position.xyz / gl_Position.w).xyz;
oTexcoord = iTexCoord;
}
uniform sampler2D tex0;
uniform mat4 proj;
uniform vec4 ambientColor;
uniform vec3 farCorner;
uniform float farClipDistance;
void main()
{
// Attribute 0: Normal+depth
vec4 a0 = texture2D(tex0, gl_TexCoord[0].xy);
// Clip fragment if depth is too close,
// so the skybox can be rendered on the background
// clip(a0.w-0.0001);
if (a0.w < 0.0001)
discard;
// Calculate ambient colour of fragment
gl_FragColor = vec4(ambientColor.xyz, 0.0);
// Calculate depth of fragment
vec3 viewPos = normalize(gl_TexCoord[1].xyz) * farClipDistance * a0.w;
vec4 projPos = proj * vec4(viewPos, 1.0);
gl_FragDepth = (projPos.z / projPos.w) * 0.5 + 0.5;
}
uniform float farDistance;
void main()
{
float depth = length(gl_TexCoord[0].xyz) / farDistance;
gl_FragColor = vec4(depth, depth, depth, 0.0);
}
uniform mat4 worldViewProj;
uniform mat4 worldView;
void main()
{
gl_Position = worldViewProj * gl_Vertex;
gl_TexCoord[0].xyz = (worldView * gl_Vertex).xyz;
}
uniform sampler2D tex0;
uniform sampler2D tex1;
uniform mat4 proj;
uniform vec4 ambientColor;
uniform float farClipDistance;
void main()
{
// Attribute 0: Normal+depth
vec4 a0 = texture2D(tex0, gl_TexCoord[0].xy);
// Attribute 1: Diffuse color+shininess
vec4 a1 = texture2D(tex1, gl_TexCoord[0].xy);
// Clip fragment if depth is too close, so the skybox can be rendered
// on the background
if (a0.w - 0.0001 < 0.0)
discard;
// Calculate ambient color of fragment
gl_FragColor = ambientColor * vec4(a1.xyz, 0.0);
// Calculate depth of fragment;
vec3 viewPos = normalize(gl_TexCoord[1].xyz) * farClipDistance * a0.w;
vec4 projPos = proj * vec4(viewPos, 1.0);
gl_FragDepth = (projPos.z / projPos.w) * 0.5 + 0.5;
}
// Post shader: Light geometry material
#define LIGHT_POINT 1
#define LIGHT_SPOT 2
#define LIGHT_DIRECTIONAL 3
uniform sampler2D tex0;
#ifdef USE_MAT_PROPERTIES
uniform sampler2D tex1;
#endif
#if LIGHT_TYPE != LIGHT_POINT
uniform vec3 lightDir;
#endif
#if LIGHT_TYPE == LIGHT_SPOT
uniform vec4 spotParams;
#endif
#if LIGHT_TYPE != LIGHT_DIRECTIONAL
uniform float vpWidth;
uniform float vpHeight;
uniform vec3 farCorner;
uniform float flip;
#endif
#ifdef IS_SHADOW_CASTER
uniform mat4 invView;
uniform mat4 shadowViewProjMat;
uniform vec3 shadowCamPos;
uniform float shadowFarClip;
uniform sampler2D shadowTex;
#endif
uniform float farClipDistance;
// Attributes of light
uniform vec4 lightDiffuseColor;
uniform vec4 lightSpecularColor;
uniform vec4 lightFalloff;
uniform vec4 lightPos;
void checkShadow(sampler2D shadowMap, vec3 viewPos, mat4 invView,
mat4 shadowViewProj, float shadowFarClip)
{
vec3 worldPos = (invView * vec4(viewPos, 1.0)).xyz;
vec4 shadowProjPos = shadowViewProj * vec4(worldPos, 1.0);
shadowProjPos /= shadowProjPos.w;
vec2 shadowSampleTexCoord = shadowProjPos.xy;
float shadowDepth = texture2D(shadowMap, shadowSampleTexCoord).x;
if (shadowDepth < shadowProjPos.z - 0.005)
discard;
}
//////////////////////////////////////////////////////////////////////////////
// Main shader section
//////////////////////////////////////////////////////////////////////////////
void main()
{
float NL = 0.0;
float specular = 0.0;
// None directional lights have some calculations to do in the beginning
// of the pixel shader
#if LIGHT_TYPE != LIGHT_DIRECTIONAL
vec4 projectionPos = gl_TexCoord[0] / gl_TexCoord[0].w;
// -1 is because generally +Y is down for textures but up for the screen
vec2 texCoord = vec2(projectionPos.x,
projectionPos.y * -1.0 * flip) * 0.5 + 0.5;
// Texture coordinate magic, this compensates for jitter
// texCoord = fixUV(texCoord, vec2(vpWidth, vpHeight));
vec3 ray = vec3(projectionPos.x, projectionPos.y * flip, 1.0) * farCorner;
#else
vec2 texCoord = gl_TexCoord[0].xy;
vec3 ray = gl_TexCoord[1].xyz;
#endif
// Attribute 0: Normal + depth
vec4 a0 = texture2D(tex0, texCoord);
// Distance from viewer (w)
float distance = a0.w;
vec3 normal = normalize(a0.xyz);
#ifdef USE_MAT_PROPERTIES
// Attribute 1: Diffuse color + shininess
vec4 a1 = texture2D(tex1, texCoord);
// Attributes
vec3 color = a1.xyz;
float specularity = a1.w;
#endif
// Calculate position of texel in view space
vec3 viewPos = normalize(ray) * distance * farClipDistance;
// Calculate light direction and distance
#if LIGHT_TYPE == LIGHT_DIRECTIONAL
vec3 objToLightDir = -lightDir.xyz;
#else
vec3 objToLightVec = lightPos.xyz - viewPos;
float len_sq = dot(objToLightVec, objToLightVec);
float len = sqrt(len_sq);
vec3 objToLightDir = objToLightVec / len;
#endif
#ifdef IS_SHADOW_CASTER
checkShadow(shadowTex, viewPos, invView, shadowViewProjMat, shadowFarClip);
#endif
// Calculate diffuse color
// vec3 total_light_contrib;
// Lambertian term
NL = max(0.0, dot(objToLightDir, normal));
// * lightDiffuseColor.xyz;
vec3 viewDir;
vec3 h;
#ifdef IS_SPECULAR
// Calculate specular component
viewDir = -normalize(viewPos);
h = normalize(viewDir + objToLightDir);
//specular = max(0.0, dot(viewDir, h));
specular = max(0.0, dot(normal, h));
#ifdef USE_MAT_PROPERTIES
specular = pow(specular, specularity);
#else
specular = pow(specular, 30.0);
//specular = pow(dot(normal, h), 30.0);
//vec3 light_specular = pow(dot(normal, h), 32.0) * lightSpecularColor.xyz;
//total_light_contrib += specularity * light_specular;
#endif
#endif
float attenuation = 1.0;
#if LIGHT_TYPE != LIGHT_DIRECTIONAL
#ifdef IS_ATTENUATED
// clip(lightFalloff.x - len);
//if (lightFalloff.x - len < 0.0)
// discard;
// Calculate attenuation
attenuation /= dot(lightFalloff.yzw, vec3(1.0, len, len_sq));
// total_light_contrib /= attenuation;
#endif
#endif
#if LIGHT_TYPE == LIGHT_SPOT
float spotlightAngle = clamp(dot(lightDir.xyz, -objToLightDir), 0.0, 1.0);
float spotFalloff = clamp((spotlightAngle - spotParams.x) /
(spotParams.y - spotParams.x), 0.0, 1.0);
attenuation *= (1.0 - spotFalloff);
//total_light_contrib *= (1.0 - spotFalloff);
#endif
#ifdef USE_MAT_PROPERTIES
// gl_FragColor = vec4(total_light_contrib * color, 0.0);
gl_FragColor = vec4((NL * (lightDiffuseColor.xyz + specular * lightSpecularColor.xyz)) * color * attenuation, 1.0);
#else
gl_FragColor = vec4(NL * attenuation * lightDiffuseColor.xyz,
specular * NL * attenuation);
#endif
}
uniform mat4 worldViewProj;
void main()
{
gl_Position = worldViewProj * gl_Vertex;
gl_TexCoord[0] = gl_Position;
}
// Post shader: Generic fullscreen quad
uniform vec3 farCorner;
uniform float flip;
void main()
{
vec2 pos;
// Clean up inaccuracies
pos = sign(gl_Vertex.xy);
gl_Position = vec4(pos, 0.0, 1.0);
gl_Position.y *= flip;
// Image-space
gl_TexCoord[0].x = 0.5 * (1.0 + pos.x);
gl_TexCoord[0].y = 0.5 * (1.0 - pos.y);
// This ray will be interpolated and will be the ray from the camera
// to the far clip plane, per pixel
gl_TexCoord[1].xyz = farCorner * vec3(pos, 1.0);
}
#define NUM_BLUR_SAMPLES 8
uniform vec4 invTexSize;
uniform sampler2D map;
uniform sampler2D geomMap;
//ps_3_0 vec4 TEX2DLOD(sampler2D map, vec2 uv)
//{
// return texture2DLod(map, vec4(uv.xy, 0.0, 0.0));
//}
vec4 TEX2DLOD(sampler2D map, vec2 uv)
{
return texture2D(map, uv);
}
// vec2 uv : TEXCOORD0,
void main()
{
vec2 o = vec2(invTexSize.x, 0.0);
vec4 sum = TEX2DLOD(map, gl_TexCoord[0].xy) * (9.0);
float denom = 9.0;
vec4 geom = TEX2DLOD(geomMap, gl_TexCoord[0].xy);
for (int i = 1; i <= NUM_BLUR_SAMPLES; ++i)
{
vec2 nuv = gl_TexCoord[0].xy + o * float(i);
vec4 nGeom = TEX2DLOD(geomMap, nuv);
float coef = (9.0 - float(i)) * float(dot(geom.xyz, nGeom.xyz) > 0.9);
sum += TEX2DLOD(map, nuv) * coef;
denom += coef;
}
for (int i = 1; i <= 4; ++i)
{
vec2 nuv = gl_TexCoord[0].xy + o * -float(i);
vec4 nGeom = TEX2DLOD(geomMap, nuv);
float coef = (9.0 - float(i)) * float(dot(geom.xyz, nGeom.xyz) > 0.9);
sum += TEX2DLOD(map, nuv) * coef;
denom += coef;
}
gl_FragColor = sum / denom;
}
#define NUM_BLUR_SAMPLES 8
uniform vec4 invTexSize;
uniform sampler2D map;
uniform sampler2D geomMap;
//ps_3_0 vec4 TEX2DLOD(sampler2D map, vec2 uv)
//{
// return texture2DLod(map, vec4(uv.xy, 0.0, 0.0));
//}
vec4 TEX2DLOD(sampler2D map, vec2 uv)
{
return texture2D(map, uv);
}
void main()
{
vec2 o = vec2(0.0, invTexSize.y);
vec4 sum = TEX2DLOD(map, gl_TexCoord[0].xy) * (9.0);
float denom = 9.0;
vec4 geom = TEX2DLOD(geomMap, gl_TexCoord[0].xy);
for (int i = 1; i <= NUM_BLUR_SAMPLES; ++i)
{
vec2 nuv = gl_TexCoord[0].xy + o * float(i);
vec4 nGeom = TEX2DLOD(geomMap, nuv);
float coef = (9.0 - float(i)) * float(dot(geom.xyz, nGeom.xyz) > 0.9);
sum += TEX2DLOD(map, nuv) * coef;
denom += coef;
}
for (int i = 1; i <= 4; ++i)
{
vec2 nuv = gl_TexCoord[0].xy + o * -float(i);
vec4 nGeom = TEX2DLOD(geomMap, nuv);
float coef = (9.0 - float(i)) * float(dot(geom.xyz, nGeom.xyz) > 0.9);
sum += TEX2DLOD(map, nuv) * coef;
denom += coef;
}
gl_FragColor = sum / denom;
}
#define MAX_RAND_SAMPLES 14
#define RADIUS 0.2125
#define NUM_BASE_SAMPLES 6
uniform mat4 ptMat;
uniform float far;
uniform sampler2D geomMap;
uniform sampler2D randMap;
/*const vec3 RAND_SAMPLES[6] = vec3[6](
vec3(1.0, 0.0, 0.0),
vec3(-1.0, 0.0, 0.0),
vec3(0.0, 1.0, 0),
vec3(0.0, -1.0, 0),
vec3(0.0, 0.0, 1.0),
vec3(0.0, 0.0, -1.0)
);
*/
//vec3 computeZ(vec2 xy)
//{
// return vec3(xy, sqrt(1.0 - dot(xy, xy)));
//}
// for ps_3_0, we want to use tex2Dlod because it's faster
//ps_3_0 vec4 TEX2DLOD(sampler2D map, vec2 uv)
//{
// return texture2DLod(map, vec4(uv.xy, 0.0, 0.0));
//}
vec4 TEX2DLOD(sampler2D map, vec2 uv)
{
return texture2D(map, uv);
}
void main()
{
// random normal lookup from a texture and expand to [-1..1]
vec3 randN = TEX2DLOD(randMap, gl_TexCoord[0].xy * 24.0).xyz * 2.0 - 1.0;
vec4 geom = TEX2DLOD(geomMap, gl_TexCoord[0].xy);
float depth = geom.w;
// IN.ray will be distorted slightly due to interpolation
// it should be normalized here
vec3 viewPos = normalize(gl_TexCoord[1].xyz) * depth;
// by computing Z manually, we lose some accuracy under extreme angles
// considering this is just for bias, this loss is acceptable
vec3 viewNorm = geom.xyz; //computeZ(geom.yz);
// accumulated occlusion factor
float occ = 0.0;
for (int i = 0; i < NUM_BASE_SAMPLES; ++i)
{
// reflected direction to move in for the sphere
// (based on random samples and a random texture sample)
// bias the random direction away from the normal
// this tends to minimize self occlusion
vec3 rr;
if (i == 0)
rr = vec3(1.0, 0.0, 0.0);
else if (i==1)
rr = vec3(-1.0, 0.0, 0.0);
else if (i==2)
rr = vec3(0.0, 1.0, 0);
else if (i==3)
rr = vec3(0.0, -1.0, 0);
else if (i==4)
rr = vec3(0.0, 0.0, 1.0);
else if (i==5)
rr = vec3(0.0, 0.0, -1.0);
vec3 randomDir = reflect(rr, randN) + viewNorm;
// move new view-space position back into texture space
vec4 nuv = ptMat * vec4(viewPos.xyz + randomDir * RADIUS, 1.0);
nuv.xy /= nuv.w;
// compute occlusion based on the (scaled) Z difference
float zd = clamp(far * (depth - TEX2DLOD(geomMap, nuv.xy).w), 0.0, 1.0);
// this is a sample occlusion function, you can always play with
// other ones, like 1.0 / (1.0 + zd * zd) and stuff
occ += clamp(pow(1.0 - zd, 11.0) + zd, 0.0, 1.0);
}
occ /= 6.0;
gl_FragColor = vec4(occ, occ, occ, 1.0);
}
uniform vec3 farCorner;
uniform mat4 wvp;
void main()
{
gl_Position = wvp * gl_Vertex;
// clean up inaccuracies for the UV coords
vec2 uv = sign(gl_Vertex.xy);
// convert to image space
uv = (vec2(uv.x, -uv.y) + 1.0) * 0.5;
gl_TexCoord[0].xy = uv;
// calculate the correct ray
// (modify XY parameters based on screen-space quad XY)
gl_TexCoord[1].xyz = farCorner * vec3(sign(gl_Vertex.xy), 1.0);
}
uniform sampler2D GBuff;
uniform sampler2D GBuff1;
uniform vec3 LightColor;
uniform vec4 viewportSize;
uniform float farClipDistance;
uniform mat4 invView;
uniform vec3 farCorner;
uniform float flip;
uniform float attenuation;
uniform float clampTo;
//ps_2_x ps_3_0 vec2 fixUV(vec2 texCoord)
//{
// return vec2(texCoord.x, -texCoord.y);
//}
vec2 fixUV(vec2 texCoord)
{
return texCoord;
}
void main()
{
vec2 texcoord = gl_FragCoord.xy * viewportSize.zw;
texcoord.y *= -flip;
//texcoord = fixUV(texcoord);
vec4 normDepth = texture2D(GBuff1, vec2(texcoord.x, texcoord.y));
vec3 albedo = texture2D(GBuff, vec2(texcoord.x, texcoord.y)).xyz;
vec3 normal = normalize(normDepth.xyz);
vec3 ray = vec3(gl_TexCoord[0].x, flip * gl_TexCoord[0].y, 1.0) * farCorner;
vec3 viewPos = normalize(ray) * normDepth.w * farClipDistance;
vec3 lightToFrag = gl_TexCoord[2].xyz - viewPos;
vec3 L = normalize(lightToFrag);
float NL = max(0.0, dot(normal, L));
float att = 1.0;
att *= 1.0 / (1.0 + attenuation * dot(lightToFrag, lightToFrag));
gl_FragColor = vec4(clamp(albedo * gl_TexCoord[1].xyz * att * NL * LightColor,
0.0, clampTo), 1.0);
}
uniform sampler2D GBuff;
uniform vec3 LightColor;
uniform vec4 viewportSize;
uniform float farClipDistance;
uniform mat4 invView;
uniform vec3 farCorner;
uniform float flip;
uniform float attenuation;
uniform float clampTo;
void main()
{
vec2 texcoord = gl_FragCoord.xy * viewportSize.zw;
texcoord.y = texcoord.y * float(-flip);
// texcoord = fixUV(texcoord);
vec4 normDepth = texture2D(GBuff, texcoord);
vec3 normal = normalize(normDepth.xyz);
vec3 ray = vec3(gl_TexCoord[0].x, flip * gl_TexCoord[0].y, 1.0) * farCorner;
vec3 viewPos = normalize(ray) * normDepth.w * farClipDistance;
vec3 lightToFrag = gl_TexCoord[2].xyz - viewPos;
vec3 L = normalize(lightToFrag);
float NL = max(0.0, dot(normal, L));
float att = clamp(dot(gl_TexCoord[3].xyz, -normal), 0.0, 1.0);
att *= 1.0 / (1.0 + attenuation * dot(lightToFrag, lightToFrag));
// clampTo is a parameter that can be tuned
gl_FragColor = vec4(clamp(gl_TexCoord[1].xyz * att * NL * LightColor, 0.0, clampTo), 0.0);
// return vec4(clamp(gl_TexCoord[1].xyz*att*NL*LightColor,0,clampTo),0);
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment