简体   繁体   English

Cel-Shading对BMP模型纹理的影响?

[英]Cel-Shading effect on BMP model textures?

I have stumbled across Nehe's Cel-Shading Tutorial and I was wondering if it was possible to have this technique applied to textured geometry.... 我偶然发现了Nehe的Cel-Shading教程 ,我想知道是否可以将这种技术应用于纹理几何体。

I understand that in that code the effect is obtained by applying one uni-color texture to the model, the relevant code from the tutorial I think is the following for loading the shader effect: 我了解到,在该代码中,效果是通过将一种单色纹理应用于模型而获得的,我认为来自教程的相关代码如下,用于加载着色器效果:

In = fopen ("Data\\shader.txt", "r");           // Open The Shader File

if (In)                         // Check To See If The File Opened
{
    for (i = 0; i < 32; i++)         // Loop Though The 32 Greyscale Values
    {
        if (feof (In))              // Check For The End Of The File
            break;

        fgets (Line, 255, In);          // Get The Current Line

// Copy Over The Value
        shaderData[i][0] = shaderData[i][1] = shaderData[i][2] = atof (Line);
    }

    fclose (In);                    // Close The File
}

else
    return FALSE;  

glGenTextures (1, &shaderTexture[0]);           // Get A Free Texture ID

glBindTexture (GL_TEXTURE_1D, shaderTexture[0]);    // Bind This Texture. From Now On It Will Be 1D

// For Crying Out Loud Don't Let OpenGL Use Bi/Trilinear Filtering!
glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

// Upload
glTexImage1D (GL_TEXTURE_1D, 0, GL_RGB, 32, 0, GL_RGB , GL_FLOAT, shaderData);

And the following for enabling the effect for drawing 以及以下用于启用绘图效果

// Cel-Shading Code
glEnable (GL_TEXTURE_1D);               // Enable 1D Texturing
glBindTexture (GL_TEXTURE_1D, shaderTexture[0]);    // Bind Our Texture

glColor3f (1.0f, 1.0f, 1.0f);  

....

Is there a way to run that on a model textured with a BMP GL_TEXTURE_2, and obtain a cel-shaded look of that texture? 有没有办法在带有BMP GL_TEXTURE_2纹理的模型上运行该模型,并获得该纹理的cel阴影外观?

You don't actually need a 1D texture for cel shading. 您实际上不需要1D纹理进行cel着色。 You can make it procedural by: 您可以通过以下方式使它具有程序性:

// GLSL fragment shader
vec3 colour = /* a value in range 0..1, possibly from a texture */
colour -= mod(colour, 0.2) /* limit the colour range for cel-shading */

This works because x - mod(x, M) results in a nice stepping function, M controlling the step height. 之所以x - mod(x, M)是因为x - mod(x, M)产生了很好的步进功能,M控制了步进高度。

In his tutorial on gamedev.net MENTAL gives an approach on how to apply Cel-shaded look to a textured model. 在他的gamedev.net上的教程中,MENTAL提供了一种如何将Cel阴影外观应用于纹理模型的方法。

However that approach doesn't give the desired results - the lighting appears to be very "smooth" - that is because OpenGL interpolates color values along the polygon when switched to GL_SMOOTH mode. 但是,这种方法无法提供理想的结果-光照看起来非常“平滑”-这是因为OpenGL在切换到GL_SMOOTH模式时会沿多边形插值颜色值。 I am using an old-style OpenGL 1.1 immediate mode and do not have any clue about shaders. 我使用的是旧式OpenGL 1.1立即模式,对着色器没有任何线索。

My approach is either to use multitexturing from ARB extentions or to play with alpha channel and blending. 我的方法是使用ARB扩展中的多重纹理,或者使用alpha通道和混合。 Conceptually you just set up 2 textures - one 2D for object's texture and second is 1D - for sharp lighting. 从概念上讲,您只需设置2个纹理-一个2D用于对象的纹理,第二个是1D-用于锐利的照明。

You compute the second's texture coordinate by dot product and the you either use multi-texturing through extentions (haven't tried it myself though) or render your object in 2 paths applying alpha-test and blending (or just a blending). 您可以通过点积计算第二个纹理的坐标,然后要么通过扩展使用多重纹理(虽然我自己没有尝试过),要么使用alpha测试和混合(或仅混合)在2条路径中渲染对象。 I'll try to post a source code for my experiments shortly after to exeplify this approach. 为了体现这种方法,我将在不久之后尝试发布用于实验的源代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM