죄송합니다. 저는 OpenGL ES 및 처리 아래 처리 및 셰이더 출력 전용 배경에 대한 새로운 기능입니다.
PShader Gouraud, Phong;
rocket = loadShape("rocket.obj");
rocket.setFill(color(800, 0, 0));
Gouraud= loadShader("gouraudfragment.glsl","gouraudvertex.glsl");
Phong= loadShader("phongfragment.glsl","phongvertex.glsl");
background(0);
pushMatrix();
shader(Gouraud);
translate(130,height/2.0);
rotateY(rc);
rotateX(0.4);
noStroke();
fill(#800080);
box(100);
rc+=(0.02+speedCube);
rc*=dirCube;
popMatrix();
pushMatrix();
shader(Gouraud);
translate(width/2, height/2 + 100, -200);
rotateZ(PI);
rotateY(rr);
shape(rocket,100,100);
rr +=( 0.02+speedRocket);
rr*=dirRocket;
popMatrix();
정점 셰이더
varying vec3 N;
varying vec3 v;
varying vec4 diffuse;
varying vec4 spec;
attribute vec4 position;
attribute vec3 normal;
uniform mat4 modelview;
uniform mat4 projectionMatrix;
uniform mat3 normalMatrix;
uniform vec4 lightPosition;
uniform vec3 lightAmbient;
uniform vec3 lightDiffuse;
uniform vec3 lightSpecular;
uniform float SpecularPower;
void main()
{
vec4 diffuse;
vec4 spec;
vec4 ambient;
v = vec3(modelview * position);
N = normalize(normalMatrix * normal);
gl_Position = projectionMatrix * position;
vec3 L = normalize(lightPosition.xyz - v);
vec3 E = normalize(-v);
vec3 R = normalize(reflect(-L,N));
ambient = vec4(lightAmbient,100.0);
diffuse = vec4(clamp( lightDiffuse * max(dot(N,L), 0.0) , 0.0, 1.0 ) ,100.0);
spec = vec4(clamp (lightSpecular * pow(max(dot(R,E),0.0),0.3*SpecularPower) , 0.0, 1.0 ),100.0);
color = ambient + diffuse + spec;
}
조각 셰이더
void main()
{
gl_FragColor = color;
}
진행 과정은 obj를로드하고 큐브를 그리고 gouraud 셰이더를 적용하지만 그 후에는 backgroud 만 표시되고 obj가로드되고 큐브가 사라집니다. 아무것도 표시되지 않습니다!
셰이더는 컴파일 및 링크조차하지 않습니다. 버텍스 셰이더에는 1 개의 varying
출력 ( color
)이 있으므로 프레임 셰이더에는 입력이 필요합니다 varying vec4 color;
.
varying vec4 color;
클립 공간 위치를 설정할 때 꼭짓점 좌표는 모델보기 및 투영 행렬에 의해 변환되어야합니다.
gl_Position = projectionMatrix * modelview * position;
의 종류 사양 v
및 N
누락의 종류 ambient
, diffuse
그리고 spec
있습니다 vec4
보다는 vec3
.
정점 셰이더 :
attribute vec4 position;
attribute vec3 normal;
varying vec4 color;
uniform mat4 modelview;
uniform mat4 projectionMatrix;
uniform mat3 normalMatrix;
uniform vec4 lightPosition;
uniform vec3 lightAmbient;
uniform vec3 lightDiffuse;
uniform vec3 lightSpecular;
uniform float SpecularPower;
void main()
{
vec3 v = vec3(modelview * position);
vec3 N = normalize(normalMatrix * normal);
gl_Position = projectionMatrix * modelview * position;
vec3 L = normalize(lightPosition.xyz - v);
vec3 E = normalize(-v);
vec3 R = normalize(reflect(-L,N));
vec4 ambient = vec4(lightAmbient,100.0);
vec4 diffuse = vec4(clamp( lightDiffuse * max(dot(N,L), 0.0) , 0.0, 1.0 ) ,100.0);
vec4 spec = vec4(clamp (lightSpecular * pow(max(dot(R,E),0.0),0.3*SpecularPower) , 0.0, 1.0 ),100.0);
color = ambient + diffuse + spec;
}
조각 셰이더 :
varying vec4 color;
void main()
{
gl_FragColor = color;
}
물론 최소한 주변 광원을 설정해야합니다 ambientLight()
. 당신은을 사용할 수 있습니다 directionalLight()
, pointLight()
또는 spotLight()
도.
그러나 셰이더는 1 개의 광원 만 처리 할 수 있습니다. 1 개의 광원이 더 많이 얻을 것입니다.
상단 endDraw ()의 OpenGL 오류 1282 : 잘못된 작업
당신이 1 개 이상의 광원을 사용하고자하는 경우에 당신은을 위해 버텍스 쉐이더하는 int 균일 한 배열을 사용하는 것 lightPosition
, lightAmbient
, lightDiffuse
,와 lightSpecular
. 참조 처리에 쉐이더의 유형 ( https://processing.org/tutorials/pshader/ )
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다