On 27/05/2015 at 19:48, xxxxxxxx wrote:
I know this is a somewhat older thread, but maybe 'my' method can be of use to others.
What i sometimes do in an procedural shader is use the cd->vd->pp[] vectors to determine the 4 point displacement for bump mapping.
As far as i understand, the pp[] vectors are surface hits for the adjacent screen pixels in the x and y direction (given that the traced rays can be seen as frustums projecting into world space onto objects).
Vector surfp = cd->vd->p;
Vector dx = cd->vd->pp[0] - surfp;
Vector dy = cd->vd->pp[1] - surfp;
Int32 texflag = cd->texflag;
if (GET_TEX_CHANNEL(texflag) == CHANNEL_BUMP) {
switch (GET_TEX_BUMP_SAMPLE(texflag)) {
case 0: surfp -= _delta * dx; break;
case 1: surfp += _delta * dx; break;
case 2: surfp -= _delta * dy; break;
case 3: surfp += _delta * dy; break;
}
}
// use surfp instead of cd->vd->p when sampling your shadercode
// _delta is an user adjustable value, a default value of 1.0 gives nice results.
Personally this method gave me great results, far better than using a delta value only, but your mileage may vary.
One little note: the api docs state that cd->vd->pp[] is only valid if VOLUMEINFO_MIPSAT is set, but this doesn't seem necessary in a shaderdata plugin (setting it can only be done in a materialdata plugin?)