Page 4 of 4
Finalement pour le rendue
layout (location = 0) in vec3 in_position; layout (location = 1) in vec3 in_texcoord; layout (location = 2) in vec3 in_normal; layout (location = 3) in vec3 in_tangent; layout (location = 4) in vec3 in_viewVector; uniform Transform transform; uniform vec2 screenSize; out vec4 fragColor; int tile; /** * return the number of light index inside the current tile */ uint light_count() { return lightIndexes[tile]; } /** * compute the light contributuon from a light source at the index inside the tile */ vec4 light_contribution_from(uint j) { int lightIndex = tileLights[tile][j]; vec3 lightPosition = lightData[lightIndex].pos4.xyz; lightPosition = vec3(transform.proj * transform.view * vec4(lightPosition, 1.0)); float dist = length(lightPosition - in_position); //Diffuse vec3 viewDir = normalize(-in_position); vec3 lightDir = normalize(lightPosition - in_position); vec3 diffuse = max(dot(in_normal, lightDir), 0.0) * lightData[lightIndex].lightColour.rgb; //Specular vec3 halfDir = normalize(lightDir + viewDir); float specPower = pow(max(dot(in_normal, halfDir), 0.0), 500.0); vec3 specular = lightData[lightIndex].lightColour.rgb * specPower; //Attenuation float attenuation = 0; attenuation = 1.0 - clamp(dist / lightData[lightIndex].lightRadius, 0.0, 1.0); attenuation *= lightData[lightIndex].intensity; diffuse *= attenuation; specular *= attenuation; return vec4(vec3(diffuse + specular), 0.0); } // // Main part. To be removed in the benefit of Template.frag.glsl. // void main(void) { //Transform screenspace coordinates into a tile index vec3 ScreenCoord = abs(vec3(gl_FragCoord.xy, in_position.z-1.0) / vec3(screenSize, FIXED_ZFAR)); ivec3 GridCoord = ivec3(ScreenCoord * GRID_SIZE); // calculate the tile index corresponding to the cluster position tile = GridCoord.x + (GridCoord.y * GRID_SIZE.x) + + (GridCoord.z * GRID_SIZE.x * GRID_SIZE.y); for(int j = 0; j < light_count(); j++) fragColor += light_contribution_from(j); }
ont utilise les sources lumineuses en fonction de la position de fragment :
Copyrigth
Les résultats et les codes présenter ont été effectuer lors de mon projet de M2, et visais à ajouter certaines fonctionnalités au moteur graphique de l'IRIT, le RadiumEngine