Updated shader code to v330
This commit is contained in:
@@ -4,15 +4,16 @@
|
|||||||
Shader::Shader() {
|
Shader::Shader() {
|
||||||
|
|
||||||
addCacheableShaderFromSourceCode(QOpenGLShader::Vertex, R"(
|
addCacheableShaderFromSourceCode(QOpenGLShader::Vertex, R"(
|
||||||
attribute highp vec3 a_vertex;
|
#version 330
|
||||||
attribute highp vec3 a_normal;
|
in highp vec3 a_vertex;
|
||||||
attribute lowp vec4 a_color;
|
in highp vec3 a_normal;
|
||||||
|
in lowp vec4 a_color;
|
||||||
uniform highp mat4 M;
|
uniform highp mat4 M;
|
||||||
uniform highp mat4 V;
|
uniform highp mat4 V;
|
||||||
uniform highp mat4 P;
|
uniform highp mat4 P;
|
||||||
varying highp vec3 v_normal;
|
out highp vec3 v_normal;
|
||||||
varying lowp vec4 v_color;
|
out lowp vec4 v_color;
|
||||||
varying lowp vec4 v_vertex;
|
out lowp vec4 v_vertex;
|
||||||
void main() {
|
void main() {
|
||||||
gl_Position = P * V * M * vec4(a_vertex, 1.0);
|
gl_Position = P * V * M * vec4(a_vertex, 1.0);
|
||||||
v_normal = (V * M * vec4(a_normal, 0.0)).xyz;
|
v_normal = (V * M * vec4(a_normal, 0.0)).xyz;
|
||||||
@@ -22,20 +23,23 @@ Shader::Shader() {
|
|||||||
)");
|
)");
|
||||||
|
|
||||||
addCacheableShaderFromSourceCode(QOpenGLShader::Fragment, R"(
|
addCacheableShaderFromSourceCode(QOpenGLShader::Fragment, R"(
|
||||||
|
#version 330
|
||||||
uniform vec4 color;
|
uniform vec4 color;
|
||||||
uniform bool useNormal;
|
uniform bool useNormal;
|
||||||
uniform bool useVertexColor;
|
uniform bool useVertexColor;
|
||||||
varying highp vec3 v_normal;
|
in highp vec3 v_normal;
|
||||||
varying lowp vec4 v_color;
|
in lowp vec4 v_color;
|
||||||
varying lowp vec4 v_vertex;
|
in lowp vec4 v_vertex;
|
||||||
|
|
||||||
|
layout(location=1) out vec4 fragColor;
|
||||||
void main() {
|
void main() {
|
||||||
vec3 lightPos = vec3(0,0,0); // camera
|
vec3 lightPos = vec3(0,0,0); // camera
|
||||||
//vec3 lightVec = normalize(vec3(0,0,1));
|
//vec3 lightVec = normalize(vec3(0,0,1));
|
||||||
vec3 lightVec = normalize(lightPos - v_vertex.xyz);
|
vec3 lightVec = normalize(lightPos - v_vertex.xyz);
|
||||||
float intensity = useNormal ? 0.3 + 0.7 * dot( normalize(v_normal), lightVec ) : 1.0; // light at camera pos
|
float intensity = useNormal ? 0.3 + 0.7 * dot( normalize(v_normal), lightVec ) : 1.0; // light at camera pos
|
||||||
vec4 col = useVertexColor ? v_color : color;
|
vec4 col = useVertexColor ? v_color : color;
|
||||||
gl_FragColor.rgb = col.rgb * intensity;
|
fragColor.rgb = col.rgb * intensity;
|
||||||
gl_FragColor.a = col.a;
|
fragColor.a = col.a;
|
||||||
}
|
}
|
||||||
)");
|
)");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user