Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/engine/renderer/glsl_source/computeLight_fp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
// computeLight_fp.glsl - Light computing helper functions

#if defined(USE_REFLECTIVE_SPECULAR)
uniform samplerCube u_EnvironmentMap0;
uniform samplerCube u_EnvironmentMap1;
uniform float u_EnvironmentInterpolation;
#endif // USE_REFLECTIVE_SPECULAR

struct light {
vec4 center_radius;
vec4 color_type;
Expand Down Expand Up @@ -49,6 +55,14 @@ uniform int u_numLights;
uniform vec2 u_SpecularExponent;

// lighting helper functions

void ReadLightGrid(in vec4 texel, out vec3 ambientColor, out vec3 lightColor) {
float ambientScale = 2.0 * texel.a;
float directedScale = 2.0 - ambientScale;
ambientColor = ambientScale * texel.rgb;
lightColor = directedScale * texel.rgb;
}

void computeLight( vec3 lightDir, vec3 normal, vec3 viewDir, vec3 lightColor,
vec4 diffuseColor, vec4 materialColor,
inout vec4 color ) {
Expand Down Expand Up @@ -101,6 +115,14 @@ void computeLight( vec3 lightDir, vec3 normal, vec3 viewDir, vec3 lightColor,
NdotL = clamp( NdotL, 0.0, 1.0 );
#endif

#if defined(USE_REFLECTIVE_SPECULAR)
// not implemented for PBR yet
vec4 envColor0 = textureCube(u_EnvironmentMap0, reflect(-viewDir, normal));
vec4 envColor1 = textureCube(u_EnvironmentMap1, reflect(-viewDir, normal));

materialColor.rgb *= mix(envColor0, envColor1, u_EnvironmentInterpolation).rgb;
#endif // USE_REFLECTIVE_SPECULAR

color.rgb += diffuseColor.rgb * lightColor.rgb * NdotL;
#if defined(r_specularMapping) && !defined(USE_PHYSICAL_SHADING)
color.rgb += materialColor.rgb * lightColor.rgb * pow( NdotH, u_SpecularExponent.x * materialColor.a + u_SpecularExponent.y) * r_SpecularScale;
Expand Down
7 changes: 3 additions & 4 deletions src/engine/renderer/glsl_source/lightMapping_fp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ void main()
// compute the diffuse term
vec4 diffuse = texture2D(u_DiffuseMap, texCoords);

// vertex blend operation like: alphaGen vertex
diffuse *= var_Color;

if( abs(diffuse.a + u_AlphaThreshold) <= 1.0 )
{
discard;
return;
}

// vertex blend operation like: alphaGen vertex
diffuse *= var_Color;

// compute normal in world space from normalmap
vec3 normal = NormalInWorldSpace(texCoords, tangentToWorldMatrix);

Expand All @@ -85,7 +85,6 @@ void main()
#if defined(USE_DELUXE_MAPPING)
// compute light direction in world space
vec4 deluxe = texture2D(u_DeluxeMap, var_TexLight);

vec3 lightDir = normalize(2.0 * deluxe.xyz - 1.0);

// Lightmaps generated by q3map2 don't store the raw light value, but
Expand Down
26 changes: 8 additions & 18 deletions src/engine/renderer/glsl_source/liquid_fp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,6 @@ IN(smooth) vec3 var_Normal;

DECLARE_OUTPUT(vec4)

void ReadLightGrid(in vec3 pos, out vec3 lightDir,
out vec3 ambientColor, out vec3 lightColor) {
vec4 texel1 = texture3D(u_LightGrid1, pos);
vec4 texel2 = texture3D(u_LightGrid2, pos);

float ambientScale = 2.0 * texel1.a;
float directedScale = 2.0 - ambientScale;
ambientColor = ambientScale * texel1.rgb;
lightColor = directedScale * texel1.rgb;

lightDir = normalize( texel2.rgb - (128.0 / 255.0) );
}

void main()
{
// compute incident ray
Expand Down Expand Up @@ -129,12 +116,15 @@ void main()
color.rgb = mix(u_FogColor, color.rgb, fogFactor);
}

vec3 lightDir;
vec3 ambientColor;
vec3 lightColor;
vec3 lightGridPos = (var_Position - u_LightGridOrigin) * u_LightGridScale;

// compute light color from light grid
vec3 ambientColor, lightColor;
ReadLightGrid(texture3D(u_LightGrid1, lightGridPos), ambientColor, lightColor);

ReadLightGrid((var_Position - u_LightGridOrigin) * u_LightGridScale,
lightDir, ambientColor, lightColor);
// compute light direction in world space
vec4 texel = texture3D(u_LightGrid2, lightGridPos);
vec3 lightDir = normalize(texel.xyz - (128.0 / 255.0));

vec4 diffuse = vec4(0.0, 0.0, 0.0, 1.0);

Expand Down
46 changes: 11 additions & 35 deletions src/engine/renderer/glsl_source/vertexLighting_DBS_entity_fp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ uniform sampler2D u_DiffuseMap;
uniform sampler2D u_MaterialMap;
uniform sampler2D u_GlowMap;

#if defined(USE_REFLECTIVE_SPECULAR)
uniform samplerCube u_EnvironmentMap0;
uniform samplerCube u_EnvironmentMap1;
uniform float u_EnvironmentInterpolation;
#endif // USE_REFLECTIVE_SPECULAR

uniform float u_AlphaThreshold;
uniform vec3 u_ViewOrigin;

Expand All @@ -49,19 +43,6 @@ IN(smooth) vec3 var_Normal;

DECLARE_OUTPUT(vec4)

void ReadLightGrid(in vec3 pos, out vec3 lightDir,
out vec3 ambientColor, out vec3 lightColor) {
vec4 texel1 = texture3D(u_LightGrid1, pos);
vec4 texel2 = texture3D(u_LightGrid2, pos);

float ambientScale = 2.0 * texel1.a;
float directedScale = 2.0 - ambientScale;
ambientColor = ambientScale * texel1.rgb;
lightColor = directedScale * texel1.rgb;

lightDir = normalize( texel2.rgb - (128.0 / 255.0) );
}

void main()
{
// compute view direction in world space
Expand All @@ -71,12 +52,15 @@ void main()

mat3 tangentToWorldMatrix = mat3(var_Tangent.xyz, var_Binormal.xyz, var_Normal.xyz);

// compute light direction in world space
vec3 lightDir;
vec3 ambientColor;
vec3 lightColor;
vec3 lightGridPos = (var_Position - u_LightGridOrigin) * u_LightGridScale;

ReadLightGrid((var_Position - u_LightGridOrigin) * u_LightGridScale, lightDir, ambientColor, lightColor);
// compute light color from light grid
vec3 ambientColor, lightColor;
ReadLightGrid(texture3D(u_LightGrid1, lightGridPos), ambientColor, lightColor);

// compute light direction in world space
vec4 texel = texture3D(u_LightGrid2, lightGridPos);
vec3 lightDir = normalize(texel.xyz - (128.0 / 255.0));

#if defined(USE_PARALLAX_MAPPING)
// compute texcoords offset from heightmap
Expand All @@ -88,29 +72,21 @@ void main()
// compute the diffuse term
vec4 diffuse = texture2D(u_DiffuseMap, texCoords);

// vertex blend operation like: alphaGen vertex
diffuse *= var_Color;

if( abs(diffuse.a + u_AlphaThreshold) <= 1.0 )
{
discard;
return;
}

// vertex blend operation like: alphaGen vertex
diffuse *= var_Color;

// compute normal in world space from normalmap
vec3 normal = NormalInWorldSpace(texCoords, tangentToWorldMatrix);

// compute the material term
vec4 material = texture2D(u_MaterialMap, texCoords);

#if defined(USE_REFLECTIVE_SPECULAR) && !defined(USE_PHYSICAL_MAPPING)
// not implemented for PBR yet
vec4 envColor0 = textureCube(u_EnvironmentMap0, reflect(-viewDir, normal));
vec4 envColor1 = textureCube(u_EnvironmentMap1, reflect(-viewDir, normal));

material.rgb *= mix(envColor0, envColor1, u_EnvironmentInterpolation).rgb;
#endif // USE_REFLECTIVE_SPECULAR && !USE_PHYSICAL_MAPPING

// compute final color
vec4 color = vec4(ambientColor * r_AmbientScale * diffuse.rgb, diffuse.a);

Expand Down
32 changes: 11 additions & 21 deletions src/engine/renderer/glsl_source/vertexLighting_DBS_world_fp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,6 @@ IN(smooth) vec3 var_Normal;

DECLARE_OUTPUT(vec4)

void ReadLightGrid(in vec3 pos, out vec3 lightDir,
out vec3 ambientColor, out vec3 lightColor) {
vec4 texel1 = texture3D(u_LightGrid1, pos);
vec4 texel2 = texture3D(u_LightGrid2, pos);

float ambientScale = 2.0 * texel1.a;
float directedScale = 2.0 - ambientScale;
ambientColor = ambientScale * texel1.rgb;
lightColor = directedScale * texel1.rgb;

lightDir = normalize( texel2.rgb - (128.0 / 255.0) );
}

void main()
{
// compute view direction in world space
Expand All @@ -65,12 +52,15 @@ void main()

mat3 tangentToWorldMatrix = mat3(var_Tangent.xyz, var_Binormal.xyz, var_Normal.xyz);

// compute light direction in world space
vec3 lightDir;
vec3 ambientColor;
vec3 lightColor;
vec3 lightGridPos = (var_Position - u_LightGridOrigin) * u_LightGridScale;

// compute light color from light grid
vec3 ambientColor, lightColor;
ReadLightGrid(texture3D(u_LightGrid1, lightGridPos), ambientColor, lightColor);

ReadLightGrid((var_Position - u_LightGridOrigin) * u_LightGridScale, lightDir, ambientColor, lightColor);
// compute light direction in world space
vec4 texel = texture3D(u_LightGrid2, lightGridPos);
vec3 lightDir = normalize(texel.xyz - (128.0 / 255.0));

#if defined(USE_PARALLAX_MAPPING)
// compute texcoords offset from heightmap
Expand All @@ -82,15 +72,15 @@ void main()
// compute the diffuse term
vec4 diffuse = texture2D(u_DiffuseMap, texCoords);

// vertex blend operation like: alphaGen vertex
diffuse *= var_Color;

if( abs(diffuse.a + u_AlphaThreshold) <= 1.0 )
{
discard;
return;
}

// vertex blend operation like: alphaGen vertex
diffuse *= var_Color;

// compute normal in world space from normalmap
vec3 normal = NormalInWorldSpace(texCoords, tangentToWorldMatrix);

Expand Down