// Copyright (C) 2006 Robert Geist // All rights reserved. // xrgba_rn.frag ... always called with k == 0; // we want to update gba layers, and leave red alone; // if direction xyzdir yields a k == -1, we need to shift the lookup: // g(0) -> r(E/4-1), b(0) -> g(E/4-1), a(0) -> b(E/4-1) #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, red; 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 red value; // it's coming from the top layer northern 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)); red = color.r; // 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 < 0.0){ // color shift from_node.z = fEDGE/4.0 - 1.0; row = from_node.z*fEDGE + from_node.x; col = from_node.y*fDIR + m; color = texture2DRect(photon,vec2(col,row)); // udate .gba but read from .rgb pcolor = color.rgb; cloud_density = texture2DRect(cloud,vec2(from_node.y,row)); scattered_in = vec4(0.0,0.0,0.0,0.0); for(n=0;n14.0) && (m<15.0)) color = vec4(55555.0,66666.0,0.0,0.0); } gl_FragColor = color; }