hi im trying to get crome effect on the object using environment mapping
im able to have simple chrome effect but when i move the camera im not able to move the texture applied to the object properly im getting bulk at some positions of the camera.
here is the code
void CApp::DrawMayaModelsShader( void )
{
glDisable(GL_BLEND);
cgGLDisableProfile(m_cgFprofile);
cgGLDisableProfile(m_cgVprofile);
glEnable(GL_DEPTH_TEST);
glPushMatrix();
Vec4f eyePos_eye, eyePos_model;
eyePos_eye = Vec4f(m_Camera.GetPos(),1.0);
CMatrix4 view = m_Camera.GetViewMatrix();
CMatrix4 viewInv = view.Inverse();
eyePos_model = viewInv* eyePos_eye;
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glPushMatrix();
for(unsigned int i =0; i “less” m_vModelArray.size(); i++)
{
glPushMatrix();
cgGLBindProgram(m_CromeVprog);
cgGLEnableProfile(m_cgVprofile);
cgGLBindProgram(m_CromeFprog);
cgGLEnableProfile(m_cgFprofile);
cgGLSetParameter3f(m_EyePosParam, 0.0,0.0,0.01/eyePos_model.x, eyePos_model.y, eyePos_model.z/);
cgGLSetStateMatrixParameter(m_ModelViewProjParam, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);
cgGLSetStateMatrixParameter(m_WorldMatrixParam, CG_GL_MODELVIEW_MATRIX, CG_GL_MATRIX_IDENTITY);
cgGLSetStateMatrixParameter(m_TextureMatrixParam, CG_GL_TEXTURE_MATRIX, CG_GL_MATRIX_INVERSE_TRANSPOSE );
cgSetParameter1f(m_EtaParam, 1.0);
glRotatef(m_fCameraAngle,0.0,1.0,0.0);
m_vModelArray[i].Draw();
//glutSolidSphere(10,50,50);
//GetFanModel().Draw();
cgGLDisableProfile(m_cgFprofile);
cgGLDisableProfile(m_cgVprofile);
glPopMatrix();
}
glPopMatrix();
glPopMatrix();
glDisable(GL_DEPTH_TEST);
}
here is the shader code vertex shader
#include “Vertex.cg”
VertexOut main(VertexIn In,
uniform float4x4 ModelViewProj,
uniform float4x4 ModelView,
uniform float3 EyePos
)
{
VertexOut Out;
Out.position = mul(ModelViewProj, In.position);
Out.texcoord = In.texcoord;
Out.ViewDir = (EyePos) - Out.position.xyz;
float3 wPos = mul(ModelView, In.position).xyz;
float3 N = mul((float3x3)ModelView, In.normal);
Out.normal = normalize(N);
Out.ViewDir = normalize( (-EyePos) - normalize(Out.position.xyz) );
Out.color = In.color;
return Out;
}
here is the fragment shader code
#include “Pixel.cg”
PixelOut main(PixelIn In,
uniform float eta,
uniform samplerCUBE texCube,
uniform float4x4 TextureMatrix
)
{
PixelOut Out;
float3 ReflectDir;
ReflectDir = reflect( normalize(In.ViewDir) ,normalize(In.normal));
ReflectDir = mul(((float3x3)TextureMatrix), ReflectDir);
float4 Reflect = texCUBE(texCube,ReflectDir);
//float NDotI;
//NDotI = smoothstep(0.0,1.0,dot( normalize(In.normal) , normalize(In.ViewDir) )) ;
//NDotI += eta ;
//NDotI = clamp(NDotI,0.20,1.0);
Out.color = Reflect;// * NDotI;////float4(1,0,0,1);
return Out;
}