OpenArena Message Boards

OpenArena Contributions => Development => Topic started by: revanic on October 08, 2014, 08:53:27 PM



Title: Specular envmapping
Post by: revanic on October 08, 2014, 08:53:27 PM
This is a cross between raven's light direction envmap code and q3's default spheremap for models. Makes sure the model used actually has a light direction aswell. This allows models' envmaps to be modified by BOTH lightdirection AND viewpoint, creating a very nice specular effect. I find it to be better than raven's simple implementation, but then again I may be biased.  :P
Should be easy to figure out where this goes in the code.

Code:
if(backEnd.currentEntity && backEnd.currentEntity->e.hModel
&& (backEnd.currentEntity->lightDir[0]
|| backEnd.currentEntity->lightDir[1]
|| backEnd.currentEntity->lightDir[2])){ // to prevent faulty things from trying to use this
hasLightDir = qtrue;
}

if(backEnd.currentEntity && backEnd.currentEntity->e.hModel
&& hasLightDir){
for (i = 0 ; i < tess.numVertexes ; i++, v += 4, normal += 4, st += 2 )
{// specular envmap
VectorSubtract (backEnd.or.viewOrigin, v, viewer);
VectorNormalizeFast (viewer);
d = DotProduct (normal, viewer);

reflected[0] = normal[0]*2*d - (viewer[0] + backEnd.currentEntity->lightDir[0]);
reflected[1] = normal[1]*2*d - (viewer[1] + backEnd.currentEntity->lightDir[1]);
reflected[2] = normal[2]*2*d - (viewer[2] + backEnd.currentEntity->lightDir[2]);

st[0] = 0.5 + reflected[1] * 0.5;
st[1] = 0.5 - reflected[2] * 0.5;
}
}
else{
for (i = 0 ; i < tess.numVertexes ; i++, v += 4, normal += 4, st += 2 )
{// normal envmap based on raven's setup
VectorSubtract (backEnd.or.viewOrigin, v, viewer);
VectorNormalizeFast (viewer);

d = DotProduct (normal, viewer);

reflected[0] = normal[0]*2*d - viewer[0];
reflected[1] = normal[1]*2*d - viewer[1];
reflected[2] = normal[2]*2*d - viewer[2];

st[0] = 0.5 + reflected[0] * 0.5;
st[1] = 0.5 - reflected[1] * 0.5;
}
}


Title: Re: Specular envmapping
Post by: fromhell on October 08, 2014, 09:31:58 PM
I actually have something similar implemented for an experimental celshading environmentmap (no relation to the other celshade stuff in the engine backported from zeq2)


Title: Re: Specular envmapping
Post by: revanic on October 08, 2014, 09:42:23 PM
Really? I thought you weren't going to do celshading? Unless it's mostly a test type thing.


Title: Re: Specular envmapping
Post by: fromhell on October 08, 2014, 10:03:07 PM
It was kind of a test type thing.

r_anime would activate it, and try to load shaders prefixed _cel after any shader for an available 'cel' version, and this cel shader would have multiple stages involving tcGen celshading or so.


Title: Re: Specular envmapping
Post by: revanic on November 09, 2014, 12:41:34 PM
I found the code you were talking about in github and i found something:
Code:
 (directedLight[0] + directedLight[1] + directedLight[2] / 3);
I don't know if you changed it already considering this may be old, but the / 3 should go on the outside of the parenthesis. Otherwise it's only dividing directedLight[2] and not the whole thing. Ignore me if you already figured that out :p