Cel Shading Problem

Started by
5 comments, last by MrPickle 16 years, 1 month ago
I am doing something wrong and I don't know what :3. The model is appearing white, here's my code.

GLuint celBrightness;

void Init()
{
	GLfloat LightAmbient[]= { 0.5f, 0.5f, 0.5f, 1.0f }; 
	GLfloat LightDiffuse[]= { 1.0f, 1.0f, 1.0f, 1.0f };
	GLfloat LightPosition[]= { 0.0f, 0.0f, 2.0f, 1.0f };

	glEnable(GL_DEPTH_TEST);
	glShadeModel(GL_SMOOTH);
	glDisable (GL_LINE_SMOOTH);
	glEnable (GL_CULL_FACE);
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);
	glMatrixMode(GL_MODELVIEW);

	float celBrightnessData[16] = { 127, 127, 127, 191, 191, 191, 191, 191, 255, 255, 255, 255, 255, 255, 255, 255};
	glGenTextures(1, &celBrightness);
	glBindTexture(GL_TEXTURE_1D, celBrightness);
	glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);	
	glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
	glTexImage1D(GL_TEXTURE_1D, 0, GL_LUMINANCE, 32, 0, GL_RGB , GL_FLOAT, celBrightnessData);

	glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);	
	glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);	
	glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);
	glEnable(GL_LIGHT1);

}

void Draw()
{
	glClearColor(0.5f, 0.8f, 0.9f, 0.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
        gluLookAt(0, 1, 50, 0, 0, 0, 0, 1, 0);
        glTranslatef(g_fTransX, g_fTransY, g_fZoom); //For camera
        glRotatef(g_fSpinX, 1.0f, 0.0f, 0.0f); //For camera
        glRotatef(g_fSpinY, 0.0f, 1.0f, 0.0f); //For camera
	glColor3f(1.0f, 1.0f, 1.0f);

	glEnable(GL_LIGHTING);
	glTranslatef(0.0f, 1.3f, 0.0f);
	glBindTexture(GL_TEXTURE_1D, celBrightness);
	glEnable(GL_TEXTURE_1D);
	glutSolidTorus(1.0, 2.0, 10, 10);
	glDisable(GL_TEXTURE_1D);

	glutSwapBuffers();
}
Here to learn :)
Advertisement
I'm not sure exactly what you are trying to do, but this bit looks suspicious:

Quote:Original post by MrPickle

	float celBrightnessData[16] = { 127, 127, 127, 191, 191, 191, 191, 191, 255, 255, 255, 255, 255, 255, 255, 255};...		glTexImage1D(GL_TEXTURE_1D, 0, GL_LUMINANCE, 32, 0, GL_RGB , GL_FLOAT, celBrightnessData);


This is going to produce a white texture. Floating point color data needs to be in the range 0.0 - 1.0. Either change to using a byte buffer to load the texture data or scale the color data to the 0 to 1 range.
I'm trying to cel shade my models, in this case a torus. I think I'm missing something to do with cos.

Changing float to byte makes it render black.
Here to learn :)
Shouldn't you be using this texture in a shader by using dot(N,L) to get the texture coordinate?

Also, you have the width of the texture set to 32, but you don't provide enough data in your array to cover that. Isn't that function going to be reading past the end of your array?
Yea your whole setup is weird I guess. First, I dont know how to cel-shade in fixed function, so someone else is going to have to help you there.
But:

why is your [16] array having multiple numbers? Cel-shading means your values go from 0-255 in incremental steps say : 0,20,40,60,80....255.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

Because that's the way a tutorial was doing it :3

I thought that the variable is basically replicating this:
Here to learn :)
Well, it's no longer being one colour, I basically followed NeHe's tutorial but now it looks like this:

Fading across flatly
Photobucket

and

Random Spots of Black and Yellow
Photobucket
Here to learn :)

This topic is closed to new replies.

Advertisement