diff options
Diffstat (limited to 'src/datavis3d/engine/shaders')
-rw-r--r-- | src/datavis3d/engine/shaders/fragmentShader | 30 | ||||
-rw-r--r-- | src/datavis3d/engine/shaders/fragmentShaderAmbient | 31 | ||||
-rw-r--r-- | src/datavis3d/engine/shaders/vertexShader | 25 |
3 files changed, 86 insertions, 0 deletions
diff --git a/src/datavis3d/engine/shaders/fragmentShader b/src/datavis3d/engine/shaders/fragmentShader new file mode 100644 index 00000000..365f653e --- /dev/null +++ b/src/datavis3d/engine/shaders/fragmentShader @@ -0,0 +1,30 @@ +varying highp vec2 UV; +varying highp vec3 position_wrld; +varying highp vec3 normal_cmr; +varying highp vec3 eyeDirection_cmr; +varying highp vec3 lightDirection_cmr; +uniform highp vec3 lightPosition_wrld; +uniform highp vec3 color_mdl; +uniform highp float lightStrength; +void main() { + highp vec3 materialDiffuseColor = color_mdl; + highp vec3 materialAmbientColor = vec3(0.5, 0.5, 0.5) * materialDiffuseColor; + highp vec3 materialSpecularColor = vec3(1.0, 1.0, 1.0); + highp float distance = length(lightPosition_wrld - position_wrld); + highp vec3 n = normalize(normal_cmr); + highp vec3 l = normalize(lightDirection_cmr); + highp float cosTheta = dot(n, l); + if (cosTheta < 0.0) { cosTheta = 0.0; } + if (cosTheta > 1.0) { cosTheta = 1.0; } + highp vec3 E = normalize(eyeDirection_cmr); + highp vec3 R = reflect(-l, n); + highp float cosAlpha = dot(E, R); + if (cosAlpha < 0.0) { cosAlpha = 0.0; } + if (cosAlpha > 1.0) { cosAlpha = 1.0; } + gl_FragColor.rgb = //color_mdl + color_mdl * vec3(cosTheta * cosTheta) / (distance * distance) + vec3(cosAlpha * cosAlpha * cosAlpha * cosAlpha * cosAlpha * cosAlpha * cosAlpha * cosAlpha) / (distance * distance); + materialAmbientColor + + materialDiffuseColor * lightStrength * (cosTheta * cosTheta) / distance + + materialSpecularColor * lightStrength * (cosAlpha * cosAlpha * cosAlpha * cosAlpha * cosAlpha * cosAlpha * cosAlpha * cosAlpha * cosAlpha * cosAlpha) / distance;//(distance * distance); + gl_FragColor.a = 1.0; +} + diff --git a/src/datavis3d/engine/shaders/fragmentShaderAmbient b/src/datavis3d/engine/shaders/fragmentShaderAmbient new file mode 100644 index 00000000..7614570e --- /dev/null +++ b/src/datavis3d/engine/shaders/fragmentShaderAmbient @@ -0,0 +1,31 @@ +varying highp vec2 UV; +varying highp vec3 position_wrld; +varying highp vec3 normal_cmr; +varying highp vec3 eyeDirection_cmr; +varying highp vec3 lightDirection_cmr; +uniform highp vec3 lightPosition_wrld; +uniform highp vec3 color_mdl; +void main() { + highp vec3 lightColor = vec3(1.0, 1.0, 1.0); + highp float lightPower = 10.0; + highp vec3 materialAmbientColor = vec3(0.5, 0.5, 0.5) * color_mdl; + //highp vec3 materialDiffuseColor = vec3(0.1, 0.1, 0.1) * color_mdl; + highp vec3 materialSpecularColor = vec3(0.3, 0.3, 0.3) * color_mdl; + highp float distance = length(lightPosition_wrld - position_wrld); + highp vec3 n = normalize(normal_cmr); + highp vec3 l = normalize(lightDirection_cmr); + highp float cosTheta = dot(n, l); + if (cosTheta < 0.0) { cosTheta = 0.0; } + if (cosTheta > 1.0) { cosTheta = 1.0; } + highp vec3 E = normalize(eyeDirection_cmr); + highp vec3 R = reflect(-l, n); + highp float cosAlpha = dot(E, R); + if (cosAlpha < 0.0) { cosAlpha = 0.0; } + if (cosAlpha > 1.0) { cosAlpha = 1.0; } + gl_FragColor.rgb = + materialAmbientColor + + //materialDiffuseColor * lightColor * lightPower * cosTheta / (distance * distance) + + materialSpecularColor * lightColor * lightPower * (cosAlpha * cosAlpha * cosAlpha * cosAlpha * cosAlpha) / (distance * distance); + gl_FragColor.a = 1.0; +} + diff --git a/src/datavis3d/engine/shaders/vertexShader b/src/datavis3d/engine/shaders/vertexShader new file mode 100644 index 00000000..19f9d617 --- /dev/null +++ b/src/datavis3d/engine/shaders/vertexShader @@ -0,0 +1,25 @@ +attribute highp vec3 vertexPosition_mdl; +attribute highp vec2 vertexUV; +attribute highp vec3 vertexNormal_mdl; +uniform highp mat4 MVP; +uniform highp mat4 V; +uniform highp mat4 M; +uniform highp mat4 itM; +uniform highp vec3 lightPosition_wrld; +varying highp vec2 UV; +varying highp vec3 position_wrld; +varying highp vec3 normal_cmr; +varying highp vec3 eyeDirection_cmr; +varying highp vec3 lightDirection_cmr; +varying highp vec2 coords_mdl; +void main() { + gl_Position = MVP * vec4(vertexPosition_mdl, 1.0); + coords_mdl = vertexPosition_mdl.xy; + position_wrld = (M * vec4(vertexPosition_mdl, 1.0)).xyz; + vec3 vertexPosition_cmr = (V * M * vec4(vertexPosition_mdl, 1.0)).xyz; + eyeDirection_cmr = vec3(0.0, 0.0, 0.0) - vertexPosition_cmr; + vec3 lightPosition_cmr = (V * vec4(lightPosition_wrld, 1.0)).xyz; + lightDirection_cmr = lightPosition_cmr + eyeDirection_cmr; + normal_cmr = (V * itM * vec4(vertexNormal_mdl, 0.0)).xyz; // Use modelMatrix's transposed inverse, as it's scaled + UV = vertexUV; +} |