-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Allow texture and specularMaterial to coexist, explicitly defaulting _hasSetAmbient to false #6135
Changes from all commits
d8d1283
579809e
326edf8
e892b5d
2306de4
a537be3
38a21b9
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 |
---|---|---|
|
@@ -389,6 +389,114 @@ suite('p5.RendererGL', function() { | |
expect(pixel[1]).to.equal(128); | ||
expect(pixel[2]).to.equal(128); | ||
}); | ||
|
||
test('fill() sets _hasSetAmbient to false', function() { | ||
myp5.createCanvas(100, 100, myp5.WEBGL); | ||
myp5.noStroke(); | ||
myp5.lights(); | ||
myp5.ambientMaterial(255, 255, 255); | ||
myp5.fill(255, 0, 0); | ||
myp5.plane(100); | ||
const pixel = myp5.get(50, 50); | ||
expect(pixel[0]).to.equal(221); | ||
expect(pixel[1]).to.equal(0); | ||
expect(pixel[2]).to.equal(0); | ||
}); | ||
|
||
test('texture() sets _hasSetAmbient to false', function() { | ||
myp5.createCanvas(100, 100, myp5.WEBGL); | ||
const tex = myp5.createGraphics(256, 256); | ||
tex.noStroke(); | ||
for (let i=0; i<256; i++) { | ||
tex.fill(i, i, 255); | ||
tex.rect(0, i, 256, 1); | ||
} | ||
myp5.noStroke(); | ||
myp5.lights(); | ||
myp5.ambientMaterial(128, 128, 128); | ||
myp5.texture(tex); | ||
myp5.plane(100); | ||
const pixel = myp5.get(50, 50); | ||
expect(pixel[0]).to.equal(112); | ||
expect(pixel[1]).to.equal(112); | ||
expect(pixel[2]).to.equal(221); | ||
}); | ||
|
||
test('texture() does not set _useSpecularMaterial to false', | ||
function() { | ||
myp5.createCanvas(100, 100, myp5.WEBGL); | ||
const tex = myp5.createGraphics(256, 256); | ||
tex.noStroke(); | ||
for (let i=0; i<256; i++) { | ||
tex.fill(i, i, 255); | ||
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. If we're just doing assertions on one pixel, maybe we can do 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. I will recreate it when I create a unit test in a new pull request. Later I realized that textures can be monochromatic. excuse me. I will do so when I recreate it. |
||
tex.rect(0, i, 256, 1); | ||
} | ||
myp5.noStroke(); | ||
myp5.lights(); | ||
myp5.specularMaterial(128, 128, 128); | ||
myp5.texture(tex); | ||
myp5.plane(100); | ||
const pixel = myp5.get(50, 50); | ||
expect(pixel[0]).to.equal(240); | ||
expect(pixel[1]).to.equal(240); | ||
expect(pixel[2]).to.equal(255); | ||
} | ||
); | ||
|
||
test('ambientMaterial() does not null texture', function() { | ||
myp5.createCanvas(100, 100, myp5.WEBGL); | ||
const tex = myp5.createGraphics(256, 256); | ||
tex.noStroke(); | ||
for (let i=0; i<256; i++) { | ||
tex.fill(i, i, 255); | ||
tex.rect(0, i, 256, 1); | ||
} | ||
myp5.noStroke(); | ||
myp5.lights(); | ||
myp5.texture(tex); | ||
myp5.ambientMaterial(128, 128, 128); | ||
myp5.plane(100); | ||
const pixel = myp5.get(50, 50); | ||
expect(pixel[0]).to.equal(111); | ||
expect(pixel[1]).to.equal(111); | ||
expect(pixel[2]).to.equal(158); | ||
}); | ||
test('specularMaterial() does not null texture', function() { | ||
myp5.createCanvas(100, 100, myp5.WEBGL); | ||
const tex = myp5.createGraphics(256, 256); | ||
tex.noStroke(); | ||
for (let i=0; i<256; i++) { | ||
tex.fill(i, i, 255); | ||
tex.rect(0, i, 256, 1); | ||
} | ||
myp5.noStroke(); | ||
myp5.lights(); | ||
myp5.texture(tex); | ||
myp5.specularMaterial(128, 128, 128); | ||
myp5.plane(100); | ||
const pixel = myp5.get(50, 50); | ||
expect(pixel[0]).to.equal(240); | ||
expect(pixel[1]).to.equal(240); | ||
expect(pixel[2]).to.equal(255); | ||
}); | ||
test('emissiveMaterial() does not null texture', function() { | ||
myp5.createCanvas(100, 100, myp5.WEBGL); | ||
const tex = myp5.createGraphics(256, 256); | ||
tex.noStroke(); | ||
for (let i=0; i<256; i++) { | ||
tex.fill(i, i, 255); | ||
tex.rect(0, i, 256, 1); | ||
} | ||
myp5.noStroke(); | ||
myp5.lights(); | ||
myp5.texture(tex); | ||
myp5.emissiveMaterial(128, 128, 128); | ||
myp5.plane(100); | ||
const pixel = myp5.get(50, 50); | ||
expect(pixel[0]).to.equal(240); | ||
expect(pixel[1]).to.equal(240); | ||
expect(pixel[2]).to.equal(255); | ||
}); | ||
}); | ||
|
||
suite('loadpixels()', function() { | ||
|
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.
Maybe instead of mentioning the ambient term here, we could phrase it like:
fill
sets all reflective material colors to the specified color, but if you want to set them individually, usespeculatMaterial()
andambientMaterial()
.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.
Regarding the ambientMaterial flag, I decided not to set it to false. I will close this pull request once. I will launch a pull request on another topic (about omitting processing to null _tex), so please review it.
If I don't call ambientMaterial(), the color won't fade, so that's fine. thank you.