GLSL gl_LightSource点/方向/点差异 [英] GLSL gl_LightSource point/directional/spot differentiation

查看:177
本文介绍了GLSL gl_LightSource点/方向/点差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个GLSL程序,作为在封闭源3D应用程序Maya中运行的插件的一部分.我的插件将自定义几何图形渲染到与应用程序呈现其默认多边形几何图形相同的图像缓冲区中.该应用程序使用OpenGL固定管线进行照明和着色,但是我正在使用GLSL渲染自定义几何图形和材质.

I am writing a GLSL program as part of a plugin that runs inside of Maya, a closed-source 3D application. My plugin renders custom geometry into the same image buffer that the application renders it's default polygonal geometry. The application uses the OpenGL fixed pipeline for it's lighting and shading but I am using GLSL to render custom geometry and materials.

我的问题是,我想模仿着色器中固定管线灯的行为.该应用程序以gl_LightSource制服定义灯光,我希望它们在分配给我的自定义几何图形时具有与在分配给应用程序的默认多边形几何图形时相同的方向,强度等.

My problem is, I want to mimic the behavior of the fixed pipeline lights in my shader. The application defines the lights in the gl_LightSource uniform and I want them to have the same direction, intensity etc when assigned to my custom geometry that they have when assigned to the application's default polygonal geometry.

gl_LightSource字段有明确的文档说明,但是我找不到关于固定管道如何解释这些字段的权威文档.关于如何在GLSL中对点/方向/点光源进行编码,有很多示例,但它们似乎并不能完全模仿固定管线.例如,如果应用程序定义了它们的混合,您如何确定光源是点光源,定向光源还是点光源?可以在不为着色器引入过多分支的情况下处理多种灯光类型吗?

The gl_LightSource fields are clearly documented but I cannot find definitive documentation of how the fixed-pipeline interprets those fields. There are many examples of how to code point/directional/spot lights in GLSL but they do not seem to exactly mimic the fixed pipeline. For example, how do you determine if a light is a point, directional or spot light if the application defines a mix of them? Can a mix of light types be handled without introducing excessive branching in my shader?

简而言之,是否有任何权威性文档或固定功能管道如何评估gl_LightSource的示例?

In short, is there any definitive documentation or example of how the fixed function pipeline evaluates gl_LightSource?

推荐答案

我的问题是,我想模仿片段着色器中固定管线灯的行为.

My problem is, I want to mimic the behavior of the fixed pipeline lights in my fragment shader.

您的第一个问题是,因为固定管线灯"是在 vertex 处理器中实现的,而不是在每个片段中实现的.

Well there's your first problem, because the "fixed pipeline lights" are implemented in the vertex processor, not per-fragment.

简而言之,关于固定函数管道如何评估gl_LightSource,是否有任何权威性的文档或示例?

In short, is there any definitive documentation or example of how the fixed function pipeline evaluates gl_LightSource?

是的.它称为"OpenGL图形系统:规范".可从OpenGL注册表中下载下载;您需要兼容性配置文件. 4.2兼容性规范的2.13节涵盖了用于照明的所有数学运算.只需将其转换为GLSL代码即可.

Yes. It's called "The OpenGL Graphics System: A Specification." It's available for download on the OpenGL Registry; you want the compatibility profile. Section 2.13 of the 4.2 compatibility specification covers all of the math used for lighting. Simply translate that into GLSL code.

请注意,您将无法精确地模仿固定功能管道.也就是说,没有办法保证基于着色器的照明和固定功能的照明之间的不变性.您会得到接近的结果,但没有二进制相同的值.

Note that you're not going to be able to exactly mimic the fixed-function pipeline. That is, there is no way to guarantee invariance between shader-based and fixed-function lighting.You'll get something close, but not binary-identical values.

是否可以处理多种灯光类型而不会在我的着色器中引入过多的分支?

Can a mix of light types be handled without introducing excessive branching in my shader?

您如何定义过多"?您将需要分支,因为OpenGL的光照方程式涉及条件逻辑.

How do you define "excessive"? You're going to need to branch, because OpenGL's lighting equations involve conditional logic.

这通常是人们不要只是在着色器中重新实现GL照明的部分原因.如果您只编写GLSL,而不是使用数据驱动的方法,则可以提高效率.

That's generally part of the reason why people don't just re-implement GL's lighting in a shader. You can be much more efficient if you just write GLSL, rather than using a data-driven approach.

这篇关于GLSL gl_LightSource点/方向/点差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆