Don't blend a polyline that has crossed lines with itself in webgl
文章推薦指數: 80 %
I'm drawing two polylines (which are lines in the sample) in webgl with enabled blending. gl.uniform4f(colorUniformLocation, 0, 0, 0, ...
Home
Public
Questions
Tags
Users
Companies
Collectives
ExploreCollectives
Teams
StackOverflowforTeams
–Startcollaboratingandsharingorganizationalknowledge.
CreateafreeTeam
WhyTeams?
Teams
CreatefreeTeam
Collectives™onStackOverflow
Findcentralized,trustedcontentandcollaboratearoundthetechnologiesyouusemost.
LearnmoreaboutCollectives
Teams
Q&Aforwork
Connectandshareknowledgewithinasinglelocationthatisstructuredandeasytosearch.
LearnmoreaboutTeams
Don'tblendapolylinethathascrossedlineswithitselfinwebgl
AskQuestion
Asked
2years,11monthsago
Modified
2years,11monthsago
Viewed
92times
0
I'mdrawingtwopolylines(whicharelinesinthesample)inwebglwithenabledblending.
gl.uniform4f(colorUniformLocation,0,0,0,0.3);
gl.enable(gl.BLEND);
gl.blendFunc(gl.ONE,gl.ONE_MINUS_SRC_ALPHA);
gl.bufferData(gl.ARRAY_BUFFER,newFloat32Array([0.2,-1,0.2,1,]),gl.STATIC_DRAW);
gl.drawArrays(gl.LINE_STRIP,0,2);
gl.bufferData(gl.ARRAY_BUFFER,newFloat32Array([0,-1,0,1,0,-1,0,1]),gl.STATIC_DRAW);
gl.drawArrays(gl.LINE_STRIP,0,4);
Hereisthecodepensample.
Theleftlinearecrossedwithitselfanditseemslikeitblendswithitself,soasresultitbecomesdarker.
Iwouldliketheblendtoworkbetweenthosepolylines,butdon'twantapolylinetoblendwithitself.Isthereawaytodoit?
webglalphablendingwebgl2
Share
Follow
askedSep30,2019at13:17
mt_sergmt_serg
7,34944goldbadges2727silverbadges4545bronzebadges
Addacomment
|
1Answer
1
Sortedby:
Resettodefault
Highestscore(default)
Trending(recentvotescountmore)
Datemodified(newestfirst)
Datecreated(oldestfirst)
1
Onewaywouldbetousethestenciltest.You'dsetwebglsothatthestencilstoresacertainvaluewhenapixelisdrawnandyou'dsetthestenciltestsoitfailsifitseesthatvalue.
Firstanexamplethatdraws2setsof2overlappingtriangleswithblendingon.Thepairswillgetdarkerwheretheyoverlap
functionmain(){
constm4=twgl.m4;
constgl=document
.querySelector('canvas')
.getContext('webgl');
constvs=`
attributevec4position;
uniformmat4matrix;
voidmain(){
gl_Position=matrix*position;
}
`;
constfs=`
precisionmediumpfloat;
uniformvec4color;
voidmain(){
gl_FragColor=color;
}
`;
//compileshader,linkprogram,lookuplocations
constprogramInfo=twgl.createProgramInfo(gl,[vs,fs]);
gl.useProgram(programInfo.program);
//createabufferandputdatainit
constbufferInfo=twgl.createBufferInfoFromArrays(gl,{
position:{
numComponents:2,
data:[
-0.5,-0.2,
0.5,-0.2,
0.5,0.2,
-0.2,-0.5,
-0.2,0.5,
0.2,0.5,
],
},
});
gl.enable(gl.BLEND);
gl.blendFunc(gl.ONE,gl.ONE_MINUS_SRC_ALPHA);
//callsgl.bindBuffer,gl.enableVertexAttribArray,gl.vertexAttribPointer
twgl.setBuffersAndAttributes(gl,programInfo,bufferInfo);
//callsgl.uniform??
twgl.setUniforms(programInfo,{
color:[0.5,0,0,0.5],
matrix:m4.identity(),
});
//callsgl.drawArraysorgl.drawElements
twgl.drawBufferInfo(gl,bufferInfo);
twgl.setUniforms(programInfo,{
color:[0,0,0.5,0.5],
matrix:m4.rotateZ(
m4.translation([-0.1,0.2,0]),
Math.PI*1.2),
});
twgl.drawBufferInfo(gl,bufferInfo);
}
main();
延伸文章資訊
- 1Animated lines with WebGL | Sample Code - ArcGIS Developer
... polyline graphics. This description assumes familiarity with WebGL and custom WebGL layer vie...
- 2WebGL polyline tessellation with tesspathy - Popular Blocks
WebGL polyline tessellation with tesspathy. +-. Leaflet · Open. yet another tessellation of polyl...
- 3WebGL polyline tessellation with tesspathy - gists · GitHub
WebGL polyline tessellation with tesspathy. GitHub Gist: instantly share code, notes, and snippets.
- 4Drawing Lines with WebGL - Scott Logic Blog
Connecting points on a chart with a line is one of the most basic uses of a charting library. Whe...
- 5Robust Polyline Rendering with WebGL - Cesium
Our new method for drawing polylines is to draw a screen-aligned quads for each segment of the li...