[Interest] Where is "shininess" in these shaders?

Rainer Wiesenfarth rainer_wiesenfarth at trimble.com
Tue May 12 18:25:36 CEST 2020


The value in question should be the materialSpecularColor term. You might
check this by simply removing the
"+ materialSpecularColor * lightStrength * pow(cosAlpha, 10))" from the
fragment shader.

The result may be too dark, so you have these options:
- introduce an additional factor from 0.0 (no specular color) to 1.0
(current) to the term above
- play with the lightStrength parameter (also affects the diffuse color
part)
- play with the lightColor parameter (also affects the ambient color part)

HTH, and cheers
Rainer


On Tue, May 12, 2020 at 5:18 PM Tom O'Reilly <oreilly at mbari.org> wrote:

> I have little experience with OpenGL shader programs - can someone please
> help me understand some GLSL shader code?
>
> I have source code for Qt 5.14.2, including DataVisualization, and would
> like to modify the source to reduce specular “shininess” from Surface3D. This
> screenshot
> <https://drive.google.com/file/d/1Sx8d8guY1T13EkRaql5WVlMfowe1ai3j/view?usp=sharing>
> shows a Surface3D that depicts topography, and it has a very “shiny” look
> to it. Debugging with gdb I’ve determined that the following shaders are
> generating this surface. Could someone please comment on how this shader
> code affects the shininess of the surface? The code doesn't look like it's
> directly based on the Phong reflection model,
> <https://en.wikibooks.org/wiki/GLSL_Programming/GLUT/Specular_Highlights>
> e.g. I don't see an exponential "shininess" term in the code.
>
> Thanks very much!
>
> *vertex shader (“shadow.vert”)*
>
> #version 120
>
> uniform highp mat4 MVP;
>
> uniform highp mat4 V;
>
> uniform highp mat4 M;
>
> uniform highp mat4 itM;
>
> uniform highp mat4 depthMVP;
>
> uniform highp vec3 lightPosition_wrld;
>
> attribute highp vec3 vertexPosition_mdl;
>
> attribute highp vec3 vertexNormal_mdl;
>
> attribute highp vec2 vertexUV;
>
> 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 vec4 shadowCoord;
>
> varying highp vec2 coords_mdl;
>
> const highp mat4 bias = mat4(0.5, 0.0, 0.0, 0.0,
>
>                              0.0, 0.5, 0.0, 0.0,
>
>                              0.0, 0.0, 0.5, 0.0,
>
>                              0.5, 0.5, 0.5, 1.0);
>
> void main() {
>
>     gl_Position = MVP * vec4(vertexPosition_mdl, 1.0);
>
>     coords_mdl = vertexPosition_mdl.xy;
>
>     shadowCoord = bias * depthMVP * vec4(vertexPosition_mdl, 1.0);
>
>     position_wrld = vec4(M * vec4(vertexPosition_mdl, 1.0)).xyz;
>
>     vec3 vertexPosition_cmr = vec4(V * M * vec4(vertexPosition_mdl,
> 1.0)).xyz;
>
>     eyeDirection_cmr = vec3(0.0, 0.0, 0.0) - vertexPosition_cmr;
>
>     lightDirection_cmr = vec4(V * vec4(lightPosition_wrld, 0.0)).xyz;
>
>     normal_cmr = vec4(V * itM * vec4(vertexNormal_mdl, 0.0)).xyz;
>
>     UV = vertexUV;
>
> }
>
>
>
>
> *fragment shader (“surfaceShadowNoTex.frag”):*
>
> #version 120
>
> varying highp vec2 coords_mdl;
>
> varying highp vec3 position_wrld;
>
> varying highp vec3 normal_cmr;
>
> varying highp vec3 eyeDirection_cmr;
>
> varying highp vec3 lightDirection_cmr;
>
> varying highp vec4 shadowCoord;
>
> uniform highp sampler2DShadow shadowMap;
>
> uniform sampler2D textureSampler;
>
> uniform highp vec3 lightPosition_wrld;
>
> uniform highp float lightStrength;
>
> uniform highp float ambientStrength;
>
> uniform highp float shadowQuality;
>
> uniform highp vec4 lightColor;
>
> uniform highp float gradMin;
>
> uniform highp float gradHeight;
>
> highp vec2 poissonDisk[16] = vec2[16](vec2(-0.94201624, -0.39906216),
>
>                                       vec2(0.94558609, -0.76890725),
>
>                                       vec2(-0.094184101, -0.92938870),
>
>                                       vec2(0.34495938, 0.29387760),
>
>                                       vec2(-0.91588581, 0.45771432),
>
>                                       vec2(-0.81544232, -0.87912464),
>
>                                       vec2(-0.38277543, 0.27676845),
>
>                                       vec2(0.97484398, 0.75648379),
>
>                                       vec2(0.44323325, -0.97511554),
>
>                                       vec2(0.53742981, -0.47373420),
>
>                                       vec2(-0.26496911, -0.41893023),
>
>                                       vec2(0.79197514, 0.19090188),
>
>                                       vec2(-0.24188840, 0.99706507),
>
>                                       vec2(-0.81409955, 0.91437590),
>
>                                       vec2(0.19984126, 0.78641367),
>
>                                       vec2(0.14383161, -0.14100790));
>
> void main() {
>
>     highp vec2 gradientUV = vec2(0.0, gradMin + coords_mdl.y * gradHeight);
>
>     highp vec3 materialDiffuseColor = texture2D(textureSampler,
> gradientUV).xyz;
>
>     highp vec3 materialAmbientColor = lightColor.rgb * ambientStrength
> *
>
>           materialDiffuseColor;
>
>     highp vec3 materialSpecularColor = lightColor.rgb;
>
>     highp vec3 n = normalize(normal_cmr);
>
>     highp vec3 l = normalize(lightDirection_cmr);
>
>     highp float cosTheta = clamp(dot(n, l), 0.0, 1.0);
>
>     highp vec3 E = normalize(eyeDirection_cmr);
>
>     highp vec3 R = reflect(-l, n);
>
>     highp float cosAlpha = clamp(dot(E, R), 0.0, 1.0);
>
>     highp float bias = 0.005 * tan(acos(cosTheta));
>
>     bias = clamp(bias, 0.001, 0.01);
>
>     vec4 shadCoords = shadowCoord;
>
>     shadCoords.z -= bias;
>
>     highp float visibility = 0.6;
>
>     for (int i = 0; i < 15; i++) {
>
>         vec4 shadCoordsPD = shadCoords;
>
>         shadCoordsPD.x += cos(poissonDisk[i].x) / shadowQuality;
>
>         shadCoordsPD.y += sin(poissonDisk[i].y) / shadowQuality;
>
>         visibility += 0.025 * shadow2DProj(shadowMap, shadCoordsPD).r;
>
>     }
>
>     gl_FragColor.rgb =
>
>         (materialAmbientColor +
>
>         materialDiffuseColor * lightStrength * cosTheta +
>
>         materialSpecularColor * lightStrength * pow(cosAlpha, 10));
>
>     gl_FragColor.a = 1.0;
>
>     gl_FragColor.rgb = visibility * clamp(gl_FragColor.rgb, 0.0, 1.0);
>
> }
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> https://lists.qt-project.org/listinfo/interest
>


-- 
Software Engineer | Trimble Imaging Division
Rotebühlstraße 81 | 70178 Stuttgart | Germany
Office +49 711 22881 0 | Fax +49 711 22881 11
http://www.trimble.com/imaging/ | http://www.inpho.de/

Trimble Germany GmbH, Am Prime Parc 11, 65479 Raunheim
Eingetragen beim Amtsgericht Darmstadt unter HRB 83893,
Geschäftsführer: Rob Reeder, Jürgen Kesper
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20200512/9fbdc77c/attachment-0001.html>


More information about the Interest mailing list