Samstag, 22. November 2014
/*
wallshader (c) 2014 dirk hochegger
*/
[VERT-SHADER]
attribute vec3 aVertexPosition;
attribute vec2 aTextureCoord;
attribute vec4 aNormalCoord;
uniform mat4 viewMAT;
uniform mat4 projMAT;
uniform mat4 worldMAT;
uniform bool is2D;
uniform vec2 UV_gridCNT;
uniform vec2 UV_POS;
varying vec2 vTextureCoord;
varying vec4 vpos;
varying vec4 vpos1;
varying vec4 normals;
varying mat4 worldMATRIX;
void main(void) {
vec4 vertPOS = vec4(aVertexPosition.x,aVertexPosition.y,aVertexPosition.z,1.0);
vpos1 = vertPOS;
if(is2D){
vpos =viewMAT * worldMAT * vertPOS;
}
else{
vpos = projMAT * viewMAT * worldMAT * vec4(vertPOS.x,vertPOS.y,vertPOS.z,vertPOS.w);
}
worldMATRIX = worldMAT;
normals = aNormalCoord;
vTextureCoord = aTextureCoord;
gl_PointSize = 10.0;
gl_Position = vpos;
}
/*
vec3 wallBLOOD(){
}
vec3 wallFX(){
wallBLOOD();
}*/
[PIXEL-SHADER]
precision highp float;
varying vec2 vTextureCoord;
uniform vec4 uCOLOR;
uniform sampler2D rootSAMPLER;
/*mask*/
uniform sampler2D maskSAMPLER;
uniform sampler2D maskDENSITY_SAMPLER;
uniform sampler2D patternSAMPLER;
/*normals*/
uniform sampler2D nrmlSAMPLER_BRICKS;
uniform sampler2D nrmlSAMPLER_DIRT;
uniform sampler2D nrmlSAMPLER_PAINT;
uniform sampler2D nrmlSAMPLER_ETC;
/*color*/
uniform sampler2D colSAMPLER_BRICKS;
uniform sampler2D colSAMPLER_DIRT;
uniform sampler2D colSAMPLER_PAINT;
uniform sampler2D colSAMPLER_ETC;
/*detail*/
uniform sampler2D brickDETAIL1_SAMPLER;
/*light*/
uniform sampler2D lightMAP_SAMPLER;
uniform vec3 lightPOS;
uniform vec4 uvINFO0;
uniform vec4 uvINFO1;
uniform vec4 genINFO0;
varying mat4 worldMATRIX;
varying vec4 vpos1;
vec3 normals(vec4 mask){
float ru = uvINFO0.x;
float rv = uvINFO0.y;
float brickMASK = mask.x;
float dirtMASK = mask.y;
float paintMASK = mask.z;
float densityMASK = texture2D(maskDENSITY_SAMPLER,vec2(vTextureCoord.s,vTextureCoord.t)).x;
vec4 nBRICKS = texture2D(nrmlSAMPLER_BRICKS,vec2(vTextureCoord.s*ru*(1.0+ (densityMASK/2.0)),vTextureCoord.t*rv*(1.0+(densityMASK/2.0))))*brickMASK;
vec4 nBRICKS_detail = texture2D(brickDETAIL1_SAMPLER,vec2(vTextureCoord.s*ru,vTextureCoord.t*rv))*brickMASK;
nBRICKS += nBRICKS_detail;
nBRICKS /= 2.0;
nBRICKS = normalize(nBRICKS);
ru = uvINFO0.z;
rv = uvINFO0.w;
vec4 nDIRT = texture2D(nrmlSAMPLER_DIRT,vec2(vTextureCoord.s*ru,vTextureCoord.t*rv))*dirtMASK;
ru = uvINFO1.x;
rv = uvINFO1.y;
vec4 nPAINT = texture2D(nrmlSAMPLER_PAINT,vec2(vTextureCoord.s*ru,vTextureCoord.t*rv))*paintMASK;
ru = 1.0;
rv = 1.0;
float etcMASK = texture2D(maskSAMPLER,vec2(vTextureCoord.s,vTextureCoord.t)).w;
vec4 nETC = texture2D(nrmlSAMPLER_ETC,vec2(vTextureCoord.s*ru,vTextureCoord.t*rv))*etcMASK;
vec3 nrmls = vec3(nDIRT.xyz+nBRICKS.xyz+nPAINT.xyz);
nrmls -= nBRICKS.xyz*paintMASK;
nrmls -= nDIRT.xyz*paintMASK;
nrmls = normalize(nrmls);
nrmls.x = -.5+nrmls.x;
nrmls.y = -.5+nrmls.y;
nrmls.z = -.5+nrmls.z;
vec4 alignedNRMLS = worldMATRIX * vec4(nrmls,1.0);
nrmls = alignedNRMLS.xyz;
return nrmls;
}
vec3 darkWRINKLES(){
float offX = (1.0/2048.0)*10.0;
float offY = (1.0/2048.0)*10.0;
float ru = uvINFO0.x;
float rv = uvINFO0.y;
float densityMASK = texture2D(maskDENSITY_SAMPLER,vec2(vTextureCoord.s,vTextureCoord.t)).x;
vec4 center = texture2D(nrmlSAMPLER_BRICKS,vec2(vTextureCoord.s,vTextureCoord.t));
vec4 left = texture2D(nrmlSAMPLER_BRICKS,vec2(vTextureCoord.s-offX,vTextureCoord.t));
vec4 right = texture2D(nrmlSAMPLER_BRICKS,vec2(vTextureCoord.s+offX,vTextureCoord.t));
vec4 up = texture2D(nrmlSAMPLER_BRICKS,vec2(vTextureCoord.s,vTextureCoord.t+offY));
vec4 down = texture2D(nrmlSAMPLER_BRICKS,vec2(vTextureCoord.s,vTextureCoord.t-offY));
vec4 v0 = center - left;
vec4 v1 = center - right;
vec4 v2 = center - up;
vec4 v3 = center - down;
float len = dot(center,v0);
float len1 = dot(center,v1);
float len2 = dot(center,v2);
float len3 = dot(center,v3);
len += len1 + len2 + len3;
len /= 4.0;
vec3 wrinkles = vec3(len,len,len);
wrinkles = 1.0 - wrinkles;
return wrinkles;
}
vec3 shaded(vec3 nrmls){
vec3 lVEC = lightPOS - vpos1.xyz;
float shade = dot(lVEC,nrmls);
vec3 shading = vec3(shade,shade,shade);
return shading;
}
vec4 pattern(){
vec4 pattern = vec4(0.0,0.0,0.0,0.0);
/*
for(int i=0;i<1;i++){
float size = 5.0;
float random;
vec4 testPATTERN = texture2D(patternSAMPLER,vec2(vTextureCoord.s*size*random,vTextureCoord.t*size*random));
if(testPATTERN.x >= .1){
pattern += testPATTERN;
}
else{
pattern += vec4(0.0,0.0,0.0,0.0);
}
}*/
vec4 testPATTERN = texture2D(patternSAMPLER,vec2(vTextureCoord.s*10.0,vTextureCoord.t*10.0));
return testPATTERN;
}
vec3 textureLIGHT(vec3 nrmls,float spec){
vec3 light = texture2D(lightMAP_SAMPLER,vec2(vTextureCoord.s*nrmls.x+.5,vTextureCoord.t*nrmls.z+.5)).xyz*spec;
return light;
}
vec4 difuse(vec4 mask){
float brickMASK = mask.x;
float dirtMASK = mask.y;
float paintMASK = mask.z;
vec4 col = vec4(0.0,0.0,0.0,0.0);
float ru = uvINFO0.x;
float rv = uvINFO0.y;
float densityMASK = texture2D(maskDENSITY_SAMPLER,vec2(vTextureCoord.s,vTextureCoord.t)).x;
vec4 brick = texture2D(colSAMPLER_BRICKS,vec2(vTextureCoord.s*ru*(1.0+(densityMASK/2.0)),vTextureCoord.t*rv*(1.0+(densityMASK/2.0))));
/*brick.x = pow(brick.x,2.0);
brick.y = pow(brick.y,2.0);
brick.z = pow(brick.z,2.0);*/
vec4 dirt = vec4(.75*dirtMASK,.7*dirtMASK,.75*dirtMASK,1.0);
vec4 p = vec4(.2*paintMASK,.22*paintMASK,.2*paintMASK,1.0);
brick.w = p.x;
float diffBRICK_r = brick.x;
float diffBRICK_g = brick.y;
float diffBRICK_b = brick.z;
float diffDIRT_r = brick.x;
float diffDIRT_g = brick.y;
float diffDIRT_b = brick.z;
col = p+dirt+brick;
col.x -= diffBRICK_r*paintMASK;
col.y -= diffBRICK_g*paintMASK;
col.z -= diffBRICK_b*paintMASK;
col.x -= diffDIRT_r*dirtMASK;
col.y -= diffDIRT_g*dirtMASK;
col.z -= diffDIRT_b*dirtMASK;
return col;
}
void main(void) {
float ru = 1.0;
float rv = 1.0;
vec4 rootMAP = texture2D(nrmlSAMPLER_DIRT,vec2(vTextureCoord.s*ru,vTextureCoord.t*rv));
vec4 mask = texture2D(maskSAMPLER,vec2(vTextureCoord.s,vTextureCoord.t));
vec3 nrmls = normals(mask);
vec4 shading = vec4(shaded(nrmls),1.0);
/*vec4 p = pattern();*/
vec4 paint = difuse(mask);
float spec = paint.w;
vec3 dw = darkWRINKLES();
vec3 lit = textureLIGHT(nrmls,spec);
vec4 col = shading * vec4(paint.xyz,1.0);
col *= vec4(lit*(genINFO0.x),1.0);
gl_FragColor = col;/* vec4(dw,1.0);*/
}
Abonnieren
Kommentare zum Post (Atom)
Keine Kommentare:
Kommentar veröffentlichen