Results 1 to 5 of 5

Thread: Introduce How to use .vert and .frag on OGLES2

  1. #1
    Lesser Wizard
    Join Date
    Feb 2013
    Posts
    142
    Last edited by feelthat; 12-04-2013 at 06:04 AM.

  2. #2
    Lesser Wizard
    Join Date
    Feb 2013
    Posts
    142

    Default GLSL (OpenGL Shading Language) outline

    https://plus.google.com/photos/11469...54049719647435

    ////////////attribute/////////
    1 Position dimensionality 2,3,4
    2 Normal dimensionality 3
    3 Color dimensionality 4
    4 Point Size dimensionality 1
    5 Texture Coordinate dimensionality 2,3,4
    6 Generic Attribute(ES 2.0) dimensionality 1,2,3,4

    dimensionality
    typedef Vector1<float> vec1;
    vec1(1.0);

    typedef Vector2<float> vec2;
    vec2(1.0,1.0);

    typedef Vector3<float> vec3;
    vec3(1.0,1.0,1.0);

    typedef Vector4<float> vec4;
    vec4(1.0,1.0,1.0,1.0);

    ////////////varying/////////////////
    1. a connection point.

    2.Vertex Program
    varying vec4 pcolor
    void main()
    {
    gl_Position = position;
    pcolor = color;
    }

    3.Fragment Program
    varying vec4 pcolor;
    void main()
    {
    gl_FragColor = pcolor;
    }

    pcolor is varying

    ////////////////uniform/////////////////////
    uniform variables remain the same values for all vertices/fragments
    you cannot change their values in .vert
    set value in .cpp or .mm

    1 modeling matrix
    2 viewing matrix
    3 projection matrix
    4 modelview matrix
    5 modelviewprojection matrix


    ////////////
    ////////////
    ///////////example.vert
    attribute vec4 Position;
    attribute vec4 SourceColor;
    varying vec4 DestinationColor;
    uniform mat4 Projection;
    uniform mat4 Modelview;

    void main(void)
    {
    DestinationColor = SourceColor;
    gl_Position = Projection * Modelview * Position;
    }

    /////////////example.frag
    varying lowp vec4 DestinationColor;

    void main(void)
    {
    gl_FragColor = DestinationColor;
    }


    DestinationColor is a connect point
    Last edited by feelthat; 11-29-2013 at 09:21 PM.

  3. #3
    Lesser Wizard
    Join Date
    Feb 2013
    Posts
    142

    Default irrlicht GLGS ogles2.vert

    attribute vec3 inVertexPosition;
    attribute vec3 inVertexNormal;
    attribute vec4 inVertexColor;
    attribute vec2 inTexCoord0;

    attribute name define in sBuiltInVertexAttributeNames of EVertexAttributes.h
    const char* const sBuiltInVertexAttributeNames[] =
    {
    "inVertexPosition",
    "inVertexNormal",
    "inVertexColor",
    "inTexCoord0",
    "inTexCoord1",
    "inVertexTangent",
    "inVertexBinormal",
    0
    };

    //! Enumeration of EVertexAttributes.h for all vertex attibutes there are
    enum E_VERTEX_ATTRIBUTES
    {
    EVA_POSITION = 0,
    EVA_NORMAL,
    EVA_COLOR,
    EVA_TCOORD0,
    EVA_TCOORD1,
    EVA_TANGENT,
    EVA_BINORMAL,
    EVA_COUNT
    };

    void COGLES2MaterialRenderer::init(s32& outMaterialTypeNr,
    const c8* vertexShaderProgram,
    const c8* pixelShaderProgram,
    bool addMaterial)
    //bind those attribute before linkProgram()
    for ( size_t i = 0; i < EVA_COUNT; ++i )
    glBindAttribLocation( Program, i, sBuiltInVertexAttributeNames[i]);


    //glVertexAttribPointer use EVA_POSITION~EVA_BINORMAL
    //example
    void COGLES2Driver::drawVertexPrimitiveList2d3d(const void* vertices,
    u32 vertexCount,
    const void* indexList,
    u32 primitiveCount,
    E_VERTEX_TYPE vType,
    scene::E_PRIMITIVE_TYPE pType,
    E_INDEX_TYPE iType,
    bool threed)
    {
    glVertexAttribPointer(EVA_POSITION, (threed ? 3 : 2), GL_FLOAT, false, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].Pos);
    }

    ///////////////////////////////////////////////////////////////////////

    uniform mat4 mWorldViewProj;
    uniform mat4 mInvWorld;
    uniform mat4 mTransWorld;
    uniform vec3 mLightPos;
    uniform vec4 mLightColor;

    OnSetConstants(video::IMaterialRendererServices* services, s32 userData)
    {
    //get uniform ID
    WorldViewProjID = services->getVertexShaderConstantID("mWorldViewProj");
    TransWorldID = services->getVertexShaderConstantID("mTransWorld");
    InvWorldID = services->getVertexShaderConstantID("mInvWorld");
    PositionID = services->getVertexShaderConstantID("mLightPos");
    ColorID = services->getVertexShaderConstantID("mLightColor");

    //set uniform matrix
    services->setVertexShaderConstant(WorldViewProjID, worldViewProj.pointer(), 16);
    services->setVertexShaderConstant(TransWorldID, world.pointer(), 16);
    services->setVertexShaderConstant(InvWorldID, invWorld.pointer(), 16);
    services->setVertexShaderConstant(PositionID, reinterpret_cast<f32*>(&pos), 3);
    services->setVertexShaderConstant(ColorID, reinterpret_cast<f32*>(&col), 4);
    }
    Last edited by feelthat; 12-02-2013 at 08:28 AM.

  4. #4
    Lesser Wizard
    Join Date
    Feb 2013
    Posts
    142

    Default Introduce OGLES1 and OGLES2 of Projection Matrix setting

    ///////////For OGLES 1.1, this changes to the following:
    glMatrixMode(GL_PROJECTION);
    glFrustumf(-1.6f, 1.6, -2.4, 2.4, 5, 10);
    glMatrixMode(GL_MODELVIEW);
    glTranslatef(0, 0, -7);

    //////////For OGLES 2.0, this changes to the following:
    m_simpleProgram = BuildProgram(SimpleVertexShader, SimpleFragmentShader);
    glUseProgram(m_simpleProgram);

    GLint projectionUniform = glGetUniformLocation(m_simpleProgram, "Projection");
    mat4 projectionMatrix = mat4::Frustum(-1.6f, 1.6, -2.4, 2.4, 5, 10);
    glUniformMatrix4fv(projectionUniform, 1, 0, projectionMatrix.Pointer());

    /////////////////////mat4::Frustum()/////////////////
    static Matrix4<T> Frustum(T left, T right, T bottom, T top, T near, T far)
    {
    T a = 2 * near / (right - left);
    T b = 2 * near / (top - bottom);
    T c = (right + left) / (right - left);
    T d = (top + bottom) / (top - bottom);
    T e = - (far + near) / (far - near);
    T f = -2 * far * near / (far - near);
    Matrix4 m;
    m.x.x = a; m.x.y = 0; m.x.z = 0; m.x.w = 0;
    m.y.x = 0; m.y.y = b; m.y.z = 0; m.y.w = 0;
    m.z.x = c; m.z.y = d; m.z.z = e; m.z.w = -1;
    m.w.x = 0; m.w.y = 0; m.w.z = f; m.w.w = 1;
    return m;
    }

    ////////////////////simple.vert////////////////
    attribute vec4 Position;
    attribute vec4 SourceColor;
    varying vec4 DestinationColor;
    uniform mat4 Projection;
    uniform mat4 Modelview;

    void main(void)
    {
    DestinationColor = SourceColor;
    gl_Position = Projection * Modelview * Position;
    }

  5. #5
    Lesser Wizard
    Join Date
    Feb 2013
    Posts
    142

    Default the order which matrix multiplies which

    from http://www.opengl.org/discussion_boa...ltiplies-which


    First of all, there is no real difference between a "World Matrix" and a "View Matrix", they are both transformation matrices and the distinction is somewhat arbitrary. Some systems even combine the two (OpenGL simply has a "ModelView" matrix).

    Traditionally the "world matrix" is used to move individual models from "model space" to "world space". Then the "view matrix" is used to move all the models from world space into their relative positions in front of the camera (which, in effect, "moves the camera"). And finally the "Projection Matrix" converts the 3D positions into their 2D positions on the screen (generally with a perspective projection). Because they are matrices, they can be multiplied together into a single matrix that can transform points in a single step.

    ///////////multiplies order//////////////
    mat4 modelview = cameraviewmatrix * modelmatrix;
    mat4 modelviewproj = projectionmatrix * modelview;
    gl_Position = modelview * gl_Vertex;

    So in fixed function terms, the ModelView matrix is calculated as:

    MV = V * M

    and ModelViewProjection is:

    MVP = P * V * M

    Therefore every vertex sent to the Fixed function or a shader is transformed by:

    gl_Position = V * M * Vertex;

Similar Threads

  1. RT3DApp and RTPhysics done in Ogles2 and OpenGL
    By feelthat in forum Proton SDK
    Replies: 18
    Last Post: 12-26-2013, 08:23 PM
  2. Introduce! ;)
    By Shelf in forum Meet & Greet
    Replies: 0
    Last Post: 11-09-2013, 04:31 AM
  3. integrated OGLES2 into Proton 3D
    By feelthat in forum Proton SDK
    Replies: 5
    Last Post: 10-22-2013, 12:03 PM
  4. introduce my self.
    By rotc3495 in forum Meet & Greet
    Replies: 1
    Last Post: 07-28-2013, 02:39 PM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •