refraction has black edges when rotated

This topic contains 1 reply, has 1 voice, and was last updated by  dazed3confused 5 years, 7 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #30852


    I was just wanting to ask a question about refraction. I am working with ios, and I have created a refraction effect from taking a look at the training materials provided with the SDK (Which are all very good and helpful by the way, I wouldn’t have been able to achieve the effect without them).

    Anyway the problem I have is when I run my project I seem to get black surfaces as the object is rotated. I am not really clear why this is happening. I have taken a couple of screen shots to show what is happening to help explain, but Im not sure I can attach them, so I will try and explain- rendering a cube the front surface looks fine, as it rotates around the y axis, as the new surface comes into sight it is black at first, and then flicks to the correct refraction/transparent effect, and just before it goes out of view it goes to a black color again.

    I thought it might be useful to show my fragment shader code-

    static const char* ReflectionFragmentShader = STRINGIFY(

    varying lowp    float  SpecularIntensity;
    varying mediump vec2   RefractCoord;
    varying mediump vec3 ReflectDir;
    varying lowp    float  ReflectRatio;

    uniform sampler2D Sampler;
    uniform samplerCube SamplerC;

    void main(void)
        mediump vec3 refractColor = texture2D(Sampler, RefractCoord).rgb;   
        mediump vec3 reflectColor = textureCube(SamplerC, ReflectDir).rgb;
        //gl_FragColor = vec4(refractColor + SpecularIntensity, 1.0);
        gl_FragColor = mix(vec4(refractColor, 1.0), vec4(reflectColor, 1.0), ReflectRatio);

    Note: the effect happens whether I use the commented out gl_FragColor line or the one that includes a reflection color also.

    So I wonder if someone can suggest why I am seeing this effect, and if there is anything I could do to improve it.

    If you need more details, or want me to upload some screenshots to a server just let me know and I’ll see what I can do.

    Perhaps also worth mentioning is this is running in the emulator, but I see the same effect on the phone, but the black is more of a blue ish color

    Thanks in advance


    Hmmm on further investigation, when I changed the refract function inputs in my vertex shader from 1.015 to 1.0 the edges are no longer black. The part I changed was

    mediump vec3 refractDir = refract(eyeDir, Normal, 1.0);

    So I am thinking that it was perhaps because of the angle the object was at that maybe it can’t refract that surface very well. Though I am not certain


Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic.