@@ -76,9 +76,9 @@ const defaultShaders = {
76
76
lineDefs + readFileSync ( join ( __dirname , '/shaders/line.frag' ) , 'utf-8' ) ,
77
77
pointVert : readFileSync ( join ( __dirname , '/shaders/point.vert' ) , 'utf-8' ) ,
78
78
pointFrag : readFileSync ( join ( __dirname , '/shaders/point.frag' ) , 'utf-8' ) ,
79
- imageLightVert : readFileSync ( join ( __dirname , '/shaders/imageLight.vert' ) , 'utf-8' ) ,
80
- imageLightDiffusedFrag : readFileSync ( join ( __dirname , '/shaders/imageLightDiffused.frag' ) , 'utf-8' ) ,
81
- imageLightSpecularFrag : readFileSync ( join ( __dirname , '/shaders/imageLightSpecular.frag' ) , 'utf-8' )
79
+ imageLightVert : readFileSync ( join ( __dirname , '/shaders/imageLight.vert' ) , 'utf-8' ) ,
80
+ imageLightDiffusedFrag : readFileSync ( join ( __dirname , '/shaders/imageLightDiffused.frag' ) , 'utf-8' ) ,
81
+ imageLightSpecularFrag : readFileSync ( join ( __dirname , '/shaders/imageLightSpecular.frag' ) , 'utf-8' )
82
82
} ;
83
83
for ( const key in defaultShaders ) {
84
84
defaultShaders [ key ] = webgl2CompatibilityShader + defaultShaders [ key ] ;
@@ -538,6 +538,10 @@ p5.RendererGL = class RendererGL extends p5.Renderer {
538
538
this . _curCamera . _computeCameraDefaultSettings ( ) ;
539
539
this . _curCamera . _setDefaultCamera ( ) ;
540
540
541
+ // FilterCamera
542
+ this . filterCamera = new p5 . Camera ( this ) ;
543
+ this . filterCamera . _computeCameraDefaultSettings ( ) ;
544
+ this . filterCamera . _setDefaultCamera ( ) ;
541
545
// Information about the previous frame's touch object
542
546
// for executing orbitControl()
543
547
this . prevTouches = [ ] ;
@@ -1078,7 +1082,7 @@ p5.RendererGL = class RendererGL extends p5.Renderer {
1078
1082
// Create and store shader for constants once on initial filter call.
1079
1083
// Need to store multiple in case user calls different filters,
1080
1084
// eg. filter(BLUR) then filter(GRAY)
1081
- if ( ! ( operation in this . defaultFilterShaders ) ) {
1085
+ if ( ! ( operation in this . defaultFilterShaders ) ) {
1082
1086
this . defaultFilterShaders [ operation ] = new p5 . Shader (
1083
1087
pg . _renderer ,
1084
1088
filterShaderVert ,
@@ -1109,7 +1113,7 @@ p5.RendererGL = class RendererGL extends p5.Renderer {
1109
1113
this . _pInst . noStroke ( ) ;
1110
1114
1111
1115
// draw main to temp buffer
1112
- tmp . image ( this , - this . width / 2 , - this . height / 2 ) ;
1116
+ tmp . image ( this , - this . width / 2 , - this . height / 2 ) ;
1113
1117
1114
1118
pg . shader ( this . filterShader ) ;
1115
1119
this . filterShader . setUniform ( 'texelSize' , texelSize ) ;
@@ -1119,15 +1123,18 @@ p5.RendererGL = class RendererGL extends p5.Renderer {
1119
1123
// horiz pass
1120
1124
this . filterShader . setUniform ( 'direction' , [ 1 , 0 ] ) ;
1121
1125
this . filterShader . setUniform ( 'tex0' , tmp ) ;
1122
- pg . rect ( - this . width / 2 , - this . height / 2 , this . width , this . height ) ;
1126
+ pg . clear ( ) ;
1127
+ pg . rect ( - this . width / 2 , - this . height / 2 , this . width , this . height ) ;
1123
1128
1124
1129
// read back to temp buffer
1125
- tmp . image ( pg , - this . width / 2 , - this . height / 2 ) ;
1130
+ tmp . clear ( ) ;
1131
+ tmp . image ( pg , - this . width / 2 , - this . height / 2 ) ;
1126
1132
1127
1133
// vert pass
1128
1134
this . filterShader . setUniform ( 'direction' , [ 0 , 1 ] ) ;
1129
1135
this . filterShader . setUniform ( 'tex0' , tmp ) ;
1130
- pg . rect ( - this . width / 2 , - this . height / 2 , this . width , this . height ) ;
1136
+ pg . clear ( ) ;
1137
+ pg . rect ( - this . width / 2 , - this . height / 2 , this . width , this . height ) ;
1131
1138
1132
1139
this . _pInst . pop ( ) ;
1133
1140
}
@@ -1140,15 +1147,24 @@ p5.RendererGL = class RendererGL extends p5.Renderer {
1140
1147
// filterParameter uniform only used for POSTERIZE, and THRESHOLD
1141
1148
// but shouldn't hurt to always set
1142
1149
this . filterShader . setUniform ( 'filterParameter' , filterParameter ) ;
1143
- pg . rect ( - this . width / 2 , - this . height / 2 , this . width , this . height ) ;
1150
+ pg . rect ( - this . width / 2 , - this . height / 2 , this . width , this . height ) ;
1144
1151
1145
1152
}
1146
1153
// draw pg contents onto main renderer
1147
1154
this . _pInst . push ( ) ;
1155
+ pg . _pInst . resetMatrix ( ) ;
1148
1156
this . _pInst . noStroke ( ) ;
1149
- this . _pInst . image ( pg , - this . width / 2 , - this . height / 2 ,
1157
+ pg . _pInst . imageMode ( constants . CORNER ) ;
1158
+ pg . _pInst . blendMode ( constants . BLEND ) ;
1159
+ this . clear ( ) ;
1160
+ this . _pInst . push ( ) ;
1161
+ this . filterCamera . _resize ( ) ;
1162
+ this . _pInst . setCamera ( this . filterCamera ) ;
1163
+ this . _pInst . resetMatrix ( ) ;
1164
+ this . _pInst . image ( pg , - this . width / 2 , - this . height / 2 ,
1150
1165
this . width , this . height ) ;
1151
1166
this . _pInst . pop ( ) ;
1167
+ this . _pInst . pop ( ) ;
1152
1168
}
1153
1169
1154
1170
blendMode ( mode ) {
@@ -1765,17 +1781,17 @@ p5.RendererGL = class RendererGL extends p5.Renderer {
1765
1781
this . _defaultLightShader = new p5 . Shader (
1766
1782
this ,
1767
1783
this . _webGL2CompatibilityPrefix ( 'vert' , 'highp' ) +
1768
- defaultShaders . phongVert ,
1784
+ defaultShaders . phongVert ,
1769
1785
this . _webGL2CompatibilityPrefix ( 'frag' , 'highp' ) +
1770
- defaultShaders . phongFrag
1786
+ defaultShaders . phongFrag
1771
1787
) ;
1772
1788
} else {
1773
1789
this . _defaultLightShader = new p5 . Shader (
1774
1790
this ,
1775
1791
this . _webGL2CompatibilityPrefix ( 'vert' , 'highp' ) +
1776
- defaultShaders . lightVert ,
1792
+ defaultShaders . lightVert ,
1777
1793
this . _webGL2CompatibilityPrefix ( 'frag' , 'highp' ) +
1778
- defaultShaders . lightTextureFrag
1794
+ defaultShaders . lightTextureFrag
1779
1795
) ;
1780
1796
}
1781
1797
}
@@ -1788,9 +1804,9 @@ p5.RendererGL = class RendererGL extends p5.Renderer {
1788
1804
this . _defaultImmediateModeShader = new p5 . Shader (
1789
1805
this ,
1790
1806
this . _webGL2CompatibilityPrefix ( 'vert' , 'mediump' ) +
1791
- defaultShaders . immediateVert ,
1807
+ defaultShaders . immediateVert ,
1792
1808
this . _webGL2CompatibilityPrefix ( 'frag' , 'mediump' ) +
1793
- defaultShaders . vertexColorFrag
1809
+ defaultShaders . vertexColorFrag
1794
1810
) ;
1795
1811
}
1796
1812
@@ -1802,9 +1818,9 @@ p5.RendererGL = class RendererGL extends p5.Renderer {
1802
1818
this . _defaultNormalShader = new p5 . Shader (
1803
1819
this ,
1804
1820
this . _webGL2CompatibilityPrefix ( 'vert' , 'mediump' ) +
1805
- defaultShaders . normalVert ,
1821
+ defaultShaders . normalVert ,
1806
1822
this . _webGL2CompatibilityPrefix ( 'frag' , 'mediump' ) +
1807
- defaultShaders . normalFrag
1823
+ defaultShaders . normalFrag
1808
1824
) ;
1809
1825
}
1810
1826
@@ -1816,9 +1832,9 @@ p5.RendererGL = class RendererGL extends p5.Renderer {
1816
1832
this . _defaultColorShader = new p5 . Shader (
1817
1833
this ,
1818
1834
this . _webGL2CompatibilityPrefix ( 'vert' , 'mediump' ) +
1819
- defaultShaders . normalVert ,
1835
+ defaultShaders . normalVert ,
1820
1836
this . _webGL2CompatibilityPrefix ( 'frag' , 'mediump' ) +
1821
- defaultShaders . basicFrag
1837
+ defaultShaders . basicFrag
1822
1838
) ;
1823
1839
}
1824
1840
@@ -1830,9 +1846,9 @@ p5.RendererGL = class RendererGL extends p5.Renderer {
1830
1846
this . _defaultPointShader = new p5 . Shader (
1831
1847
this ,
1832
1848
this . _webGL2CompatibilityPrefix ( 'vert' , 'mediump' ) +
1833
- defaultShaders . pointVert ,
1849
+ defaultShaders . pointVert ,
1834
1850
this . _webGL2CompatibilityPrefix ( 'frag' , 'mediump' ) +
1835
- defaultShaders . pointFrag
1851
+ defaultShaders . pointFrag
1836
1852
) ;
1837
1853
}
1838
1854
return this . _defaultPointShader ;
@@ -1843,9 +1859,9 @@ p5.RendererGL = class RendererGL extends p5.Renderer {
1843
1859
this . _defaultLineShader = new p5 . Shader (
1844
1860
this ,
1845
1861
this . _webGL2CompatibilityPrefix ( 'vert' , 'mediump' ) +
1846
- defaultShaders . lineVert ,
1862
+ defaultShaders . lineVert ,
1847
1863
this . _webGL2CompatibilityPrefix ( 'frag' , 'mediump' ) +
1848
- defaultShaders . lineFrag
1864
+ defaultShaders . lineFrag
1849
1865
) ;
1850
1866
}
1851
1867
@@ -1919,9 +1935,9 @@ p5.RendererGL = class RendererGL extends p5.Renderer {
1919
1935
* Returns the blurry image
1920
1936
* maps a p5.Image used by imageLight() to a p5.Graphics
1921
1937
*/
1922
- getDiffusedTexture ( input ) {
1938
+ getDiffusedTexture ( input ) {
1923
1939
// if one already exists for a given input image
1924
- if ( this . diffusedTextures . get ( input ) != null ) {
1940
+ if ( this . diffusedTextures . get ( input ) != null ) {
1925
1941
return this . diffusedTextures . get ( input ) ;
1926
1942
}
1927
1943
// if not, only then create one
@@ -1955,18 +1971,18 @@ p5.RendererGL = class RendererGL extends p5.Renderer {
1955
1971
* Storing the texture for input image in map called `specularTextures`
1956
1972
* maps the input p5.Image to a p5.MipmapTexture
1957
1973
*/
1958
- getSpecularTexture ( input ) {
1974
+ getSpecularTexture ( input ) {
1959
1975
// check if already exits (there are tex of diff resolution so which one to check)
1960
1976
// currently doing the whole array
1961
- if ( this . specularTextures . get ( input ) != null ) {
1977
+ if ( this . specularTextures . get ( input ) != null ) {
1962
1978
return this . specularTextures . get ( input ) ;
1963
1979
}
1964
1980
// Hardcoded size
1965
1981
const size = 512 ;
1966
1982
let tex ;
1967
1983
const levels = [ ] ;
1968
1984
const graphic = this . _pInst . createGraphics ( size , size , constants . WEBGL ) ;
1969
- let count = Math . log ( size ) / Math . log ( 2 ) ;
1985
+ let count = Math . log ( size ) / Math . log ( 2 ) ;
1970
1986
graphic . pixelDensity ( 1 ) ;
1971
1987
// currently only 8 levels
1972
1988
// This loop calculates 8 graphics of varying size of canvas
@@ -1975,8 +1991,8 @@ p5.RendererGL = class RendererGL extends p5.Renderer {
1975
1991
// because rougher surfaces have less detailed/more blurry reflections.
1976
1992
for ( let w = size ; w >= 1 ; w /= 2 ) {
1977
1993
graphic . resizeCanvas ( w , w ) ;
1978
- let currCount = Math . log ( w ) / Math . log ( 2 ) ;
1979
- let roughness = 1 - currCount / count ;
1994
+ let currCount = Math . log ( w ) / Math . log ( 2 ) ;
1995
+ let roughness = 1 - currCount / count ;
1980
1996
let myShader = graphic . createShader (
1981
1997
defaultShaders . imageLightVert ,
1982
1998
defaultShaders . imageLightSpecularFrag
@@ -1991,7 +2007,7 @@ p5.RendererGL = class RendererGL extends p5.Renderer {
1991
2007
}
1992
2008
graphic . remove ( ) ;
1993
2009
tex = new MipmapTexture ( this , levels , { } ) ;
1994
- this . specularTextures . set ( input , tex ) ;
2010
+ this . specularTextures . set ( input , tex ) ;
1995
2011
return tex ;
1996
2012
}
1997
2013
@@ -2093,9 +2109,9 @@ p5.RendererGL = class RendererGL extends p5.Renderer {
2093
2109
}
2094
2110
2095
2111
// getting called from _setFillUniforms
2096
- _setImageLightUniforms ( shader ) {
2112
+ _setImageLightUniforms ( shader ) {
2097
2113
//set uniform values
2098
- shader . setUniform ( 'uUseImageLight' , this . activeImageLight != null ) ;
2114
+ shader . setUniform ( 'uUseImageLight' , this . activeImageLight != null ) ;
2099
2115
// true
2100
2116
if ( this . activeImageLight ) {
2101
2117
// this.activeImageLight has image as a key
@@ -2109,8 +2125,8 @@ p5.RendererGL = class RendererGL extends p5.Renderer {
2109
2125
// only calculated 8 different levels of roughness
2110
2126
// The factor of 20 is just to spread up this range so that,
2111
2127
// [1, max] of shininess is converted to [0,160] of roughness
2112
- let roughness = 20 / this . _useShininess ;
2113
- shader . setUniform ( 'levelOfDetail' , roughness * 8 ) ;
2128
+ let roughness = 20 / this . _useShininess ;
2129
+ shader . setUniform ( 'levelOfDetail' , roughness * 8 ) ;
2114
2130
shader . setUniform ( 'environmentMapSpecular' , specularLight ) ;
2115
2131
}
2116
2132
}
0 commit comments