  	 mix(cTexel,codeTexel(vec2(texelXY.x,ceilTexXY.y),textureID,tDims,renderFlags),dH.y),//Left
  	 mix(codeTexel(vec2(ceilTexXY.x,texelXY.y),textureID,tDims,renderFlags),codeTexel(ceilTexXY,textureID,tDims,renderFlags),dH.y),//Right
  	   dH.x);//Vertical
-
- float sunIllumination			= dot(sunVector,norm);
- if(dot(norm,norm)>.1)cTexel.rgb
+ 
+ float sunIllumination			= -dot(sunVector,norm);
+ if(dot(norm.xyz,norm.xyz)>.2)cTexel.rgb
  								=((clamp(sunIllumination,0,1)*sunColor)+fogColor) * cTexel.rgb;
  								// TODO: Re-design and optimize
  cTexel 						= mix(cTexel,vec4(illuminatedFog,1),warpedFog);//FOG
  return cTexel;
  }//end intrinsicCodeTexel
+
+vec4 primitiveLayer(vec2 pQuad, float fogFactor, vec3 fogColor, vec4 vUVZI){
+ /*
+ uint		vertexID	= primitiveID*3u;
+ float		textureID	= texelFetch(vertexTextureIDTexture,ivec2(vertexID%VTX_TEXTURE_USABLE_WIDTH,vertexID/VTX_TEXTURE_USABLE_WIDTH),0).x*65536*PAGE_SIZE_VEC4;
+ uint	row				= primitiveID/PRIMS_PER_ROW;
+ uint	col				= primitiveID%PRIMS_PER_ROW;
+ uint	primitiveIndex	= row*PRIMS_PER_ROW+col;
+ uint	vertexIndex		= primitiveIndex*3u;
+ vec2	pQuadBL			= PRIM_QUAD_BL;
+ pQuadBL.x			+=float(col*2)*PRIM_TEX_WIDTH_SCALAR;// x2 because each quad is 2 texels wide.
+ pQuadBL.y			+=float(row*2)*PRIM_TEX_HEIGHT_SCALAR;
+ vec2	pQuad		= pQuadBL+vec2(PRIM_TEX_WIDTH_SCALAR*screenLoc.x,PRIM_TEX_HEIGHT_SCALAR*screenLoc.y);
+ vec4	uvzw		= textureLod(primitiveUVZWTexture,pQuad,0);
+ */
+ vec4	nXnYnZ		= textureLod(primitivenXnYnZTexture,pQuad,0);
+ vec2	uv			= texture(primaryRendering,screenLoc).xy;//GET UV //TODO: Remove
+ if(uv.x!=-.1234)uv	= vUVZI.xy; //TODO: Remove conditional, keep assignment.
+ vec3 	norm 		= texture(normTexture,screenLoc).xyz*2-1;//UNPACK NORM    //TODO: Remove
+ if(norm.x!=-.1234)norm = (nXnYnZ.xyz*2)-1;//TODO: Remove conditional, keep assignment.
+ return intrinsicCodeTexel(fogFactor,uint(vUVZI[3u]),norm,uv,fogColor);
+}
+
+uint getPrimitiveIDFromQueue(vec4 layerAccumulator, int level){
+ const vec4 ACC_MULTIPLIER = vec4(1,16,256,4096);
+ return uint(dot(mod(floor(layerAccumulator/pow(16.,float(level))),16)*ACC_MULTIPLIER,vec4(1)));
+}
+/*
+float getDepthOfPrimitive(uint primitiveID){
+}
+*/
+
+float logn(float value, float base){
+ return log2(value)/log2(base);
+}
+
+uint depthOfFloatShiftQueue(vec4 fsq){
+ return uint(logn(fsq.x,16));
+}
+
+vec2 getPQuad(uint primitiveID){
+ uint	row			= primitiveID/PRIMS_PER_ROW;
+ uint	col			= primitiveID%PRIMS_PER_ROW;
+ vec2	pQuadBL		= PRIM_QUAD_BL;
+ pQuadBL.x			+=float(col*2u)*PRIM_TEX_WIDTH_SCALAR;// x2 because each quad is 2 texels wide.
+ pQuadBL.y			+=float(row*2u)*PRIM_TEX_HEIGHT_SCALAR;
+ return				pQuadBL+vec2(PRIM_TEX_WIDTH_SCALAR*screenLoc.x,PRIM_TEX_HEIGHT_SCALAR*screenLoc.y);
+}
+
+float getTextureID(uint primitiveID){
+ uint vertexID = primitiveID * 3u;
+ return texelFetch(vertexTextureIDTexture,ivec2(vertexID%VTX_TEXTURE_USABLE_WIDTH,vertexID/VTX_TEXTURE_USABLE_WIDTH),0).x*65536*PAGE_SIZE_VEC4;
+}
 
 ////////// STRUCT LAYOUT DOCUMENTATION ///////////////
 /**

  }//end if(relevantSize>0)
  
  // D E P T H   A S S E M B L Y
  for(int i=0; i<relevantSize; i++){
   vec4 dqColor	= intrinsicCodeTexel(0,floatBitsToUint(depthQueue[ordering[i]][2u]),vec3(0,0,0),depthQueue[ordering[i]].rg,illuminatedFog);
   color 		= mix(color.rgb,dqColor.rgb,dqColor.a);
  }//end for(relevantSize)
  
fragColor.rgb		 	= color;
}//end main()
uniform sampler2D 		primaryRendering;
uniform sampler2D 		depthTexture;
uniform sampler2D 		normTexture;
uniform sampler2D 		primitiveIDTexture;
uniform sampler2D		vertexTextureIDTexture;
uniform sampler2D		primitiveUVZWTexture;
uniform sampler2D		primitivenXnYnZTexture;
uniform sampler2DArray 	rgbaTiles;
uniform sampler2D		layerAccumulator;
uniform usamplerBuffer 	rootBuffer; 	//Global memory, as a set of uint vec4s.
//uniform sampler2DMS		depthQueueTexture;
uniform vec3 			fogColor;
uniform uint 			screenWidth;
uniform uint 			screenHeight;
