具有统一vec3阵列的Qt3D着色器图 那么,关于如何在着色器图中正确使用统一数组的任何想法吗?

如何解决具有统一vec3阵列的Qt3D着色器图 那么,关于如何在着色器图中正确使用统一数组的任何想法吗?

更新

因此,通过从QShaderProgramBuilder打印已编译的着色器代码,我发现该着色器几乎可以工作,唯一的问题是对renderClicks的调用。这行

fragColor = (((renderClicks(clicks[10],colors[10],(((((((phongFunction(ka,kd,ks,shininess,worldPosition,normalize(((eyePosition - worldPosition))),normalize(worldNormal)))))))))))));

应该看起来像这样

fragColor = (((renderClicks(clicks,colors,normalize(worldNormal)))))))))))));

但是由于制服的名称是clicks[10]colors[10],所以我不确定是否可以解决。


问题

我在项目中使用QSceneLoader自动加载对象。现在,我想可视化对象3D表面上的点击。为此,我将遍历由场景加载器创建的实体层次结构,直到到达QShaderProgramBuilder。接下来,我将使用setFragmentShaderGraph替换着色器程序构建器中的片段着色器图-很遗憾,您不能提供包含正常着色器代码的文本文件。

我以default phong graph from GitHub为起点,并添加了自己的制服-点击次数和点击次数的颜色,均为vec3数组。不幸的是,直到我从两者中删除了数组定义之后,着色器才起作用。

当我在任意位置删除数组定义(即,用vec3 clicks代替vec3 clicks[10]并通过QVector3D而不是QVector<QVector3D>时,我得到了渲染的普通场景

我也找不到Qt3D节点编辑器mentioned here,但我怀疑它能否解决我的问题,因为在YouTube上的视频中似乎没有任何声明数组的选项。 / p>

那么,关于如何在着色器图中正确使用统一数组的任何想法吗?


注意:我已经检查了OpenGL版本4.6,所以这应该不是问题。

注意2:如果有人需要一个示例项目,请告诉我。我开始创建一个,但是即使尝试将其缩小也变得很大。尚未完成,但我可以完成并将其上传到GitHub。


代码

这是我从C ++提供数据作为参数的方式:

Qt3DRender::QParameter *clicksParameter = new Qt3DRender::QParameter(QStringLiteral("clicks"),m_clicks.constData());

我更改了着色器图,以包括以下新的prototype

"prototypes": {
        "renderClicks": {
            "inputs": ["clicks[10]","colors[10]","currentColor"],"outputs": ["result"],"parameters": {
                "type": {
                    "type": "QShaderLanguage::VariableType","value": "QShaderLanguage::Vec4"
                 }
             },"rules": [{
                "format": {
                    "api": "OpenGLCoreProfile","major": 3,"minor": 0
                 },"headerSnippets": [
                    "#pragma include :shaders/poseeditor/clicksRendering.inc.frag"
                 ],"substitution": "vec4 $result = renderClicks($clicks,$colors,$currentColor);"
            }]
        }
    },"nodes": ...

引用了clicksRendering.inc.frag中的以下着色器代码:

vec4 renderClicks(vec3 clicks[10],vec3 colors[10],vec4 currentColor) {
    return currentColor;
}

然后我添加了以下新的nodes

...
        {
            "uuid": "{00000000-0000-0000-0000-000000000026}","type": "input","parameters": {
                "name": "clicks[10]","qualifier": {
                    "type": "QShaderLanguage::StorageQualifier","value": "QShaderLanguage::Uniform"
                },"type": {
                    "type": "QShaderLanguage::VariableType","value": "QShaderLanguage::Vec3"
                }
            }
        },{
            "uuid": "{00000000-0000-0000-0000-000000000027}","parameters": {
                "name": "colors[10]",{
            "uuid": "{00000000-0000-0000-0000-000000000028}","type": "renderClicks"
        },...

我还更改了最后的边缘,以使最终的phong颜色通过我的自定义函数传递:

...
        {
            "sourceUuid": "{00000000-0000-0000-0000-000000000026}","sourcePort": "value","targetUuid": "{00000000-0000-0000-0000-000000000028}","targetPort": "clicks"
        },{
            "sourceUuid": "{00000000-0000-0000-0000-000000000027}","targetPort": "colors"
        },{
            "sourceUuid": "{00000000-0000-0000-0000-000000000024}","sourcePort": "outputColor","targetPort": "currentColor"
        },{
            "sourceUuid": "{00000000-0000-0000-0000-000000000028}","sourcePort": "result","targetUuid": "{00000000-0000-0000-0000-000000000025}","targetPort": "fragColor"
        }
...

其他信息

我尝试从新[10]的{​​{1}}中删除inputs部分。这将输出错误和错误的着色器代码:

prototype

因此,除了调用const int MAX_LIGHTS = 8; const int TYPE_POINT = 0; const int TYPE_DIRECTIONAL = 1; const int TYPE_SPOT = 2; struct Light { int type; vec3 position; vec3 color; float intensity; vec3 direction; float constantAttenuation; float linearAttenuation; float quadraticAttenuation; float cutOffAngle; }; uniform Light lights[MAX_LIGHTS]; uniform int lightCount; // Pre-convolved environment maps struct EnvironmentLight { samplerCube irradiance; // For diffuse contribution samplerCube specular; // For specular contribution }; uniform EnvironmentLight envLight; uniform int envLightCount = 0; #line 52 void adsModel(const in vec3 worldPos,const in vec3 worldNormal,const in vec3 worldView,const in float shininess,out vec3 diffuseColor,out vec3 specularColor) { diffuseColor = vec3(0.0); specularColor = vec3(0.0); // We perform all work in world space vec3 n = normalize(worldNormal); vec3 s = vec3(0.0); for (int i = 0; i < lightCount; ++i) { float att = 1.0; float sDotN = 0.0; if (lights[i].type != TYPE_DIRECTIONAL) { // Point and Spot lights // Light position is already in world space vec3 sUnnormalized = lights[i].position - worldPos; s = normalize(sUnnormalized); // Light direction // Calculate the attenuation factor sDotN = dot(s,n); if (sDotN > 0.0) { if (lights[i].constantAttenuation != 0.0 || lights[i].linearAttenuation != 0.0 || lights[i].quadraticAttenuation != 0.0) { float dist = length(sUnnormalized); att = 1.0 / (lights[i].constantAttenuation + lights[i].linearAttenuation * dist + lights[i].quadraticAttenuation * dist * dist); } // The light direction is in world space already if (lights[i].type == TYPE_SPOT) { // Check if fragment is inside or outside of the spot light cone if (degrees(acos(dot(-s,lights[i].direction))) > lights[i].cutOffAngle) sDotN = 0.0; } } } else { // Directional lights // The light direction is in world space already s = normalize(-lights[i].direction); sDotN = dot(s,n); } // Calculate the diffuse factor float diffuse = max(sDotN,0.0); // Calculate the specular factor float specular = 0.0; if (diffuse > 0.0 && shininess > 0.0) { float normFactor = (shininess + 2.0) / 2.0; vec3 r = reflect(-s,n); // Reflection direction in world space specular = normFactor * pow(max(dot(r,worldView),0.0),shininess); } // Accumulate the diffuse and specular contributions diffuseColor += att * lights[i].intensity * diffuse * lights[i].color; specularColor += att * lights[i].intensity * specular * lights[i].color; } } vec4 phongFunction(const in vec4 ambient,const in vec4 diffuse,const in vec4 specular,const in vec3 worldPosition,const in vec3 worldNormal) { // Calculate the lighting model,keeping the specular component separate vec3 diffuseColor,specularColor; adsModel(worldPosition,worldNormal,worldView,diffuseColor,specularColor); // Combine spec with ambient+diffuse for final fragment color vec3 color = (ambient.rgb + diffuseColor) * diffuse.rgb + specularColor * specular.rgb; return vec4(color,diffuse.a); } #line 11 uniform vec3 clicks[10]; uniform vec3 colors[10]; vec4 renderClicks(vec3 clicks[10],vec4 currentColor) { return currentColor; } #line 15 out vec4 fragColor; void main() { fragColor = (((renderClicks(clicks[10],normalize(worldNormal))))))))))))); } 之外,着色器看起来还不错。但是我不知道是否可以摆脱renderClicks(clicks[10],...)部分,因为那是它们的名字。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-