   //Perform 4-way texel mix
   cTexel		 = mix(codeTexel(iuv4A.xy,textureID, subTexV4Idx[0u], subTexV4Sub[0u],subTexV4Addr[0u],startCode[0u]),codeTexel(iuv4A.zw,textureID, subTexV4Idx[1u], subTexV4Sub[1u],subTexV4Addr[1u],startCode[1u]),sub.y);
   cTexel		 = mix(cTexel,mix(codeTexel(iuv4B.xy,textureID, subTexV4Idx[2u], subTexV4Sub[2u], subTexV4Addr[2u],startCode[2u]),codeTexel(iuv4B.zw,textureID,subTexV4Idx[3u],subTexV4Sub[3u],subTexV4Addr[3u],startCode[3u]),sub.y),sub.x);
-  
- float sunIllumination			= -dot(sunVector,norm);
- if(dot(norm.xyz,norm.xyz)>.01)cTexel.rgb
- 								=((clamp(sunIllumination,0,1)*sunColor)+ambientLight) * cTexel.rgb;
- return cTexel;
+ 
+ vec4 illumination = vec4(1);
+ if(dot(norm.xyz,norm.xyz)>.01)illumination.rgb
+ 								=((clamp(-dot(sunVector,norm),0,1)*sunColor)+ambientLight);
+ return cTexel * illumination;
  }//end intrinsicCodeTexel
 
-vec4 primitiveLayer(vec2 pQuad, vec4 vUVZI, bool disableAlpha, float w){
- vec4	nXnYnZ		= textureLod(primitivenXnYnZTexture,pQuad,0);
+vec4 primitiveLayer(vec3 pQuad, vec4 vUVZI, bool disableAlpha, float w){
+ vec4	nXnYnZ		= textureProjLod(primitivenXnYnZTexture,pQuad,0);
  vec2	uv			= vUVZI.xy;
  vec3 	norm 		= nXnYnZ.xyz/w;
  vec4	texel		= intrinsicCodeTexel(uint(vUVZI[3u]),norm,uv);

 vec4 intrinsicCodeTexel(uint textureID,vec3 norm,vec2 uv){
 if(textureID==0u)return vec4(0,1,0,1);//Green means textureID=zero
 if(textureID==DEAD_BEEF)return vec4(1,1,0,1);//Yellow means 0xDEADBEEF (unwritten) reverse[4022250974][3735928559u]
 uvec4 	tocHeader 	= texelFetch(rootBuffer,int(textureID+TOC_OFFSET_VEC4_HEADER));
 if(tocHeader[TOC_HEADER_OFFSET_QUADS_MAGIC]!=1337u)return vec4(1,0,1,1);//Magenta means invalid texture.
 
 //uint	renderFlags = tocHeader[TOC_HEADER_OFFSET_QUADS_RENDER_FLAGS];
 uv = clamp(uv-.5,0,4096);

 return uint(logn(fsq.x,16));
}

vec3 getPQuad(uint primitiveID){
 vec2	corner		= vec2(primitiveID%PRIMS_PER_ROW,primitiveID/PRIMS_PER_ROW);
 return				vec3(corner + halfScreenLocOffset,PQUAD_DENOM);
}

float getTextureID(uint primitiveID){
 uint vertexID = primitiveID * 3u;
 return texelFetch(
  vertexTextureIDTexture,
  ivec2(vertexID%VTX_TEXTURE_USABLE_WIDTH,
  vertexID/VTX_TEXTURE_USABLE_WIDTH),0).x
   *(65536u*PAGE_SIZE_VEC4);
}

////////// STRUCT LAYOUT DOCUMENTATION ///////////////
