Rebuilt shaders.

This commit is contained in:
Branimir Karadžić
2016-07-24 16:07:09 -07:00
parent 5b3c9609cb
commit 09e791be03
47 changed files with 117 additions and 117 deletions

View File

@@ -22,7 +22,7 @@ uniform vec4 u_rsmAmount;
float hardShadow(sampler2DShadow _sampler, vec4 _shadowCoord, float _bias)
{
vec2 texCoord = _shadowCoord.xy;
vec2 texCoord = _shadowCoord.xy;
return shadow2D(_sampler, vec3(texCoord.xy, _shadowCoord.z-_bias) );
}
@@ -31,8 +31,8 @@ float PCF(sampler2DShadow _sampler, vec4 _shadowCoord, float _bias, vec2 _texelS
vec2 texCoord = _shadowCoord.xy;
bool outside = any(greaterThan(texCoord, vec2_splat(1.0)))
|| any(lessThan (texCoord, vec2_splat(0.0)))
;
|| any(lessThan (texCoord, vec2_splat(0.0)))
;
if (outside)
{
@@ -69,63 +69,63 @@ float PCF(sampler2DShadow _sampler, vec4 _shadowCoord, float _bias, vec2 _texelS
float toClipSpaceDepth(float _depthTextureZ)
{
#if BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_METAL
return _depthTextureZ;
return _depthTextureZ;
#else
return _depthTextureZ * 2.0 - 1.0;
return _depthTextureZ * 2.0 - 1.0;
#endif // BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_METAL
}
vec3 clipToWorld(mat4 _invViewProj, vec3 _clipPos)
{
vec4 wpos = mul(_invViewProj, vec4(_clipPos, 1.0) );
return wpos.xyz / wpos.w;
vec4 wpos = mul(_invViewProj, vec4(_clipPos, 1.0) );
return wpos.xyz / wpos.w;
}
void main()
{
vec3 n = texture2D(s_normal, v_texcoord0).xyz;
// Expand out normal
n = n*2.0+-1.0;
vec3 l = u_lightDir.xyz;//normalize(vec3(-0.8,0.75,-1.0));
float dirLightIntensity = 1.0;
float dirLight = max(0.0,dot(n,l)) * dirLightIntensity;
// Expand out normal
n = n*2.0+-1.0;
vec3 l = u_lightDir.xyz;//normalize(vec3(-0.8,0.75,-1.0));
float dirLightIntensity = 1.0;
float dirLight = max(0.0,dot(n,l)) * dirLightIntensity;
// Apply shadow map
// Get world position so we can transform it into light space, to look into shadow map
vec2 texCoord = v_texcoord0.xy;
float deviceDepth = texture2D(s_depth, texCoord).x;
float depth = toClipSpaceDepth(deviceDepth);
vec3 clip = vec3(texCoord * 2.0 - 1.0, depth);
// Apply shadow map
// Get world position so we can transform it into light space, to look into shadow map
vec2 texCoord = v_texcoord0.xy;
float deviceDepth = texture2D(s_depth, texCoord).x;
float depth = toClipSpaceDepth(deviceDepth);
vec3 clip = vec3(texCoord * 2.0 - 1.0, depth);
#if BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_METAL
clip.y = -clip.y;
clip.y = -clip.y;
#endif // BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_METAL
vec3 wpos = clipToWorld(u_invMvp, clip);
vec3 wpos = clipToWorld(u_invMvp, clip);
const float shadowMapOffset = 0.003;
vec3 posOffset = wpos + n.xyz * shadowMapOffset;
vec4 shadowCoord = mul(u_lightMtx, vec4(posOffset, 1.0) );
const float shadowMapOffset = 0.003;
vec3 posOffset = wpos + n.xyz * shadowMapOffset;
vec4 shadowCoord = mul(u_lightMtx, vec4(posOffset, 1.0) );
#if BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_METAL
shadowCoord.y *= -1.0;
shadowCoord.y *= -1.0;
#endif // BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_METAL
float shadowMapBias = 0.001;
vec2 texelSize = vec2_splat(u_shadowDimsInv.x);
shadowCoord.xy /= shadowCoord.w;
shadowCoord.xy = shadowCoord.xy*0.5+0.5;
float shadowMapBias = 0.001;
vec2 texelSize = vec2_splat(u_shadowDimsInv.x);
float visibility = PCF(s_shadowMap, shadowCoord, shadowMapBias, texelSize);
shadowCoord.xy /= shadowCoord.w;
shadowCoord.xy = shadowCoord.xy*0.5+0.5;
dirLight *= visibility;
// Light from light buffer
vec3 albedo = texture2D(s_color, v_texcoord0).xyz;
vec3 lightBuffer = texture2D(s_light, v_texcoord0).xyz;
float visibility = PCF(s_shadowMap, shadowCoord, shadowMapBias, texelSize);
gl_FragColor.xyz = mix(dirLight * albedo, lightBuffer * albedo, u_rsmAmount.x);
dirLight *= visibility;
gl_FragColor.w = 1.0;
// Light from light buffer
vec3 albedo = texture2D(s_color, v_texcoord0).xyz;
vec3 lightBuffer = texture2D(s_light, v_texcoord0).xyz;
gl_FragColor.xyz = mix(dirLight * albedo, lightBuffer * albedo, u_rsmAmount.x);
gl_FragColor.w = 1.0;
}

View File

@@ -11,12 +11,12 @@ uniform vec4 u_tint;
void main()
{
vec3 normalWorldSpace = v_normal;
vec3 normalWorldSpace = v_normal;
// Write normal
gl_FragData[0].xyz = normalWorldSpace.xyz; // Normal is already compressed to [0,1] so can fit in gbuffer
gl_FragData[0].w = 0.0;
// Write normal
gl_FragData[0].xyz = normalWorldSpace.xyz; // Normal is already compressed to [0,1] so can fit in gbuffer
gl_FragData[0].w = 0.0;
// Write color
gl_FragData[1] = u_tint;
// Write color
gl_FragData[1] = u_tint;
}

View File

@@ -15,53 +15,53 @@ uniform mat4 u_invMvp;
float toClipSpaceDepth(float _depthTextureZ)
{
#if BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_METAL
return _depthTextureZ;
return _depthTextureZ;
#else
return _depthTextureZ * 2.0 - 1.0;
return _depthTextureZ * 2.0 - 1.0;
#endif // BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_METAL
}
vec3 clipToWorld(mat4 _invViewProj, vec3 _clipPos)
{
vec4 wpos = mul(_invViewProj, vec4(_clipPos, 1.0) );
return wpos.xyz / wpos.w;
vec4 wpos = mul(_invViewProj, vec4(_clipPos, 1.0) );
return wpos.xyz / wpos.w;
}
void main()
{
#if BGFX_SHADER_LANGUAGE_HLSL && (BGFX_SHADER_LANGUAGE_HLSL < 4)
vec2 texCoord = gl_FragCoord.xy * u_viewTexel.xy + u_viewTexel.xy * vec2_splat(0.5);
vec2 texCoord = gl_FragCoord.xy * u_viewTexel.xy + u_viewTexel.xy * vec2_splat(0.5);
#else
vec2 texCoord = gl_FragCoord.xy * u_viewTexel.xy;
vec2 texCoord = gl_FragCoord.xy * u_viewTexel.xy;
#endif
// Get world position
float deviceDepth = texture2D(s_depth, texCoord).x;
float depth = toClipSpaceDepth(deviceDepth);
// Get world position
float deviceDepth = texture2D(s_depth, texCoord).x;
float depth = toClipSpaceDepth(deviceDepth);
vec3 clip = vec3(texCoord * 2.0 - 1.0, depth);
vec3 clip = vec3(texCoord * 2.0 - 1.0, depth);
#if BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_METAL
clip.y = -clip.y;
clip.y = -clip.y;
#endif // BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_METAL
vec3 wpos = clipToWorld(u_invMvp, clip);
// Get normal from its map, and decompress
vec3 n = texture2D(s_normal, texCoord).xyz*2.0-1.0;
// Do lighting
vec3 pointToLight = v_lightCenterScale.xyz-wpos;
float lightLen = sqrt(dot(pointToLight, pointToLight));
vec3 wpos = clipToWorld(u_invMvp, clip);
float lightFalloff;
// Get normal from its map, and decompress
vec3 n = texture2D(s_normal, texCoord).xyz*2.0-1.0;
if (lightLen > v_lightCenterScale.w)
lightFalloff = 0.0;
else
lightFalloff = 1.0-(lightLen/v_lightCenterScale.w); // Linear falloff for light (could use dist sq if you want)
// Do lighting
vec3 pointToLight = v_lightCenterScale.xyz-wpos;
float lightLen = sqrt(dot(pointToLight, pointToLight));
vec3 l = normalize(pointToLight)*lightFalloff;
gl_FragColor.xyz = v_color0.xyz * max(0.0, dot(n,l));
float lightFalloff;
gl_FragColor.w = 1.0;
if (lightLen > v_lightCenterScale.w)
lightFalloff = 0.0;
else
lightFalloff = 1.0-(lightLen/v_lightCenterScale.w); // Linear falloff for light (could use dist sq if you want)
vec3 l = normalize(pointToLight)*lightFalloff;
gl_FragColor.xyz = v_color0.xyz * max(0.0, dot(n,l));
gl_FragColor.w = 1.0;
}

View File

@@ -12,11 +12,11 @@ uniform vec4 u_tint;
void main()
{
#if BGFX_SHADER_LANGUAGE_HLSL && (BGFX_SHADER_LANGUAGE_HLSL < 4)
vec2 texCoord = gl_FragCoord.xy * u_viewTexel.xy + u_viewTexel.xy * vec2_splat(0.5);
vec2 texCoord = gl_FragCoord.xy * u_viewTexel.xy + u_viewTexel.xy * vec2_splat(0.5);
#else
vec2 texCoord = gl_FragCoord.xy * u_viewTexel.xy;
vec2 texCoord = gl_FragCoord.xy * u_viewTexel.xy;
#endif
gl_FragData[0].xyz = u_tint.xyz; // Color of light sphere
gl_FragData[0].w = -v_normal.z; // Radius of light sphere
gl_FragData[0].xyz = u_tint.xyz; // Color of light sphere
gl_FragData[0].w = -v_normal.z; // Radius of light sphere
}

View File

@@ -2,9 +2,9 @@ $input a_position, a_normal
$output v_normal
/*
* Copyright 2016 Joseph Cherlin. All rights reserved.
* License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
*/
* Copyright 2016 Joseph Cherlin. All rights reserved.
* License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
*/
#include "../common/common.sh"
@@ -13,15 +13,15 @@ uniform vec4 u_tint;
void main()
{
// Calculate vertex position
// Calculate vertex position
vec3 pos = a_position;
gl_Position = mul(u_modelViewProj, vec4(pos, 1.0) );
gl_Position = mul(u_modelViewProj, vec4(pos, 1.0) );
// Calculate normal. Note that compressed normal is stored in the vertices
// Calculate normal. Note that compressed normal is stored in the vertices
vec3 normalObjectSpace = a_normal.xyz*2.0+-1.0; // Normal is stored in [0,1], remap to [-1,1].
// Transform normal into world space.
vec3 normalWorldSpace = mul(u_model[0], vec4(normalObjectSpace, 0.0) ).xyz;
// Normalize to remove (uniform...) scaling, however, recompress
v_normal.xyz = normalize(normalWorldSpace)*0.5+0.5;
// Transform normal into world space.
vec3 normalWorldSpace = mul(u_model[0], vec4(normalObjectSpace, 0.0) ).xyz;
// Normalize to remove (uniform...) scaling, however, recompress
v_normal.xyz = normalize(normalWorldSpace)*0.5+0.5;
}

View File

@@ -19,42 +19,42 @@ SAMPLER2D(s_rsm, 3); // Reflective shadow map, used to scale/color light
float toClipSpaceDepth(float _depthTextureZ)
{
#if BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_METAL
return _depthTextureZ;
return _depthTextureZ;
#else
return _depthTextureZ * 2.0 - 1.0;
return _depthTextureZ * 2.0 - 1.0;
#endif // BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_METAL
}
vec3 clipToWorld(mat4 _invViewProj, vec3 _clipPos)
{
vec4 wpos = mul(_invViewProj, vec4(_clipPos, 1.0) );
return wpos.xyz / wpos.w;
vec4 wpos = mul(_invViewProj, vec4(_clipPos, 1.0) );
return wpos.xyz / wpos.w;
}
void main()
{
// Calculate vertex position
// Calculate vertex position
vec3 objectSpacePos = a_position;
vec2 texCoord = u_sphereInfo.xy;
vec2 texCoord = u_sphereInfo.xy;
// Get world position using the shadow map
float deviceDepth = texture2DLod(s_shadowMap, texCoord, 0).x;
float depth = toClipSpaceDepth(deviceDepth);
vec3 clip = vec3(texCoord * 2.0 - 1.0, depth);
// Get world position using the shadow map
float deviceDepth = texture2DLod(s_shadowMap, texCoord, 0).x;
float depth = toClipSpaceDepth(deviceDepth);
vec3 clip = vec3(texCoord * 2.0 - 1.0, depth);
#if BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_METAL
clip.y = -clip.y;
clip.y = -clip.y;
#endif // BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_METAL
vec3 wPos = clipToWorld(u_invMvpShadow, clip);
wPos.y -= 0.001; // Would be much better to perturb in normal direction, but I didn't do that.
vec3 wPos = clipToWorld(u_invMvpShadow, clip);
wPos.y -= 0.001; // Would be much better to perturb in normal direction, but I didn't do that.
// Scale and color are already in the rsm
vec4 rsm = texture2DLod(s_rsm, texCoord, 0).xyzw;
float radScale = u_sphereInfo.z;
float rad = rsm.w * radScale;
// Scale and color are already in the rsm
vec4 rsm = texture2DLod(s_rsm, texCoord, 0).xyzw;
float radScale = u_sphereInfo.z;
float rad = rsm.w * radScale;
gl_Position = mul(u_viewProj, vec4(wPos+objectSpacePos*rad, 1.0) );
v_lightCenterScale.xyz = wPos.xyz;
v_lightCenterScale.w = rad;
v_color0.xyz = rsm.xyz;
gl_Position = mul(u_viewProj, vec4(wPos+objectSpacePos*rad, 1.0) );
v_lightCenterScale.xyz = wPos.xyz;
v_lightCenterScale.w = rad;
v_color0.xyz = rsm.xyz;
}

View File

@@ -13,12 +13,12 @@ uniform vec4 u_tint;
void main()
{
gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) );
// Calculate normal. Note that compressed normal is stored in the vertices
vec3 normalObjectSpace = a_normal.xyz*2.0+-1.0; // Normal is stored in [0,1], remap to [-1,1].
// Transform normal into view space.
v_normal = mul(u_modelView, vec4(normalObjectSpace, 0.0) ).xyz;
// Normalize to remove (uniform...) scaling
v_normal = normalize(v_normal);
// Calculate normal. Note that compressed normal is stored in the vertices
vec3 normalObjectSpace = a_normal.xyz*2.0+-1.0; // Normal is stored in [0,1], remap to [-1,1].
// Transform normal into view space.
v_normal = mul(u_modelView, vec4(normalObjectSpace, 0.0) ).xyz;
// Normalize to remove (uniform...) scaling
v_normal = normalize(v_normal);
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.