ThreeJS:为自定义着色器添加阴影r75

时间:2016-04-12 01:43:13

标签: javascript three.js webgl

过去可以将阴影计算合并到自定义着色器中,如here所述并总结here

使用r75,照明和阴影系统似乎已合并,改变了这一点。我试图通过源代码来理解,但抽象/模块有点难以理解。

我已经将我的着色器提炼到目前为止的效果:

顶点:

#chunk(shadowmap_pars_vertex);

void main() {
    vec4 worldPosition = modelMatrix * vec4(position, 1.0);
    vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);
    gl_Position = projectionMatrix * mvPosition;

    #chunk(shadowmap_vertex);
}

片段

#chunk(common);
#chunk(lights_pars);
#chunk(shadowmap_pars_fragment);

void main() {

//#if ( NUM_DIR_LIGHTS > 0 )

    IncidentLight directLight;
    DirectionalLight directionalLight;

    float shadowValue = 1.0;

    for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {

        directionalLight = directionalLights[ i ];

        shadowValue = getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] );
    }

//#endif

    gl_FragColor = vec4(vec3(shadowValue), 1.0);
}

我从lights_template chunk拉出定向光环。不幸的是,shadowValue似乎总是返回1.0,但它确实有效,并且着色器会正确呈现。

我的JS有适当的castShadowreceiveShadow设置。使用Phong的其他网格正确渲染阴影。

非常感谢。

修改material.lights = true;添加到ShaderMaterial会显示某些内容,但片段着色器中shadowValue的值明显不正确,因为球体背面远离光。附上截图。

enter image description here enter image description here

0 个答案:

没有答案
相关问题