[SOLVED] Shader gl_FrontFacing parameter - PlayCanvas ...

文章推薦指數: 80 %
投票人數:10人

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



請為這篇文章評分?