用于控制像素着色器的键盘输入

时间:2011-03-11 17:44:48

标签: c++ opengl glsl hlsl

    //pixelcolour with ambient
    //pixelcolour = vec4( textureshade*shadescale + ambient* textureshade+ textureshade*diffuseshadescale, 1.0 );   

    //ambient           
    pixelcolour += vec4(ambient*textureshade,1.0);

    //diffuse
    //pixelcolour += vec4(textureshade*diffuseshadescale, 1.0);

    //ambient && diffuse
    //pixelcolour += vec4( ambient* textureshade+ textureshade*diffuseshadescale, 1.0 );

    //ambient && specular
    //shadescale= pow(dot(h,nn),shinyness);
    //pixelcolour += vec4 ( textureshade*shadescale + ambient* textureshade, 1.0 );

    //specular && diffuse
    //shadescale= pow(dot(h,nn),shinyness);
    //pixelcolour += vec4 ( textureshade*shadescale + textureshade*diffuseshadescale , 1.0 );

    //ambient && specular && diffuse
    //shadescale= pow(dot(h,nn),shinyness);
    //pixelcolour += vec4 ( textureshade*shadescale + textureshade*diffuseshadescale + ambient*textureshade, 1.0);  

上面的代码在我拥有的像素着色器文件中使用不同的计算来显示光照。我需要从键盘控制它,需要在main中声明,例如,VK_A将循环通过我拥有的不同模式。我该如何实施呢?

你们通常如何添加键盘控制来改变它?谢谢

2 个答案:

答案 0 :(得分:1)

为每种模式编译单独版本的着色器,手动编写它们或使用字符串操作生成每组源代码。

在应用程序中,跟踪当前模式并在渲染受影响的几何体之前在每个帧上设置适当的着色器。

您遇到了一些更具体的问题吗?

答案 1 :(得分:0)

使用多个着色器的另一种方法是在着色器中使用制服来在不同的代码路径之间进行选择,并根据键盘输入循环该制服的值。

相关问题