Skip to content
Snippets Groups Projects
Commit d0c0d8e7 authored by Alexander Rose's avatar Alexander Rose
Browse files

require standardDerivatives glsl extension

parent ebf64404
No related branches found
No related tags found
No related merge requests found
......@@ -17,7 +17,6 @@ const shaderCodeId = idFactory();
type ShaderExtensionsValue = 'required' | 'optional'
export interface ShaderExtensions {
readonly standardDerivatives?: ShaderExtensionsValue
readonly fragDepth?: ShaderExtensionsValue
readonly drawBuffers?: ShaderExtensionsValue
readonly shaderTextureLod?: ShaderExtensionsValue
......@@ -163,7 +162,7 @@ export const CylindersShaderCode = ShaderCode('cylinders', cylinders_vert, cylin
import { text_vert } from './shader/text.vert';
import { text_frag } from './shader/text.frag';
export const TextShaderCode = ShaderCode('text', text_vert, text_frag, { standardDerivatives: 'required', drawBuffers: 'optional' });
export const TextShaderCode = ShaderCode('text', text_vert, text_frag, { drawBuffers: 'optional' });
import { lines_vert } from './shader/lines.vert';
import { lines_frag } from './shader/lines.frag';
......@@ -171,7 +170,7 @@ export const LinesShaderCode = ShaderCode('lines', lines_vert, lines_frag, { dra
import { mesh_vert } from './shader/mesh.vert';
import { mesh_frag } from './shader/mesh.frag';
export const MeshShaderCode = ShaderCode('mesh', mesh_vert, mesh_frag, { standardDerivatives: 'optional', drawBuffers: 'optional' });
export const MeshShaderCode = ShaderCode('mesh', mesh_vert, mesh_frag, { drawBuffers: 'optional' });
import { directVolume_vert } from './shader/direct-volume.vert';
import { directVolume_frag } from './shader/direct-volume.frag';
......@@ -209,11 +208,9 @@ function getDefinesCode(defines: ShaderDefines) {
}
function getGlsl100FragPrefix(extensions: WebGLExtensions, shaderExtensions: ShaderExtensions) {
const prefix: string[] = [];
if (shaderExtensions.standardDerivatives) {
prefix.push('#extension GL_OES_standard_derivatives : enable');
prefix.push('#define enabledStandardDerivatives');
}
const prefix: string[] = [
'#extension GL_OES_standard_derivatives : enable'
];
if (shaderExtensions.fragDepth) {
if (extensions.fragDepth) {
prefix.push('#extension GL_EXT_frag_depth : enable');
......@@ -268,9 +265,6 @@ function getGlsl300FragPrefix(gl: WebGL2RenderingContext, extensions: WebGLExten
`layout(location = 0) out highp ${outTypes[0] || 'vec4'} out_FragData0;`
];
if (shaderExtensions.standardDerivatives) {
prefix.push('#define enabledStandardDerivatives');
}
if (shaderExtensions.fragDepth) {
prefix.push('#define enabledFragDepth');
}
......
......@@ -19,14 +19,10 @@ void main() {
#include clip_pixel
// Workaround for buggy gl_FrontFacing (e.g. on some integrated Intel GPUs)
#if defined(enabledStandardDerivatives)
vec3 fdx = dFdx(vViewPosition);
vec3 fdy = dFdy(vViewPosition);
vec3 faceNormal = normalize(cross(fdx,fdy));
bool frontFacing = dot(vNormal, faceNormal) > 0.0;
#else
bool frontFacing = dot(vNormal, vViewPosition) < 0.0;
#endif
#if defined(dFlipSided)
interior = frontFacing;
......@@ -48,7 +44,7 @@ void main() {
#ifdef dIgnoreLight
gl_FragColor = material;
#else
#if defined(dFlatShaded) && defined(enabledStandardDerivatives)
#if defined(dFlatShaded)
vec3 normal = -faceNormal;
#else
vec3 normal = -normalize(vNormal);
......
......@@ -36,13 +36,11 @@ export function createExtensions(gl: GLRenderingContext): WebGLExtensions {
if (elementIndexUint === null) {
throw new Error('Could not find support for "element_index_uint"');
}
const standardDerivatives = getStandardDerivatives(gl);
if (isDebugMode && standardDerivatives === null) {
// - non-support handled downstream (flat shading option is ignored)
// - can't be a required extension because it is not supported by `headless-gl`
console.log('Could not find support for "standard_derivatives"');
if (standardDerivatives === null) {
throw new Error('Could not find support for "standard_derivatives"');
}
const textureFloat = getTextureFloat(gl);
if (isDebugMode && textureFloat === null) {
console.log('Could not find support for "texture_float"');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment