[SOLVED] Shader gl_FrontFacing parameter - PlayCanvas ...
文章推薦指數: 80 %
You are accessing gl_FrontFacing in the vertex shader when you should instead do it in the fragment shader. Acharton ... [SOLVED]Shadergl_FrontFacingparameter Help&Support Acharton June21,2016,10:43pm #1 Hello IwanttoflipthenormalsinacustomshaderbutI’vesometrooblemakingitwork.I’vetrysometutorialsbutfrommyunderstandingeachenginehandleglsldifferently.Sohereisthecode. Thefragmentshader varyingvec2vUv0; uniformsampler2DuDiffuseMap; varyingmat4matrix_model; varyingvec4verpos; varyingfloateffect; voidmain(void) { gl_FragColor=vec4(0.0); vec4color=texture2D(uDiffuseMap,vUv0); color=vec4(color.x+((verpos.y*0.0009)*(effect-0.9)*2.0),color.y+((verpos.y*0.0009)*(effect-0.9)*2.0),color.z+((verpos.y*0.0009)*(effect-0.90)*2.0),1); gl_FrontFacing=false; gl_FragColor=color; } TheVertexshader attributevec3aPosition; attributevec2aUv0; varyingvec2texCoord; uniformmat4matrix_model; uniformmat4matrix_viewProjection; uniformfloatscale; varyingfloateffect; varyingvec2vUv0; varyingvec4verpos; voidmain(void) { effect=scale; vUv0=aUv0; verpos=vec4(aPosition,scale); gl_Position=matrix_viewProjection*matrix_model*vec4(aPosition,scale); } [thelinkIfollowed](http://stackoverflow.com/questions/28160756/normals-are-inverted) I’veacompilationerroronthegl_FontFacing=false;.IsthereanyotherwayIcanaccessthisfunction. Itriedtofindsomedocumentationaboutitbutcouldn’tfindonewichactuallyworkonplaycanvas.Isitbeceauseitisonwebgl? that’salotofquestionsandi’mabitnoobinshaderprogramming.Ifanyonecanlinkmetoadocumentationthatwouldbegreat thanks! will June21,2016,11:18pm #2 gl_FrontFacingisnotafunction,it’sabooleanvalue.HereisadescriptiongivenintheGLSLspec: Thefragmentshaderhasaccesstotheread-onlybuilt-invariablegl_FrontFacingwhosevalueistrueif thefragmentbelongstoafront-facingprimitive.Oneuseofthisistoemulatetwo-sidedlightingby selectingoneoftwocolorscalculatedbythevertexshader. Sotheissuesseemtobe: Youarewritingtogl_FrontFacing,whenitisaread-onlyvalue. Youareaccessinggl_FrontFacinginthevertexshaderwhenyoushouldinsteaddoitinthefragmentshader. Acharton June21,2016,11:27pm #3 thanksforthetipandthespecs. [EDIT] Foundmymistake.Itriedtosetthevariableinsidetheglslshader.Thevariablemustbechangedinthejavascript. Theanswer material.cull=pc.CULLFACE_FRONT; 1Like
延伸文章資訊
- 1OpenGL Programming Guide: The Official Guide to Learning ...
OpenGL Shading Language has a builtin Boolean variable gl_FrontFacing allowing you to do so. The ...
- 2[SOLVED] Shader gl_FrontFacing parameter - PlayCanvas ...
You are accessing gl_FrontFacing in the vertex shader when you should instead do it in the fragme...
- 3Advanced GLSL - LearnOpenGL
The gl_FrontFacing variable tells us if the current fragment is part of a front-facing or a back-...
- 4gl_FrontFacing - The Book of Shaders
by Patricio Gonzalez Vivo. Gl_FrontFacing. Declaration / Example. Parameters. Description. See Al...
- 5gl_FrontFacing - OpenGL 4 Reference Pages - Khronos Group
Available only in the fragment language, gl_FrontFacing is an input variable whose value is true ...