Created
March 19, 2014 02:09
-
-
Save zeux/9634255 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rayattribute vec3 color; | |
varying vec3 normal; | |
varying vec2 uv; | |
uniform sampler2D diffuseTexture; | |
uniform int hasDiffuseTexture; | |
uniform vec4 diffuseColor; | |
uniform sampler2D opacityTexture; | |
uniform int hasOpacityTexture; | |
void setup() | |
{ | |
rl_OutputRayCount[0]=1; | |
if(hasOpacityTexture==1) | |
rl_OutputRayCount[0]++; | |
} | |
void main() | |
{ | |
float alpha = 1.0; | |
if(hasOpacityTexture==1) | |
{ | |
alpha = texture2D(opacityTexture, uv).x; | |
if(alpha<1.0) | |
{ | |
createRay(); | |
rl_OutRay.maxT= rl_InRay.maxT - rl_IntersectionT; | |
rl_OutRay.origin = rl_IntersectionPoint; | |
rl_OutRay.color = rl_InRay.color*(1.0-alpha); | |
emitRay(); | |
} | |
} | |
if(rl_InRay.occlusionTest) | |
return; | |
if(alpha==0.0) | |
return; | |
//Get normal | |
vec3 n = normalize(normal); | |
if(!rl_FrontFacing) | |
n*=-1.0; | |
vec4 diffuse = diffuseColor; | |
if(hasDiffuseTexture==1) | |
diffuse *= texture2D(diffuseTexture,uv); | |
vec3 lightColor=vec3(0.0); | |
vec3 lightVect; | |
float maxT; | |
accumulate(rl_InRay.color*diffuse.xyz*LightingBlock.ambientColor.xyz); | |
if(!CalculateLightColor(lightColor, lightVect, maxT, 0, n, rl_IntersectionPoint)) | |
return; | |
vec3 diffuseColor = rl_InRay.color*lightColor*diffuse.xyz; | |
createRay(); | |
rl_OutRay.direction = lightVect; | |
rl_OutRay.origin = rl_IntersectionPoint; | |
rl_OutRay.color = diffuseColor; | |
rl_OutRay.occlusionTest = true; | |
rl_OutRay.defaultPrimitive = LightingBlock.lightPrimitive; | |
rl_OutRay.maxT = maxT; | |
emitRay(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment