1. ---------------------------------------------------
  2. Qt3D ShaderPrograme
  3. Qt3D GLSL 渲染器
  4. Shader示例可参考:
  5. http://blog.csdn.net/candycat1992/article/details/44039077
  6. https://www.shadertoy.com/
  7. http://blog.csdn.net/candycat1992/article/details/44039077
  8. faq: shader的输入参数怎么各家都不一样,到底是如何定义的
  9. ---------------------------------------------------
  10. 概念
  11. 渲染代码可由ShaderProgram对象封装
  12. 参数的传递比ShaderEffect复杂得多,好麻烦
  13. 要求输出的参数是一致的(gl_Position, gl_FragColor)
  14.  
  15. Qt3D默认提供的参数
  16. attribute highp vec4 vertexPosition; // 顶点位置
  17. attribute highp vec3 vertexNormal; // 顶点法线
  18. attribute highp vec2 vertexTexCoord; // 顶点纹理坐标
  19. uniform highp mat4 mvp; // ?
  20. uniform highp mat4 modelMatrix; // ?
  21. uniform highp vec3 cameraPosition; // 相机位置
  22. uniform mat4 modelView; // ?
  23. uniform mat4 modelNormalMatrix; // ?
  24.  
  25. 常用的方法
  26. normalize
  27. dot
  28. min/mix/max/pow/
  29. textureCube
  30. highp vec4 surface = texture2D(surfaceTexture, texCoord);
  31. highp vec3 reflectedDirection = reflect(viewDirection, normalize(normal));
  32. textureCube(skyboxTexture, reflectedDirection).rgb
  33.  
  34. VertexShader
  35. // Qt 3D默认提供的参数
  36. attribute vec3 vertexPosition;
  37. attribute vec3 vertexNormal;
  38. uniform mat4 modelView;
  39. uniform mat4 modelNormalMatrix;
  40. uniform mat4 mvp;
  41. // 自己提供的参数
  42. uniform vec3 lightPosition;
  43. varying vec3 reflectVec;
  44. varying vec3 viewVec;
  45. varying float NdotL;
  46. void main( void )
  47. {
  48. vec3 ecPos = ( modelView * vec4( vertexPosition, 1.0 ) ).xyz;
  49. vec3 normal = normalize( modelNormalMatrix * vec4( vertexNormal, 1.0 ) ).xyz;
  50. vec3 lightVec = normalize( lightPosition - ecPos );
  51. reflectVec = normalize( reflect( -lightVec, normal ) );
  52. viewVec = normalize( -ecPos );
  53. NdotL = ( dot( lightVec, normal ) + 1.0 ) * 0.5;
  54. gl_Position = mvp * vec4( vertexPosition, 1.0 );
  55. }
  56.  
  57. FragmentShader
  58. // 自己提供的参数
  59. uniform vec3 surfaceColor;
  60. uniform vec3 warmColor;
  61. uniform vec3 coolColor;
  62. uniform float diffuseWarm;
  63. uniform float diffuseCool;
  64. varying vec3 reflectVec;
  65. varying vec3 viewVec;
  66. varying float NdotL;
  67. void main( void )
  68. {
  69. vec3 kcool = min( coolColor + diffuseCool * surfaceColor, 1.0 );
  70. vec3 kwarm = min( warmColor + diffuseWarm * surfaceColor, 1.0 );
  71. vec3 kfinal = mix( kcool, kwarm, NdotL );
  72. float spec = max( dot( reflectVec, viewVec ), 0.0 );
  73. spec = pow( spec, 32.0 );
  74. gl_FragColor = vec4( min( kfinal + spec, 1.0 ), 1.0 );
  75. }
  76.  
  77. cinematic3d/BackgroundCubeMap.qml
  78. ShaderProgram {
  79. id: gles2SkyboxShader
  80. vertexShaderCode: "
  81. attribute vec3 vertexPosition;
  82. varying vec3 texCoord0;
  83. uniform mat4 mvp;
  84. void main()
  85. {
  86. texCoord0 = vertexPosition.xyz;
  87. gl_Position = vec4(mvp * vec4(vertexPosition, 1.0)).xyww; // Fail depth test always against any rendered pixel
  88. }
  89. "
  90. fragmentShaderCode: "
  91. varying highp vec3 texCoord0;
  92. uniform samplerCube skyboxTexture;
  93. void main()
  94. {
  95. gl_FragColor = textureCube(skyboxTexture, texCoord0);
  96. }
  97. "
  98. }
  99.  
  100. // 二维贴图材质
  101. Texture2D {
  102. property alias source: image.source
  103. minificationFilter: Texture.LinearMipMapLinear
  104. magnificationFilter: Texture.Linear
  105. generateMipMaps: true
  106. wrapMode {
  107. x: WrapMode.ClampToEdge
  108. y: WrapMode.ClampToEdge
  109. }
  110. TextureImage {id: image}
  111. }

Qt3D Shader的更多相关文章

  1. Qt3D

    ---------------------------------------------- 概述 - 请阅读QtHelp: Qt 3D Overview https://www.kdab.com/o ...

  2. Qt QML 2D shader

    --------------------------------------------------- Qt quick 2d shader effect ---------------------- ...

  3. (持续更新)Qt3D 学习资源

    目录 一.前言 1.1 什么是Qt3D 1.2 Qt3D 的利与弊 利:原生支持 弊处:资料过少 二.学习建议 2.1 OpenGL 学习资料 2.2 Qt3D 资料 2.2.1 视频资料 2.2.4 ...

  4. Qt3D 设置窗口背景颜色和图案

    目录 设置窗口的颜色 复杂背景的设置 最近在用 Qt3D 做三维显示,需要设置窗口Qt3DWindow背景的颜色, 查了一些资料,做一些整理,备查. 设置窗口的颜色 如果只是最简单的需求设置某一种颜色 ...

  5. OpenGL shader 中关于顶点坐标值的思考

    今天工作中需要做一个事情: 在shader内部做一些空间距离上的计算,而且需要对所有的点进行计算,符合条件的显示,不符合条件的点不显示. 思路很简单,在vertex shader内知道顶点坐标,进行计 ...

  6. CSharpGL(14)用geometry shader渲染模型的法线(normal)

    +BIT祝威+悄悄在此留下版了个权的信息说: CSharpGL(14)用geometry shader渲染模型的法线(normal) +BIT祝威+悄悄在此留下版了个权的信息说: 2016-08-13 ...

  7. 【译】Unity3D Shader 新手教程(6/6) —— 更好的卡通Shader

    本文为翻译,附上原文链接. 转载请注明出处--polobymulberry-博客园. 动机 如果你想了解以下几件事,我建议你阅读以下这篇教程: 想知道如何写一个multipass的toon shade ...

  8. 【译】Unity3D Shader 新手教程(5/6) —— Bumped Diffuse Shader

    本文为翻译,附上原文链接. 转载请注明出处--polobymulberry-博客园. 动机 如果你满足以下条件,我建议你阅读这篇教程: 你想学习片段着色器(Fragment Shader). 你想实现 ...

  9. 【译】Unity3D Shader 新手教程(4/6) —— 卡通shader(入门版)

    本文为翻译,附上原文链接. 转载请注明出处--polobymulberry-博客园. 暗黑系 动机 如果你满足以下条件,我建议你阅读这篇教程: 你想了解更多有关表面着色器的细节知识. 你想实现一个入门 ...

随机推荐

  1. CSS3 box-sizing的作用

    设置CSS盒模型为标准模型或IE模型.标准模型的宽度只包括content,二IE模型包括border和padding box-sizing属性可以为三个值之一: content-box,默认值,bor ...

  2. PHP算法学习(2) 轮训加权算法

    2019年1月8日16:10:51 svn地址:svn://gitee.com/zxadmin/live_z    代码在code里面 <?php /* * 加权轮训算法 * * * $arr ...

  3. spring boot异常积累

    1.异常:Error resolving template "xxx", template might not exist or might not be accessible.. ...

  4. django分页

    page_count = 1 current_page = int(request.GET.get('p',1)) course1 = Course.objects.all().order_by('- ...

  5. 在Fastreport里使用的CRC函数

    如标题, 是在Fastreport的脚本里运行的CRC计算函数, 包括CRC-16/CRC-32 基本是从网上找的代码, 然后改出来的 至于为什么要在FR的脚本里运行....呵呵 不要在意这些细节(找 ...

  6. 【C++】子序列匹配问题

    /* 一个串的“子序列”(subsequence)是将这个串中的一些字符提取出来得到一个新串,并且不改变它们的相对位置关系.例如,串"XDoi","XianYu!&quo ...

  7. TypeScript初探

    TypeScript初探 TypeScript什么? 官方给的定义:TypeScript是一种由微软开发的自由和开源的编程语言,它是JavaScript类型的超集,可以编译成纯JavaScript,本 ...

  8. table-一列细分为多列(合并单元格)

    这个是一个很常见的一个表格展示需求,其中最要的就两个属性 rowspan 和 colspan .他们分别就是合并行 与 合并列. 要做的效果是如图下面这个,联系电话就是合并了单元格.这个说法类似于ex ...

  9. Elasticsearch学习笔记(十一)Mapping原理

    一.Mapping的功能作用 Mapping是定义如何存储和索引一个document及其所包含字段的过程. Mapping是index和type的元数据,每个type都有自己的一个mapping,决定 ...

  10. nginx修改上传文件大小限制

    问题: 项目上线,图片上传报413错误,找了半天,原来是nginx限制了上传大小 在nginx.conf的server的location中加client_max_body_size 10m;