Drawing lines with shader - OpenGL - Khronos Forums
文章推薦指數: 80 %
Hello, I'm trying to draw cube with lines which connects every single vertex on 3D space. and I want lines that are actually visible to user ... Drawinglineswithshader OpenGL pluxy January11,2022,3:02pm #1 Hello, I’mtryingtodrawcubewithlineswhichconnectseverysinglevertexon3Dspace. andIwantlinesthatareactuallyvisibletousertobedrawnonthescreen. [Expected] IcaneasilydrawcubeandlinesseparatelywithglBegin()/glEnd() image896×9237.31KB [Actual] image907×9092.19KB [VertexShader] #version450core layout(location=0)invec3aPos; outvec4aColor; uniformmat4projection; uniformmat4view; uniformmat4model; uniformvec4color; voidmain(){ aColor=color; gl_Position=projection*view*model*vec4(aPos,1.0); } [FragmentShader] #version450core invec4aColor; outvec4FragColor; voidmain(){ FragColor=aColor; } [Drawingcodes] glBindVertexArray(VAO); glDrawArrays(GL_TRIANGLES,0,36);//drawcube glBindVertexArray(0); Isthereanyguidelineswhichcanhelpmetoachievemygoalwithshader? Thanks, Alfonse_Reinheart January11,2022,3:09pm #2 Didyouturnoffdepthtestingwhenyou’rerenderinglines,sothatthetrianglesdon’tblockthemfromview? GClements January11,2022,3:29pm #3 Alfonse_Reinheart: Didyouturnoffdepthtestingwhenyou’rerenderinglines,sothatthetrianglesdon’tblockthemfromview? pluxy: andIwantlinesthatareactuallyvisibletousertobedrawnonthescreen. IOW,depth-testingneedstobeenabledtoremovethehiddenlines. YoumighttryglDepthFunc(GL_LEQUAL).ThedefaultisGL_LESS,whichwilldiscardfragmentswhosedepthvalueisequaltothatinthedepthbuffer. Butthatmaynotbeenough.Becauseofthedifferencesinrasterisation,thefragmentsgeneratedbythelineswon’thavethesamedepthasthosegeneratedbythetriangles.Thefragmentsgeneratedbytriangleswillhavethedepthcalculatedbysamplingtheplaneequationatthefragmentcentre.Thosegeneratedbylineswillbecalculatedbysamplingthelineequationattheclosestpointtothefragmentcentre. Todealwiththat,useglEnable(GL_POLYGON_OFFSET_LINE)andglPolygonOffsettomakethelineshaveslightlylowerdepthvalues.You’llneedtoexperimentregardingtheparameters,astherequiredoffsetwilldependuponthenearandfarplanedistancesusedtoconstructtheprojectionmatrixandalsouponthedistancefromtheviewpoint. 1Like pluxy January12,2022,12:37pm #4 Thankyousomuch!! Problemhasbeenresolved!! system closed July14,2022,12:38pm #5 Thistopicwasautomaticallyclosed183daysafterthelastreply.Newrepliesarenolongerallowed.
延伸文章資訊
- 1Is it possible to draw line thickness in a fragment shader?
No, it is not possible in the fragment shader using only GL_LINES . This is because GL restricts ...
- 2Drawing lines with shader - OpenGL - Khronos Forums
Hello, I'm trying to draw cube with lines which connects every single vertex on 3D space. and I w...
- 3Draw Line - Shadertoy
Build shaders, share them, and learn from the best community.
- 4Drawing Lines with WebGL - Scott Logic Blog
How would we do this in the vertex shader? We can take advantage of GL_TRIANGLE_STRIP . A triangl...
- 5Compute Shader for line drawing - Unity Forum
So I am trying to learn compute shaders and I started creating some simple ... To make a custom r...