2016-11-13 10 views
2

필자의 분야에서 조명 모델을 올바르게 수정하는 데 어려움이 있습니다. 특히, 구체에 대한 반사 하이라이트를 올바르게 얻을 수 없습니다. 이 확산 구체를 위해 (내가 알고있는 것처럼
Correct specular highlightsSphere raytracing - 반사 하이라이트

, 조명 모델 :
Wrong specular highlights

지금의 반사 하이라이트가 조금 더 다음과 같이한다 : 여기 구체 광선 추적 할 때 내가보고있는 무슨이다
가가 앰블 C R이 영역의 색상입니다 Lighting model

입니다 C :)은 다음과 같습니다는 빛의 색상 리터 C 구름의 NT 성분, n이 구체 교점에서 정상이고, le 반 사면의 색 P C 광의 방향이다 눈/봐요. r은 구체 표면에서의 반사 벡터이고, 지수의 p은 퐁 상수/지수 (빛이 얼마나 단단한 지/느슨한 지)를 나타냅니다. 이 경우, 퐁 기간 동안 눈 성분이, 그리고 방향 (1, 0, 0)이다에서 카메라의 모습이라고

public Color calculateIlluminationModel(Vector normal, Scene scene) 
{ 
    //c = cr * ca + cr * cl * max(0, n \dot l)) + cl * cp * max(0, e \dot r)^p 
    Vector lightSourceColor = getColorVector(scene.getLight().getLightColor()); //cl 
    Vector diffuseReflectanceColor = getColorVector(getMaterialColor()); //cr 
    Vector ambientColor = getColorVector(scene.getLight().getAmbientLightColor()); //ca 
    Vector specularHighlightColor = getColorVector(getSpecularHighlight()); //cp 
    Vector directionToLight = scene.getLight().getDirectionToLight(); //l 
    Vector reflectionVector = normal.multiply(2).multiply(normal.crossProduct(directionToLight)).subtract(directionToLight); //r = 2n(n \dot l) - l 

    Vector ambientTerm = diffuseReflectanceColor.multiply(ambientColor); 
    double angleBetweenLightAndNormal = directionToLight.dotProduct(normal); 
    Vector diffuseTerm = diffuseReflectanceColor.multiply(lightSourceColor).multiply(Math.max(0, angleBetweenLightAndNormal)); 
    Vector phongTerm = lightSourceColor.multiply(specularHighlightColor).multiply(Math.pow(Math.max(0, scene.getCameraSettings().getLookFrom().dotProduct(reflectionVector)), (double) getPhongConstant())); 
    return getVectorColor(ambientTerm.add(diffuseTerm).add(phongTerm)); 
} 

주 : 여기

내 과정 빛은 (1, 0, 0)입니다.

내 반사 조명이 빛의 방향을 향하는 대신 구체 상단에있는 이유는 무엇입니까?

나를 도울 필요가있는 중요한 세부 사항을 알려주는지 알려주십시오.

+0

왜 카메라 모양-에서 항상 (0, 0, 1)? 현재 그리는 픽셀에 따라 달라져야하지 않습니까? –

+0

나의 이해는 광선의 눈/기원이 바뀌지 않고 광선의 방향 만 바뀌 었다는 것이다. –

답변

1

문제는이 라인이다 원하는 방향과 직각을 이루며 위의 오류를 표시합니다. 그래서 그 대신

, 당신은해야

Vector reflectionVector = normal.multiply(2).multiply(normal.dotProduct(directionToLight)).subtract(directionToLight); //r = 2n(n \dot l) - l 
1

반사 벡터는 표면 법선 및 수신 광선 방향을 기반으로 계산되어야하며 지금처럼 빛 방향이 아닙니다.

Vector reflectionVector = normal.multiply(2).multiply(normal.crossProduct(directionToLight)).subtract(directionToLight); //r = 2n(n \dot l) - l 

대신 정상과 빛의 방향 사이의 내적을 복용, 대신 normal.crossProduct(directionToLight)을 복용의 십자가 생산, 당신에게 벡터를 줄 것이다 :

+0

그게 상황을 훨씬 더 악화 시켰습니다. 그거 확실하니? 내가 본 것에서, 반사 벡터는'r = 2n (n \ dot l) - l'이고, 여기서 'l'은 빛에 대한 방향입니다. –

+0

거울에 반사되는 모습이 주변 조명의 위치에 따라 좌우 되는가? –

+1

몇 가지 문제가 수정되었으며 몇 가지 문제가 수정 된 것으로 보입니다. 그러나 궁극적 인 근본적인 문제는 내 제품을 가져 가야 할 때 교차 제품을 사용하고 있다는 것이 었습니다. –