96 lines · 2.8 KB · Text
RawDownload
<@include gpu/Config.slh@><$VERSION_HEADER$>//  Generated on <$_SCRIBE_DATE$>//  lightClusters_drawClusterContent.frag////  Created by Sam Gateau on 9/8/2016.//  Copyright 2015 High Fidelity, Inc.//  Copyright 2024 Overte e.V.////  Distributed under the Apache License, Version 2.0.//  See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html//  // Everything about deferred buffer<@include DeferredBufferRead.slh@>  <@include graphics/Light.slh@><$declareLightBuffer(256)$> <@include LightClusterGrid.slh@> <@include gpu/Color.slh@><$declareColorWheel()$>  INPUT(0, vec2, varTexCoord0);OUTPUT(0, vec4, _fragColor); void main(void) {     // Grab the fragment data from the uv    vec2 texCoord = varTexCoord0.st;     vec4 fragEyePos = unpackDeferredPositionFromZdb(texCoord);    vec4 fragWorldPos = getViewInverse(getStereoSideFromUV(texCoord.x)) * fragEyePos;        // From frag world pos find the cluster    vec4 clusterEyePos = frustumGrid_worldToEye(fragWorldPos);    ivec3 clusterPos = frustumGrid_eyeToClusterPos(clusterEyePos.xyz);    int clusterIndex = frustumGrid_clusterToIndex(clusterPos);     ivec3 cluster = clusterGrid_getCluster(clusterIndex);    int numLights = cluster.x + cluster.y;    float numLightsScale = clamp(float(numLights) * 0.05, 0.01, 1.0);     int clusterOffset = cluster.z;    ivec3 dims = frustumGrid.dims.xyz;   dims.z +=1;   ivec3 summedDims = ivec3(dims.x * dims.y, dims.x, 1);      if (clusterPos.x < 0 || clusterPos.x >= dims.x) {       _fragColor = vec4(0.0);       return;   }      if (clusterPos.y < 0 || clusterPos.y >= dims.y) {       _fragColor = vec4(0.0);       return;   }   if (clusterPos.z < 0 || clusterPos.z > dims.z) {       _fragColor = vec4(0.0);       return;   }          int numLightTouching = 0;    for (int i = 0; i < numLights; i++) {        // Need the light now        int theLightIndex = clusterGrid_getClusterLightId(i, clusterOffset);        Light light = getLight(theLightIndex);         // Clip againgst the light volume and Make the Light vector going from fragment to light center in world space        vec4 fragLightVecLen2;        vec4 fragLightDirLen;        float cosSpotAngle;         if (!lightVolume_clipFragToLightVolumePoint(light.volume, fragWorldPos.xyz, fragLightVecLen2)) {            continue;        }        // Allright we re in the light sphere volume        fragLightDirLen.w = length(fragLightVecLen2.xyz);        fragLightDirLen.xyz = fragLightVecLen2.xyz / fragLightDirLen.w;         // Check spot        if ((i >= cluster.x) && !lightVolume_clipFragToLightVolumeSpotSide(light.volume, fragLightDirLen, cosSpotAngle)) {            continue;        }         numLightTouching++;    }     _fragColor = vec4(colorRamp(1.0 - (float(numLightTouching) / 12.0f)), float(numLightTouching > 0) * (0.5 + 0.5 * numLightsScale));} 

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t