GLSL - Passing coordinates to fragment shader? - Stack ...
文章推薦指數: 80 %
gl_Position is the clip-space position of a particular vertex. gl_FragCoord.xyz contains the window-space position of the fragment. These are ...
2022DeveloperSurveyisopen!Takesurvey.
Home
Public
Questions
Tags
Users
Companies
Collectives
ExploreCollectives
Teams
StackOverflowforTeams
–Startcollaboratingandsharingorganizationalknowledge.
CreateafreeTeam
WhyTeams?
Teams
CreatefreeTeam
Collectives™onStackOverflow
Findcentralized,trustedcontentandcollaboratearoundthetechnologiesyouusemost.
Learnmore
Teams
Q&Aforwork
Connectandshareknowledgewithinasinglelocationthatisstructuredandeasytosearch.
Learnmore
GLSL-Passingcoordinatestofragmentshader?
AskQuestion
Asked
8years,8monthsago
Modified
8years,8monthsago
Viewed
20ktimes
9
Ihavethefollowingshaders
VertexShader
#version330
layout(location=0)invec3inPosition;
layout(location=1)invec4inColour;
layout(location=2)invec2inTex;
layout(location=3)invec3inNorm;
uniformmat4transformationMatrix;
uniformmat4projectionMatrix;
outvec4ShadowCoord;
voidmain()
{
gl_Position=projectionMatrix*transformationMatrix*vec4(inPosition,1.0);
ShadowCoord=gl_Position;
}
FragmentShader
#version330
invec4ShadowCoord;
outvec4FragColor;
uniformsampler2DheightmapTexture;
voidmain()
{
FragColor=vec4(vec3(clamp(ShadowCoord.x/500,0.0,1.0),clamp(gl_FragCoord.y/500,0.0,1.0),0.0),1.0);
}
WhatIwouldexpectthistodoistodrawthescene,withgreeninthetopleft,yellowinthetopright,redinthebottomrightandblackinthebottomleft.IndeedthisiswhathappenswhenIreplaceShadowCoord.xwithgl_FragCoord.xinmyfragmentshader.Whythen,doIonlygetaverticalgradientofgreen?EvidentlysomethingscrewyishappeningtomyShadowCoord.Anyoneknowwhatitis?
openglglslshader
Share
Improvethisquestion
Follow
askedSep3,2013at10:35
rspencerrspencer
2,42122goldbadges1818silverbadges2828bronzebadges
2
1
"Anyoneknowwhatitis?"No.BecausethecontentsofShadowCoorddependentirelyonthecontentsoftwomatricesthatwehavenoideawhattheyare.Wedon'tevenknowifyou'reusingaperspectiveororthographicproject.
– NicolBolas
Sep3,2013at10:49
Ok,butthepointisthatifIreplaceShadowCoordwithgl_FragCoordinthefragshaderthenitworks.Isgl_FragCoordnotderivedfromgl_Position?IfsowhydoesShadowCoordnotundergothesameinterpolation?
延伸文章資訊
- 1Geometry Shader - LearnOpenGL
Between the vertex and the fragment shader there is an optional shader stage ... Each time we cal...
- 2Built-in Variable (GLSL) - OpenGL Wiki - Khronos Group
Fragment Shader · Compute Shader · Other shading languages. The OpenGL Shading Language defines a...
- 3Advanced GLSL - LearnOpenGL
Setting gl_Position in the vertex shader is a strict requirement if you want to render ... Anothe...
- 4Intro to GLSL - Cornell CS
Vertex shader controls vertex transformation ... "cs4620/gl/Grid.frag", // Path to fragment shade...
- 5認識著色器
getElementById('glCanvas')); installProgram(gl, shaderSourceById('vertex-shader'), shaderSourceBy...