Three.js: Fresnel Shader - Color changing or env map blending

百般思念 提交于 2019-12-23 05:31:01

问题


I'm not a shader specialist, but I'd like to pass the color value to the shader that could maybe blended with the env map color.

    var shader = THREE.FresnelShader;
// Thank you WestLangley for that trick
    var uniforms = THREE.UniformsUtils.merge( [

        THREE.UniformsLib[ "lights" ],
        shader.uniforms

    ] );

    uniforms[ "tCube" ].value = textureCube;

    var parameters = { fragmentShader: shader.fragmentShader, vertexShader: shader.vertexShader, uniforms: uniforms, lights : true };
    shaderMaterial = new THREE.ShaderMaterial( parameters );
    shaderMaterial.envMap = textureCube;

I'm clueless. Thanks for any suggestions.


回答1:


For the futures ones ;) You need to modify the FresnelShader firstly by passing the color to the shader. Afterwords in the fragmentShader add a line:

vec4 color = vec4( colorR, colorG, colorB, 1); // colorR,G,B those are floats passed to the shader

and by modifing this line:

gl_FragColor = mix( color, reflectedColor, clamp( vReflectionFactor, 0.0, 1.0 ) );

You can addjust the refracted color.



来源:https://stackoverflow.com/questions/18046248/three-js-fresnel-shader-color-changing-or-env-map-blending

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!