Advertisement Jump to content
Sign in to follow this  
Eitsch

OpenGL Problems with CG fragment shader

This topic is 4903 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

don't get it working - http://www.gamedev.net/columns/hardcore/cgbumpmapping 1st test computer: imac g5 with geforce fx 5200 2nd computer: pc with geforce 4200TI my result... Bild 1.png the opengl setup is ok. what could be the reason?

Share this post


Link to post
Share on other sites
Advertisement
the shader (of the example):


float4 main(float2 detailCoords : TEXCOORD0,
float2 bumpCoords: TEXCOORD1,
float3 lightVector : COLOR0,
float3 halfVector : COLOR1,
uniform float3 ambientColor,
uniform float3 specularColor,
uniform sampler2D detailTexture : TEXUNIT0,
uniform sampler2D bumpTexture : TEXUNIT1): COLOR
{
float3 detailColor = tex2D(detailTexture, detailCoords).rgb;

// Uncompress vectors ([0, 1] -> [-1, 1])
float3 lightVectorFinal = 2.0 * (lightVector.rgb - 0.5);

float3 bumpNormalVectorFinal = 2.0 * (tex2D(bumpTexture, bumpCoords).rgb - 0.5);

float3 halfVectorHalf = (halfVector.rgb - 0.5);
float3 halfVectorFinal = 2.0 * halfVectorHalf;

// Normalize half vector using Newton-Raphson approximation
halfVectorFinal =
(1 - saturate(dot(halfVectorFinal.xyz, halfVectorFinal.xyz))) *
halfVectorHalf + halfVectorFinal;

// Compute diffuse factor
float diffuse = dot(bumpNormalVectorFinal, lightVectorFinal);

// Compute specular factor
// If enough combiner stages are available, continue squaring
// the specular value to obtain a tigher spot
float specular = saturate(dot(bumpNormalVectorFinal, halfVectorFinal));
float specular2 = specular * specular;
float specular4 = specular2 * specular2;
float specular8 = specular4 * specular4;

return float4(diffuse * detailColor + specular8 * specularColor + ambientColor, 1.0);
}


the rendering function


cgGLEnableProfile(fragmentProfile);

cgGLBindProgram(program);

glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textur_liste[1]);

glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textur_liste[2]);

CGparameter ambientColorParameter = cgGetNamedParameter(program, "ambientColor");
cgGLSetParameter3f(ambientColorParameter, 1.0f, 1.0f, 1.0f);

glColor3f(1,1,1);

glBegin(GL_POLYGON);
glMultiTexCoord2f(GL_TEXTURE0,0.0,0.0);
glMultiTexCoord2f(GL_TEXTURE1,0.0,0.0);
glVertex3f(0.0,0.0,0.0);
glMultiTexCoord2f(GL_TEXTURE0,1.0,0.0);
glMultiTexCoord2f(GL_TEXTURE1,1.0,0.0);
glVertex3f(1.0,0.0,0.0);
glMultiTexCoord2f(GL_TEXTURE0,1.0,1.0);
glMultiTexCoord2f(GL_TEXTURE1,1.0,1.0);
glVertex3f(1.0,1.0,0.0);
glMultiTexCoord2f(GL_TEXTURE0,0.0,1.0);
glMultiTexCoord2f(GL_TEXTURE1,0.0,1.0);
glVertex3f(0.0,1.0,0.0);
glMultiTexCoord2f(GL_TEXTURE0,0.0,0.0);
glMultiTexCoord2f(GL_TEXTURE1,0.0,0.0);
glVertex3f(0.0,0.0,0.0);
glEnd();

glutSwapBuffers();


CG init

cgSetErrorCallback(cgErrorCallback);
context = cgCreateContext();

if (cgGLIsProfileSupported(CG_PROFILE_FP30))
{
fragmentProfile = CG_PROFILE_FP30;
cout << "Fp20" << endl;
}
else {
if (cgGLIsProfileSupported(CG_PROFILE_ARBFP1))
fragmentProfile = CG_PROFILE_ARBFP1;
else {
fprintf(stderr, "Koa scheiding.\n");
exit(1);
}
}


fragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT);
cgGLSetOptimalOptions(fragmentProfile);

program = cgCreateProgramFromFile(context, CG_SOURCE, "/Users/Harry/BumpMapping/bumpmapping/shader.cg",
fragmentProfile, NULL, NULL);

if (!cgIsProgramCompiled(program))
cgCompileProgram(program);


cgGLEnableProfile(fragmentProfile);
cgGLLoadProgram(program);



the result looks inverted...arggggg

Added source tags, please read stickies when i make them

[Edited by - phantom on August 21, 2005 9:27:20 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!