MatthiasBuehlmann
03-23-2012, 09:46 PM
Hello
From an animation i'd like to render a pass that shows the final normals (calculated from object and bumpmapping and so on) in object-space.
As i couldn't find a way to do this in the software, i tried to write a mentalray shader for this.
the shadercode seems to work in a simple testscene, but not in the one i want to use it with.
This is my shadercode:
struct mrNormalOutputShader_params {
miBoolean normalize;
miBoolean mapTo01;
miBoolean flipYZ;
};
extern "C" DLLEXPORT int mrNormalOutputShader_version(void) {return(2);}
extern "C" DLLEXPORT miBoolean mrNormalOutputShader(
miColor *result,
miState *state,
struct mrNormalOutputShader_params *paras)
{
miVector internalNormal = state->normal;
miVector objectSpaceNormal;
mi_normal_to_object(state,&objectSpaceNormal,&internalNormal);
if(paras->normalize){
mi_vector_normalize(&objectSpaceNormal);
}
if(paras->flipYZ){
miScalar tmpy = objectSpaceNormal.y;
objectSpaceNormal.y = objectSpaceNormal.z;
objectSpaceNormal.z = -tmpy;
}
if(paras->mapTo01){
objectSpaceNormal.x+=1.0;
objectSpaceNormal.x*=0.5;
objectSpaceNormal.y+=1.0;
objectSpaceNormal.y*=0.5;
objectSpaceNormal.z+=1.0;
objectSpaceNormal.z*=0.5;
}
result->a = 1.0;
result->r = objectSpaceNormal.x;
result->g = objectSpaceNormal.y;
result->b = objectSpaceNormal.z;
return(miTRUE);
}
I use this shader in a "mr Shader Element" render element to output a objectspace-normals pass. the direction of the output normals seems to be right qualitatively, but theyr ammount is wrong - as if some gammacorrection was applied to the values (but i did try to set different Gamma/LUT values, this only affected the visual appearance on screen, not the actual pixelvalues)
So, this is what I get:
http://neo.cycovery.com/normal_shader_problem.jpg
http://neo.cycovery.com/normal_shader_problem.jpg
in the middle top you see the normalpass output, with a pixel of the left wall testet (this wall is aligned to the world coordinate system and has no transformation applied to it). i would expect 0.5 in the green and blue channel, but i get the value 0.217
Even more strange: if i hit the "clone rendered Frame Window" button, then i get the result in the bottom right corner, where the pixelvalues deviate even more (there green and blue of the left wall have the value 0.035)
I don't see what's wrong in my shadercode... anyone can spot an error or knows how i could get that rendered correctly?
From an animation i'd like to render a pass that shows the final normals (calculated from object and bumpmapping and so on) in object-space.
As i couldn't find a way to do this in the software, i tried to write a mentalray shader for this.
the shadercode seems to work in a simple testscene, but not in the one i want to use it with.
This is my shadercode:
struct mrNormalOutputShader_params {
miBoolean normalize;
miBoolean mapTo01;
miBoolean flipYZ;
};
extern "C" DLLEXPORT int mrNormalOutputShader_version(void) {return(2);}
extern "C" DLLEXPORT miBoolean mrNormalOutputShader(
miColor *result,
miState *state,
struct mrNormalOutputShader_params *paras)
{
miVector internalNormal = state->normal;
miVector objectSpaceNormal;
mi_normal_to_object(state,&objectSpaceNormal,&internalNormal);
if(paras->normalize){
mi_vector_normalize(&objectSpaceNormal);
}
if(paras->flipYZ){
miScalar tmpy = objectSpaceNormal.y;
objectSpaceNormal.y = objectSpaceNormal.z;
objectSpaceNormal.z = -tmpy;
}
if(paras->mapTo01){
objectSpaceNormal.x+=1.0;
objectSpaceNormal.x*=0.5;
objectSpaceNormal.y+=1.0;
objectSpaceNormal.y*=0.5;
objectSpaceNormal.z+=1.0;
objectSpaceNormal.z*=0.5;
}
result->a = 1.0;
result->r = objectSpaceNormal.x;
result->g = objectSpaceNormal.y;
result->b = objectSpaceNormal.z;
return(miTRUE);
}
I use this shader in a "mr Shader Element" render element to output a objectspace-normals pass. the direction of the output normals seems to be right qualitatively, but theyr ammount is wrong - as if some gammacorrection was applied to the values (but i did try to set different Gamma/LUT values, this only affected the visual appearance on screen, not the actual pixelvalues)
So, this is what I get:
http://neo.cycovery.com/normal_shader_problem.jpg
http://neo.cycovery.com/normal_shader_problem.jpg
in the middle top you see the normalpass output, with a pixel of the left wall testet (this wall is aligned to the world coordinate system and has no transformation applied to it). i would expect 0.5 in the green and blue channel, but i get the value 0.217
Even more strange: if i hit the "clone rendered Frame Window" button, then i get the result in the bottom right corner, where the pixelvalues deviate even more (there green and blue of the left wall have the value 0.035)
I don't see what's wrong in my shadercode... anyone can spot an error or knows how i could get that rendered correctly?
