High-performance `fast-powi` crate
@mikem8891 M
·
2026-04-24
·
via The Rust Programming Language Forum - Latest posts
Your right. I forgot about Phong–Blinn style specular highlights. I wrote one a few year ago while playing with WebGL, WebGL Demo 7: Normal Map . In my example I use a power of 256! The power is just beyond what my fast-powi crate can handle. The highlight intensity usually get written into the shader, so I am not sure it is applicable to for use with Rust (unless you can compile Rust into shaders, ¯_(ツ)_/¯ ). github.com/mikem8891/WebGL Demo_7/fshader.glsl 2fc5fe01a vec4 texel = texture2D(samplerText, fragTexCoord); #if Convert_sRGB_to_Lin texel = texel * texel; #endif vec4 texelSpec = texture2D(samplerSpec, fragTexCoord); vec3 lightInt = ambLightInt + // ambient light sun.color * max(dot(normSunDir, surfaceNorm), 0.0); // diffuse light vec3 specInt = texelSpec.rgb * sun.color * pow(max(dot(normalize(viewPos - fragPosition), reflectedRay), 0.0), 256.0); // specular light vec4 colorLin = texel * vec4(lightInt, 1.0) + vec4(specInt, 1.0); gl_FragColor = pow(colorLin, vec4(1.0/GAMMA)); // pseudo gamma correction // gl_FragColor = vec4(surfaceNorm, 1.0); // display normals for debugging }
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。