opengl - fragment shader if statment and loading array of mat4 into uniform -
i have problem if here, reasons uknown me, dosnt work. when delete if statment or malualy write shadowmap[0] 1 or 2 works fine, if set of white triangles , squares.
here part of frag shader
float shadow(float bias) { float visibility = 0; int index=1; if(gl_fragcoord.z<1.0){ index=0; } vec4 shadowcoord=depthpv*vpos; if ( texture(shadowmap[index], shadowcoord.xy).z < shadowcoord.z+bias){ visibility = -1; } return visibility; }
other problem have loading array of mat4 uniform here code tried, dosnt work, use lwjgl 3 libery in java
shadowpvs=gl20.glgetuniformlocation(pid, "shadowpvs"); bytebuffer shadowpvbuff=bufferutils.createbytebuffer(shadepv.length*16*4); for(int i=0;i<shadepv.length;i++){ for(int v=0;v<16;v++){ shadowpvbuff.putfloat(shadepv[i].val[v]); } } shadowpvbuff.flip(); gl20.gluniformmatrix4f(shadowpvs, shadepv.length, false, shadowpvbuff);
and in shader
uniform mat4 shadowpvs[3];
what trying not possible current gl.
as @gemse pointed out in comments, relevant part of glsl 3.30 spec is:
samplers aggregated arrays within shader (using square brackets [ ]) can indexed integral constant expressions (see section 4.3.3 “constant expressions”).
in gl 4, constraint has been somehwat relaxed, not far enough. in current glsl 4.50 spec, statement is:
when aggregated arrays within shader, samplers can indexed dynamically uniform integral expression, otherwise results undefined.
with dynamically uniform being defined
a fragment-shader expression dynamically uniform if fragments evaluating same resulting value. when loops involved, refers expression's value same loop iteration. when functions involved, refers calls same call point. defined other shader stages, based on per-instance data process. note constant expressions trivially dynamically uniform. follows typical loop counters based on these dynamically uniform.
your index depends on data can vary per fragment, getting undefined results.
Comments
Post a Comment