用于控制像素着色器的键盘输入
//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 将循环使用我拥有的不同模式。我该如何实施呢?
你们通常如何添加键盘控制来改变这个?谢谢
//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);
The above code uses different calculations to display lighting, in the pixel shader file I have. I need to control this from the keyboard, which needs to be declared in main and, for example, VK_A will cycle through the different modes I have. How do I go about implementing this?
How do you guys normally add keyboard controll to change this? Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为每种模式编译单独版本的着色器,可以手动编写它们,也可以使用字符串操作来生成每组源代码。
在您的应用程序中,在渲染受影响的几何体之前,跟踪当前模式并在设备上每帧设置适当的着色器。
您遇到了一些更具体的问题吗?
Compile a separate version of the shader for each mode, either hand authoring them or using string manipulation to generate each set of source code.
In your application, keep track of the current mode and set the appropriate shader on the device, each frame, before rendering the affected geometry.
Is there some more specific issue you are encountering?
拥有多个着色器的另一种方法是在着色器中使用制服来在不同的代码路径之间进行选择,并根据键盘输入循环该制服的值。
An alternative to having multiple shaders would be to use a uniform in the shader to select between different code paths and to cycle the value of that uniform based on keyboard input.