// Copyright (C) 2006 Robert Geist // All rights reserved. // xrgba_rs.frag ... always called with k == EDGE/4 -1; // we want to update only rgb layers, a layer remains fixed // if direction xyzdir yields k == EDGE/4, we need shift the lookup: // r(E/4) -> g(0), g(E/4) -> b(0), b(E/4) -> a(0) #include "xrgba.h" uniform sampler2DRect cloud; uniform sampler2DRect photon; uniform sampler2DRect omega; uniform sampler2DRect directions; #define DIRECTIONS 19 void main(void) { float fEDGE = float(EDGE); float fDIR = float(DIRECTIONS); float i, j, k, m, row, col, from_m, scatter, alpha; vec4 color, cloud_density, nbr_incoming_color, scattered_in; vec3 from_node, xyzdir, pcolor; int n; i = mod(gl_TexCoord[0].t,fEDGE); j = floor(gl_TexCoord[0].s/fDIR); k = floor(gl_TexCoord[0].t/fEDGE); m = mod(gl_TexCoord[0].s,fDIR); // we need to look up this color to get the alpha value; // it's coming from the bottom layer lower boundary, // and it shouldn't change from_node = vec3(i,j,k); row = from_node.z*fEDGE + from_node.x; col = from_node.y*fDIR + m; color = texture2DRect(photon,vec2(col,row)); alpha = color.a; // access incoming photon density in direction m from neighbor xyzdir = texture2DRect(directions,vec2(m,0.5)); from_node = vec3(i,j,k) - xyzdir; if(from_node.z > (fEDGE/4.0 - 1.0)){ // color shift from_node.z = 0.0; row = from_node.z*fEDGE + from_node.x; col = from_node.y*fDIR + m; color = texture2DRect(photon,vec2(col,row)); // udate .rgb but read from .gba pcolor = color.gba; cloud_density = texture2DRect(cloud,vec2(from_node.y,row)); scattered_in = vec4(0.0,0.0,0.0,0.0); for(n=0;n