-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle uniform precision mismatches #2984
Changes from all commits
3b06e3c
e26d737
7c08b66
c9e9c64
53d8e48
2af0301
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,9 @@ define([ | |
"use strict"; | ||
|
||
function removeComments(source) { | ||
// remove inline comments | ||
source = source.replace(/\/\/.*/g, ''); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! |
||
// remove multiline comment block | ||
return source.replace(/\/\*\*[\s\S]*?\*\//gm, function(match) { | ||
// preserve the number of lines in the comment block so the line numbers will be correct when debugging shaders | ||
var numberOfLines = match.match(/\n/gm).length; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ defineSuite([ | |
'Renderer/Buffer', | ||
'Renderer/BufferUsage', | ||
'Renderer/ClearCommand', | ||
'Renderer/ContextLimits', | ||
'Renderer/DrawCommand', | ||
'Renderer/ShaderSource', | ||
'Renderer/VertexArray', | ||
|
@@ -29,6 +30,7 @@ defineSuite([ | |
Buffer, | ||
BufferUsage, | ||
ClearCommand, | ||
ContextLimits, | ||
DrawCommand, | ||
ShaderSource, | ||
VertexArray, | ||
|
@@ -77,7 +79,7 @@ defineSuite([ | |
} | ||
}); | ||
|
||
function renderFragment(context, shaderProgram) { | ||
function renderFragment(context, shaderProgram, uniformMap) { | ||
va = new VertexArray({ | ||
context : context, | ||
attributes : [{ | ||
|
@@ -97,7 +99,8 @@ defineSuite([ | |
var command = new DrawCommand({ | ||
primitiveType : PrimitiveType.POINTS, | ||
shaderProgram : shaderProgram, | ||
vertexArray : va | ||
vertexArray : va, | ||
uniformMap : uniformMap | ||
}); | ||
command.execute(context); | ||
|
||
|
@@ -355,6 +358,27 @@ defineSuite([ | |
expect(renderFragment(context, sp)).toEqual([255, 255, 255, 255]); | ||
}); | ||
|
||
it('creates duplicate uniforms if precision of uniforms in vertex and fragment shader do not match', function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's make a similar test using a built-in uniform like czm_sunDirectionWC. This is the uniform that caused the original issue (used in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the test I'm using czm_viewport. Is there a reason to use czm_sunDirectionWC besides being the first issue? Also the czm_sunDirectionWC bug won't actually happen anymore. It was added as a dependency in ShaderSource despite being in a comment. But now inline comments are removed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I see now. No, one test that covers both manual and automatic uniforms is fine (especially now that I looked at your implementation). However, my comment about the fragile test still stands. |
||
var highpFloatSupported = ContextLimits.highpFloatSupported; | ||
ContextLimits._highpFloatSupported = false; | ||
var vs = 'attribute vec4 position; uniform float u_value; varying float v_value; void main() { gl_PointSize = 1.0; v_value = u_value * czm_viewport.z; gl_Position = position; }'; | ||
var fs = 'uniform float u_value; varying float v_value; void main() { gl_FragColor = vec4(u_value * v_value * czm_viewport.z); }'; | ||
sp = ShaderProgram.fromCache({ | ||
context : context, | ||
vertexShaderSource : vs, | ||
fragmentShaderSource : fs | ||
}); | ||
var uniformMap = { | ||
u_value : function() { | ||
return 1.0; | ||
} | ||
}; | ||
expect(sp.allUniforms.u_value).toBeDefined(); | ||
expect(sp.allUniforms.czm_mediump_u_value).toBeDefined(); | ||
expect(renderFragment(context, sp, uniformMap)).not.toEqual([0, 0, 0, 0]); | ||
ContextLimits._highpFloatSupported = highpFloatSupported; | ||
}); | ||
|
||
it('1 level function dependency', function() { | ||
var vs = 'attribute vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }'; | ||
var fs = | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I'm glad we can do the remapping here instead of in
_setUniforms
.