---------------------------------------------------
Qt3D ShaderPrograme
Qt3D GLSL 渲染器
Shader示例可参考:
http://blog.csdn.net/candycat1992/article/details/44039077
https://www.shadertoy.com/
http://blog.csdn.net/candycat1992/article/details/44039077
faq: shader的输入参数怎么各家都不一样,到底是如何定义的
---------------------------------------------------
概念
渲染代码可由ShaderProgram对象封装
参数的传递比ShaderEffect复杂得多,好麻烦
要求输出的参数是一致的(gl_Position, gl_FragColor) Qt3D默认提供的参数
attribute highp vec4 vertexPosition; // 顶点位置
attribute highp vec3 vertexNormal; // 顶点法线
attribute highp vec2 vertexTexCoord; // 顶点纹理坐标
uniform highp mat4 mvp; // ?
uniform highp mat4 modelMatrix; // ?
uniform highp vec3 cameraPosition; // 相机位置
uniform mat4 modelView; // ?
uniform mat4 modelNormalMatrix; // ? 常用的方法
normalize
dot
min/mix/max/pow/
textureCube
highp vec4 surface = texture2D(surfaceTexture, texCoord);
highp vec3 reflectedDirection = reflect(viewDirection, normalize(normal));
textureCube(skyboxTexture, reflectedDirection).rgb VertexShader
// Qt 3D默认提供的参数
attribute vec3 vertexPosition;
attribute vec3 vertexNormal;
uniform mat4 modelView;
uniform mat4 modelNormalMatrix;
uniform mat4 mvp;
// 自己提供的参数
uniform vec3 lightPosition;
varying vec3 reflectVec;
varying vec3 viewVec;
varying float NdotL;
void main( void )
{
vec3 ecPos = ( modelView * vec4( vertexPosition, 1.0 ) ).xyz;
vec3 normal = normalize( modelNormalMatrix * vec4( vertexNormal, 1.0 ) ).xyz;
vec3 lightVec = normalize( lightPosition - ecPos );
reflectVec = normalize( reflect( -lightVec, normal ) );
viewVec = normalize( -ecPos );
NdotL = ( dot( lightVec, normal ) + 1.0 ) * 0.5;
gl_Position = mvp * vec4( vertexPosition, 1.0 );
} FragmentShader
// 自己提供的参数
uniform vec3 surfaceColor;
uniform vec3 warmColor;
uniform vec3 coolColor;
uniform float diffuseWarm;
uniform float diffuseCool;
varying vec3 reflectVec;
varying vec3 viewVec;
varying float NdotL;
void main( void )
{
vec3 kcool = min( coolColor + diffuseCool * surfaceColor, 1.0 );
vec3 kwarm = min( warmColor + diffuseWarm * surfaceColor, 1.0 );
vec3 kfinal = mix( kcool, kwarm, NdotL );
float spec = max( dot( reflectVec, viewVec ), 0.0 );
spec = pow( spec, 32.0 );
gl_FragColor = vec4( min( kfinal + spec, 1.0 ), 1.0 );
} cinematic3d/BackgroundCubeMap.qml
ShaderProgram {
id: gles2SkyboxShader
vertexShaderCode: "
attribute vec3 vertexPosition;
varying vec3 texCoord0;
uniform mat4 mvp;
void main()
{
texCoord0 = vertexPosition.xyz;
gl_Position = vec4(mvp * vec4(vertexPosition, 1.0)).xyww; // Fail depth test always against any rendered pixel
}
"
fragmentShaderCode: "
varying highp vec3 texCoord0;
uniform samplerCube skyboxTexture;
void main()
{
gl_FragColor = textureCube(skyboxTexture, texCoord0);
}
"
} // 二维贴图材质
Texture2D {
property alias source: image.source
minificationFilter: Texture.LinearMipMapLinear
magnificationFilter: Texture.Linear
generateMipMaps: true
wrapMode {
x: WrapMode.ClampToEdge
y: WrapMode.ClampToEdge
}
TextureImage {id: image}
}

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. 11 安装已集成HA的树莓派镜像Hassbian

    2017-09-04 10:40:47 下载Hassbian镜像文件,浏览https://github.com/home-assistant/pi-gen/releases/tag/v1.23,查看最 ...

  2. Python 小知识 杂七杂八 随手记

    1.assert 断言语句 例1:    print ‘11111111111’ assert 1==2 print ‘22222222’ 如果没有 assert 程序会输出  ‘1111111111 ...

  3. 小甲鱼Python第十九讲课后习题

    笔记: 1.内嵌函数:函数内部新创建另一个函数 2.闭包:函数式编程的重要语法,如果在一个内部函数里,对外部作用域(但不是在全局作用域的变量)进行引用,那么内部函数就会被认为是闭包. 3.nonloc ...

  4. 艺术模板 art-template-web

    艺术模板 art-template____jQuery 项目可用 最快的模板渲染引擎 兼容 ejs 语法 推荐语法 {{each arr}} {{$value}} ---- {{$index}} {{ ...

  5. git-format-patch

    使用方法: git diff ${old-commit} ${new-commit} > commit-operation.patch OR git format- b1af44f > c ...

  6. File类中的一些属性 添加删除文件夹

    import java.io.File; import java.io.IOException; public class FileD { public static void main(String ...

  7. map映射

    采集于:https://blog.csdn.net/luanpeng825485697/article/details/78056312 映射map: var map = new Map(); //映 ...

  8. CodeForces #549 Div.2 D. The Beatles

    题目 解题思路 关键是要 ,找出L 的组合,然后遍历L的组合,用最大公约数就可以算出来当前L的值要停多少次 怎么找出L的组合呢?饭店是每隔K 有一个,是重复的,我们只需要算出第一个饭店两侧,起点和停顿 ...

  9. 浏览器保存数据给app读取

    https://www.jianshu.com/p/239bab24d249 https://www.jianshu.com/p/43f8a81dd8ca

  10. oracleDB python chines_miscode

    oracle account lock: solutionhttp://www.cnblogs.com/jianqiang2010/archive/2011/09/01/2162574.html li ...