Shaders - LearnOpenGL
文章推薦指數: 80 %
GLSL. Shaders are written in the C-like language GLSL. GLSL is tailored for use with graphics and contains useful features specifically targeted at vector and ...
Ifyou'rerunningAdBlock,pleaseconsiderwhitelistingthissiteifyou'dliketosupportLearnOpenGL;andnoworries,Iwon'tbemadifyoudon't:)
IntroductionGettingstartedOpenGLCreatingawindowHelloWindowHelloTriangleShadersTexturesTransformationsCoordinateSystemsCameraReviewLightingColorsBasicLightingMaterialsLightingmapsLightcastersMultiplelightsReviewModelLoadingAssimpMeshModelAdvancedOpenGLDepthtestingStenciltestingBlendingFacecullingFramebuffersCubemapsAdvancedDataAdvancedGLSLGeometryShaderInstancingAntiAliasingAdvancedLightingAdvancedLightingGammaCorrectionShadowsShadowMappingPointShadowsNormalMappingParallaxMappingHDRBloomDeferredShadingSSAOPBRTheoryLightingIBLDiffuseirradianceSpecularIBLInPracticeDebuggingTextRendering2DGameBreakoutSettingupRenderingSpritesLevelsCollisionsBallCollisiondetectionCollisionresolutionParticlesPostprocessingPowerupsAudioRendertextFinalthoughtsGuestArticlesHowtopublish2020OITIntroductionWeightedBlendedSkeletalAnimation2021CSMSceneSceneGraphFrustumCullingTessellationHeightmapTessellationDSACoderepositoryTranslationsAbout
BTC
1CLGKgmBSuYJ1nnvDGAepVTKNNDpUjfpRa
ETH/ERC20
0x1de59bd9e52521a46309474f8372531533bd7c43
Shaders
Getting-started/Shaders
AsmentionedintheHelloTrianglechapter,shadersarelittleprogramsthatrestontheGPU.Theseprogramsarerunforeachspecificsectionofthegraphicspipeline.Inabasicsense,shadersarenothingmorethanprogramstransforminginputstooutputs.Shadersarealsoveryisolatedprogramsinthatthey'renotallowedtocommunicatewitheachother;theonlycommunicationtheyhaveisviatheirinputsandoutputs.
Inthepreviouschapterwebrieflytouchedthesurfaceofshadersandhowtoproperlyusethem.Wewillnowexplainshaders,andspecificallytheOpenGLShadingLanguage,inamoregeneralfashion.
GLSL
ShadersarewrittenintheC-likelanguageGLSL.GLSListailoredforusewithgraphicsandcontainsusefulfeaturesspecificallytargetedatvectorandmatrixmanipulation.
Shadersalwaysbeginwithaversiondeclaration,followedbyalistofinputandoutputvariables,uniformsanditsmainfunction.Eachshader'sentrypointisatitsmainfunctionwhereweprocessanyinputvariablesandoutputtheresultsinitsoutputvariables.Don'tworryifyoudon'tknowwhatuniformsare,we'llgettothoseshortly.
Ashadertypicallyhasthefollowingstructure:
#versionversion_number
intypein_variable_name;
intypein_variable_name;
outtypeout_variable_name;
uniformtypeuniform_name;
voidmain()
{
//processinput(s)anddosomeweirdgraphicsstuff
...
//outputprocessedstufftooutputvariable
out_variable_name=weird_stuff_we_processed;
}
Whenwe'retalkingspecificallyaboutthevertexshadereachinputvariableisalsoknownasavertexattribute.Thereisamaximumnumberofvertexattributeswe'reallowedtodeclarelimitedbythehardware.OpenGLguaranteestherearealwaysatleast164-componentvertexattributesavailable,butsomehardwaremayallowformorewhichyoucanretrievebyqueryingGL_MAX_VERTEX_ATTRIBS:
intnrAttributes;
glGetIntegerv(GL_MAX_VERTEX_ATTRIBS,&nrAttributes);
std::cout<//includegladtogetalltherequiredOpenGLheaders
#include
延伸文章資訊
- 1GLSL - 维基百科,自由的百科全书
GLSL - OpenGL Shading Language 也稱作GLslang,是一個以C語言為基礎的高階著色語言。它是由OpenGL ARB 所建立,提供開發者對繪圖管線更多的直接控制,而...
- 2GLSL着色器- 游戏开发环境 - MDN Web Docs
使用GLSL的着色器(shader), GLSL是一门特殊的有着类似于C语言的语法, 在图形管道(graphic pipeline)中直接可执行的OpenGL着色语言.
- 3高级GLSL
GLSL有几个以gl_为前缀的变量,使我们有一个额外的手段来获取和写入数据。其中两个我们已经打过交道了: gl_Position 和 gl_FragCoord ,前一个是顶点着色器的输出向量,后...
- 4Shaders - LearnOpenGL
GLSL. Shaders are written in the C-like language GLSL. GLSL is tailored for use with graphics and...
- 5Core Language (GLSL) - OpenGL Wiki - Khronos Group
Core Language (GLSL) ... Shader stages: ... The OpenGL Shading Language is a C-style language, so...