1

OpenGL オブジェクトでシェーディングを使用したいのですが、opengl パッケージの GLSL 関数にアクセスできないようです。Eclipse で OpenGL ES に使用できる GLSL パッケージはありますか?

編集:ティムが指摘したように。シェーダーはテキスト ファイルとして作成され、glShaderSoure を使用して読み込まれます。レイ トレーシング アプリケーション用に 1 回作成した C++ シェーダー ファイルがあります。しかし、Javaで実装する方法については本当に混乱しています。Rendererクラスで gl オブジェクトを使用して 2D 正方形を描画したとしMySquareます。以下のシェーダー ファイルに相当する Java を実装するにはどうすればよいでしょうか。

Shader.vert

     varying vec3 N;
     varying vec3 v;

void main()
{

// Need to transform the normal into eye space.
N = normalize(gl_NormalMatrix * gl_Normal);


// Always have to transform vertex positions so they end
// up in the right place on the screen.
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}

  // Fragment shader for per-pixel Phong interpolation and shading.

Shader.Frag

// The "varying" keyword means that the parameter's value is interpolated
// between the nearby vertices.
varying vec3 N;
varying vec3 v;

//Used for Environmental mapping shader calculations
const vec3 xUnitVec=vec3(1.0, 0.0, 0.0), yUnitVec=vec3(1.0, 1.0, 0.0);
uniform vec3 BaseColor, MixRatio;
uniform sampler2D EnvMap;


 void main()
{
    // The scene's ambient light.
    vec4 ambient = gl_LightModel.ambient * gl_FrontMaterial.ambient;

// The normal vectors is generally not normalized after being
// interpolated across a triangle.  Here we normalize it.
vec3 Normal = normalize(N);

// Since the vertex is in eye space, the direction to the
// viewer is simply the normalized vector from v to the
// origin.
vec3 Viewer = -normalize(v);

// Get the lighting direction and normalize it.
vec3 Light  = normalize(gl_LightSource[0].position.xyz);

// Compute halfway vector
vec3 Half = normalize(Viewer+Light);

// Compute factor to prevent light leakage from below the
// surface
float B = 1.0;
if(dot(Normal, Light)<0.0) B = 0.0;

// Compute geometric terms of diffuse and specular
float diffuseShade = max(dot(Normal, Light), 0.0);
float specularShade = 
  B * pow(max(dot(Half, Normal), 0.0), gl_FrontMaterial.shininess);

// Compute product of geometric terms with material and
// lighting values
vec4 diffuse = diffuseShade * gl_FrontLightProduct[0].diffuse;
vec4 specular = specularShade * gl_FrontLightProduct[0].specular;
ambient += gl_FrontLightProduct[0].ambient;

// Assign final color
gl_FragColor= ambient + diffuse + specular + gl_FrontMaterial.emission;
}
4

3 に答える 3

3

Learnopengles.comでチュートリアルをチェックしてください。彼らはあなたが持っているすべての質問に答えます.

于 2012-06-22T19:39:10.877 に答える
0

シェーダー ファイルに「Java に相当するもの」はありません。シェーダーはGLSLで書かれています。opengl が Java、C++、Python などでラップされていても、シェーダーは同じです。OpenGL と OpenGLES の間の小さな API の違いは別として、C++ で使用したものとまったく同じシェーダーを Java でアップロードすることができます。

于 2012-06-22T18:52:04.223 に答える