Changeset 12727

Timestamp:
Oct 3, 2012, 2:40:01 PM (12 years ago)
Author:
myconid
Message:

Changing sky manager to render sky using cubemaps, to avoid duplication of sky textures in memory.

Location:
ps/trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • ps/trunk/binaries/data/mods/public/shaders/arb/sky.fp

    r12551 r12727  
    11!!ARBfp1.0
    2 
    3 TEX result.color, fragment.texcoord[0], texture[0], 2D;
    4 
     2# cgc version 3.1.0013, build date Apr 24 2012
     3# command line args: -oglsl -profile arbfp1
     4# source file: sky.fs
     5#vendor NVIDIA Corporation
     6#version 3.1.0.13
     7#profile arbfp1
     8#program main
     9#semantic baseTex
     10#var float4 gl_FragColor : $vout.COLOR : COL : -1 : 1
     11#var samplerCUBE baseTex :  : texunit 0 : -1 : 1
     12#var float3 v_tex : $vin.TEX0 : TEX0 : -1 : 1
     13#const c[0] = 0.25 0 1 4
     14PARAM c[1] = { { 0.25, 0, 1, 4 } };
     15TEMP R0;
     16TEMP R1;
     17TEMP R2;
     18SLT R2.x, c[0].y, fragment.texcoord[0].y;
     19ABS R2.x, R2;
     20TEX R0, fragment.texcoord[0], texture[0], CUBE;
     21ADD R1.x, -fragment.texcoord[0].y, c[0];
     22MUL R1, R0, R1.x;
     23MUL R1, R1, c[0].w;
     24CMP R2.x, -R2, c[0].y, c[0].z;
     25CMP result.color, -R2.x, R0, R1;
    526END
     27
  • ps/trunk/binaries/data/mods/public/shaders/arb/sky.xml

    r12551 r12727  
    77
    88    <fragment file="arb/sky.fp">
    9         <uniform name="baseTex" loc="0" type="sampler2D"/>
     9        <uniform name="baseTex" loc="0" type="sampler"/>
    1010    </fragment>
    1111
  • ps/trunk/binaries/data/mods/public/shaders/glsl/sky.fs

    r12551 r12727  
    11#version 110
    22
    3 uniform sampler2D baseTex;
    4 varying vec2 v_tex;
     3uniform sampler baseTex;
     4varying vec v_tex;
    55
    66void main()
    77{
    8   gl_FragColor = texture2D(baseTex, v_tex);
     8 
     9  vec4 tex = textureCube(baseTex, v_tex);
     10
     11  float m = (1.0 - v_tex.y) - 0.75;
     12  m *= 4.0;
     13
     14  gl_FragColor = (v_tex.y > 0.0) ? (tex * m) : tex;
     15 
    916}
  • ps/trunk/binaries/data/mods/public/shaders/glsl/sky.vs

    r12557 r12727  
    11#version 110
    22
    3 varying vec2 v_tex;
     3varying vec v_tex;
    44attribute vec3 a_vertex;
    5 attribute vec2 a_uv0;
     5attribute vec a_uv0;
    66
    77void main()
    88{
    99  gl_Position = gl_ModelViewProjectionMatrix * vec4(a_vertex, 1.0);
    10   v_tex = gl_MultiTexCoord0.xy;
     10  v_tex = gl_MultiTexCoord0.xy;
    1111}
  • ps/trunk/source/graphics/ShaderManager.cpp

    r12306 r12727  
    176176    CShaderDefines defines = baseDefines;
    177177    std::map<CStrIntern, int> vertexUniforms;
    178     std::map<CStrIntern, int> fragmentUniforms;
     178    std::map<CStrIntern, t> fragmentUniforms;
    179179    std::map<CStrIntern, int> vertexAttribs;
    180180    int streamFlags = 0;
     
    241241                if (Param.GetNodeName() == el_uniform)
    242242                {
    243                     fragmentUniforms[CStrIntern(Attrs.GetNamedItem(at_name))] = Attrs.GetNamedItem(at_loc).ToInt();
     243                    // A somewhat incomplete listing, missing "shadow" and "rect" versions
     244                    // which are interpreted as 2D (NB: our shadowmaps may change
     245                    // type based on user config).
     246                    GLenum type = GL_TEXTURE_2D;
     247                    CStr t = Attrs.GetNamedItem(at_type);
     248                    if (t == "sampler1D")
     249                        type = GL_TEXTURE_1D;
     250                    else if (t == "sampler2D")
     251                        type = GL_TEXTURE_2D;
     252                    else if (t == "sampler3D")
     253                        type = GL_TEXTURE_3D;
     254                    else if (t == "samplerCube")
     255                        type = GL_TEXTURE_CUBE_MAP;
     256                   
     257                    fragmentUniforms[CStrIntern(Attrs.GetNamedItem(at_name))] =
     258                        std::make_pair(Attrs.GetNamedItem(at_loc).ToInt(), type);
    244259                }
    245260            }
  • ps/trunk/source/graphics/ShaderProgram.cpp

    r11663 r12727  
    3737    CShaderProgramARB(const VfsPath& vertexFile, const VfsPath& fragmentFile,
    3838        const CShaderDefines& defines,
    39         const std::map<CStrIntern, int>& vertexIndexes, const std::map<CStrIntern, int>& fragmentIndexes,
     39        const std::map<CStrIntern, int>& vertexIndexes, const std::map<CStrIntern, t>& fragmentIndexes,
    4040        int streamflags) :
    4141        CShaderProgram(streamflags),
     
    148148    }
    149149
    150     int GetUniformFragmentIndex(CStrIntern id)
    151     {
    152         std::map<CStrIntern, int>::iterator it = m_FragmentIndexes.find(id);
     150    t GetUniformFragmentIndex(CStrIntern id)
     151    {
     152        std::map<CStrIntern, t>::iterator it = m_FragmentIndexes.find(id);
    153153        if (it == m_FragmentIndexes.end())
    154             return -1;
     154            return ;
    155155        return it->second;
    156156    }
     
    158158    virtual Binding GetTextureBinding(texture_id_t id)
    159159    {
    160         int index = GetUniformFragmentIndex(CStrIntern(id));
     160        frag_index_pair_t fPair = GetUniformFragmentIndex(CStrIntern(id));
     161        int index = fPair.first;
    161162        if (index == -1)
    162163            return Binding();
    163164        else
    164             return Binding((int)GL_TEXTURE_2D, index);
     165            return Binding((int), index);
    165166    }
    166167
    167168    virtual void BindTexture(texture_id_t id, Handle tex)
    168169    {
    169         int index = GetUniformFragmentIndex(CStrIntern(id));
     170        frag_index_pair_t fPair = GetUniformFragmentIndex(CStrIntern(id));
     171        int index = fPair.first;
    170172        if (index != -1)
    171173        {
     
    173175            ogl_tex_get_texture_id(tex, &h);
    174176            pglActiveTextureARB(GL_TEXTURE0+index);
    175             glBindTexture(GL_TEXTURE_2D, h);
     177            glBindTexture(, h);
    176178        }
    177179    }
     
    179181    virtual void BindTexture(texture_id_t id, GLuint tex)
    180182    {
    181         int index = GetUniformFragmentIndex(CStrIntern(id));
     183        frag_index_pair_t fPair = GetUniformFragmentIndex(CStrIntern(id));
     184        int index = fPair.first;
    182185        if (index != -1)
    183186        {
    184187            pglActiveTextureARB(GL_TEXTURE0+index);
    185             glBindTexture(GL_TEXTURE_2D, tex);
     188            glBindTexture(, tex);
    186189        }
    187190    }
     
    197200    {
    198201        CStrIntern idIntern(id);
    199         return Binding(GetUniformVertexIndex(idIntern), GetUniformFragmentIndex(idIntern));
     202        return Binding(GetUniformVertexIndex(idIntern), GetUniformFragmentIndex(idIntern));
    200203    }
    201204
    202205    virtual Binding GetUniformBinding(CStrIntern id)
    203206    {
    204         return Binding(GetUniformVertexIndex(id), GetUniformFragmentIndex(id));
     207        return Binding(GetUniformVertexIndex(id), GetUniformFragmentIndex(id));
    205208    }
    206209
     
    248251
    249252    std::map<CStrIntern, int> m_VertexIndexes;
    250     std::map<CStrIntern, int> m_FragmentIndexes;
     253   
     254    // pair contains <index, gltype>
     255    std::map<CStrIntern, frag_index_pair_t> m_FragmentIndexes;
    251256};
    252257
     
    681686/*static*/ CShaderProgram* CShaderProgram::ConstructARB(const VfsPath& vertexFile, const VfsPath& fragmentFile,
    682687    const CShaderDefines& defines,
    683     const std::map<CStrIntern, int>& vertexIndexes, const std::map<CStrIntern, int>& fragmentIndexes,
     688    const std::map<CStrIntern, int>& vertexIndexes, const std::map<CStrIntern, t>& fragmentIndexes,
    684689    int streamflags)
    685690{
  • ps/trunk/source/graphics/ShaderProgram.h

    r11663 r12727  
    6868
    6969public:
     70
     71
     72
     73
     74
    7075    /**
    7176     * Construct based on ARB vertex/fragment program files.
     
    7378    static CShaderProgram* ConstructARB(const VfsPath& vertexFile, const VfsPath& fragmentFile,
    7479        const CShaderDefines& defines,
    75         const std::map<CStrIntern, int>& vertexIndexes, const std::map<CStrIntern, int>& fragmentIndexes,
     80        const std::map<CStrIntern, int>& vertexIndexes, const std::map<CStrIntern, t>& fragmentIndexes,
    7681        int streamflags);
    7782
     
    8893     */
    8994    static CShaderProgram* ConstructFFP(const std::string& id, const CShaderDefines& defines);
    90 
    91     typedef const char* attrib_id_t;
    92     typedef const char* texture_id_t;
    93     typedef const char* uniform_id_t;
    94 
     95   
    9596    /**
    9697     * Represents a uniform attribute or texture binding.
  • ps/trunk/source/renderer/SkyManager.cpp

    r12697 r12727  
    7777void SkyManager::LoadSkyTextures()
    7878{
    79     for (size_t i = 0; i < ARRAY_SIZE(m_SkyTexture); ++i)
     79    for (size_t i = 0; i < ARRAY_SIZE(m_SkyTexture); ++i)
    8080    {
    8181        VfsPath path = VfsPath("art/textures/skies") / m_SkySet / (Path::String(s_imageNames[i])+L".dds");
     
    8686        texture->Prefetch();
    8787        m_SkyTexture[i] = texture;
    88     }
     88    }
    8989   
    9090    ///////////////////////////////////////////////////////////////////////////
     
    246246    const CCamera& camera = g_Renderer.GetViewCamera();
    247247    CVector3D pos = camera.m_Orientation.GetTranslation();
     248
    248249    glTranslatef( pos.X, m_HorizonHeight, pos.Z );
    249250
    250251    // Rotate so that the "left" face, which contains the brightest part of each
    251252    // skymap, is in the direction of the sun from our light environment
    252     glRotatef( 90.0f + RADTODEG(g_Renderer.GetLightEnv().GetRotation()), 0.0f, 1.0f, 0.0f );
     253    glRotatef( + RADTODEG(g_Renderer.GetLightEnv().GetRotation()), 0.0f, 1.0f, 0.0f );
    253254
    254255    // Distance to draw the faces at
     
    263264        skytech->BeginPass();
    264265        shader = skytech->GetShader();
    265     }
    266 
    267     // Front face (positive Z)
     266        shader->BindTexture("baseTex", m_SkyCubeMap);
     267    }
     268    else
     269    {
     270        glDisable(GL_TEXTURE_2D);
     271        glEnable(GL_TEXTURE_CUBE_MAP);
     272        glBindTexture(GL_TEXTURE_CUBE_MAP, m_SkyCubeMap);
     273    }
     274
     275    // GL_TEXTURE_CUBE_MAP_NEGATIVE_X
     276    glBegin(GL_QUADS);
     277        glTexCoord3f( +1, +1, +1 );  glVertex3f( -D, -D, -D );
     278        glTexCoord3f( +1, +1, -1 );  glVertex3f( -D, -D, +D );
     279        glTexCoord3f( +1, -1, -1 );  glVertex3f( -D, +D, +D );
     280        glTexCoord3f( +1, -1, +1 );  glVertex3f( -D, +D, -D );
     281    glEnd();
     282
     283    // GL_TEXTURE_CUBE_MAP_POSITIVE_X
     284    glBegin(GL_QUADS);
     285        glTexCoord3f( -1, +1, -1 );  glVertex3f( +D, -D, +D );
     286        glTexCoord3f( -1, +1, +1 );  glVertex3f( +D, -D, -D );
     287        glTexCoord3f( -1, -1, +1 );  glVertex3f( +D, +D, -D );
     288        glTexCoord3f( -1, -1, -1 );  glVertex3f( +D, +D, +D );
     289    glEnd();
     290   
     291    // GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
     292    glBegin(GL_QUADS);
     293        glTexCoord3f( -1, +1, +1 );  glVertex3f( +D, -D, -D );
     294        glTexCoord3f( -1, +1, -1 );  glVertex3f( +D, -D, +D );
     295        glTexCoord3f( +1, +1, -1 );  glVertex3f( -D, -D, +D );
     296        glTexCoord3f( +1, +1, +1 );  glVertex3f( -D, -D, -D );
     297       
     298    glEnd();
     299   
     300    // GL_TEXTURE_CUBE_MAP_POSITIVE_Y
     301    glBegin(GL_QUADS);
     302        glTexCoord3f( +1, -1, +1 );  glVertex3f( -D, +D, -D );
     303        glTexCoord3f( +1, -1, -1 );  glVertex3f( -D, +D, +D );
     304        glTexCoord3f( -1, -1, -1 );  glVertex3f( +D, +D, +D );
     305        glTexCoord3f( -1, -1, +1 );  glVertex3f( +D, +D, -D );
     306    glEnd();
     307   
     308    // GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
     309    glBegin(GL_QUADS);
     310        glTexCoord3f( -1, +1, +1 );  glVertex3f( +D, -D, -D );
     311        glTexCoord3f( +1, +1, +1 );  glVertex3f( -D, -D, -D );
     312        glTexCoord3f( +1, -1, +1 );  glVertex3f( -D, +D, -D );
     313        glTexCoord3f( -1, -1, +1 );  glVertex3f( +D, +D, -D );
     314    glEnd();
     315
     316    // GL_TEXTURE_CUBE_MAP_POSITIVE_Z
     317    glBegin(GL_QUADS);
     318        glTexCoord3f( +1, +1, -1 );  glVertex3f( -D, -D, +D );
     319        glTexCoord3f( -1, +1, -1 );  glVertex3f( +D, -D, +D );
     320        glTexCoord3f( -1, -1, -1 );  glVertex3f( +D, +D, +D );
     321        glTexCoord3f( +1, -1, -1 );  glVertex3f( -D, +D, +D );
     322    glEnd();
     323
    268324    if (g_Renderer.GetRenderPath() == CRenderer::RP_SHADER)
    269         shader->BindTexture("baseTex", m_SkyTexture[FRONT]);
     325    {
     326        skytech->EndPass();
     327    }
    270328    else
    271         m_SkyTexture[FRONT]->Bind();
    272    
    273     glBegin( GL_QUADS );
    274         glTexCoord2f( 0, 1 );
    275         glVertex3f( -D, -D, +D );
    276         glTexCoord2f( 1, 1 );
    277         glVertex3f( +D, -D, +D );
    278         glTexCoord2f( 1, 0 );
    279         glVertex3f( +D, +D, +D );
    280         glTexCoord2f( 0, 0 );
    281         glVertex3f( -D, +D, +D );
    282     glEnd();
    283 
    284     // Back face (negative Z)
    285     if (g_Renderer.GetRenderPath() == CRenderer::RP_SHADER)
    286         shader->BindTexture("baseTex", m_SkyTexture[BACK]);
    287     else
    288         m_SkyTexture[BACK]->Bind();
    289    
    290     glBegin( GL_QUADS );
    291         glTexCoord2f( 1, 1 );
    292         glVertex3f( -D, -D, -D );
    293         glTexCoord2f( 1, 0 );
    294         glVertex3f( -D, +D, -D );
    295         glTexCoord2f( 0, 0 );
    296         glVertex3f( +D, +D, -D );
    297         glTexCoord2f( 0, 1 );
    298         glVertex3f( +D, -D, -D );
    299     glEnd();
    300 
    301     // Right face (negative X)
    302     if (g_Renderer.GetRenderPath() == CRenderer::RP_SHADER)
    303         shader->BindTexture("baseTex", m_SkyTexture[RIGHT]);
    304     else
    305         m_SkyTexture[RIGHT]->Bind();
    306    
    307     glBegin( GL_QUADS );
    308         glTexCoord2f( 0, 1 );
    309         glVertex3f( -D, -D, -D );
    310         glTexCoord2f( 1, 1 );
    311         glVertex3f( -D, -D, +D );
    312         glTexCoord2f( 1, 0 );
    313         glVertex3f( -D, +D, +D );
    314         glTexCoord2f( 0, 0 );
    315         glVertex3f( -D, +D, -D );
    316     glEnd();
    317 
    318     // Left face (positive X)
    319     if (g_Renderer.GetRenderPath() == CRenderer::RP_SHADER)
    320         shader->BindTexture("baseTex", m_SkyTexture[LEFT]);
    321     else
    322         m_SkyTexture[LEFT]->Bind();
    323    
    324     glBegin( GL_QUADS );
    325         glTexCoord2f( 1, 1 );
    326         glVertex3f( +D, -D, -D );
    327         glTexCoord2f( 1, 0 );
    328         glVertex3f( +D, +D, -D );
    329         glTexCoord2f( 0, 0 );
    330         glVertex3f( +D, +D, +D );
    331         glTexCoord2f( 0, 1 );
    332         glVertex3f( +D, -D, +D );
    333     glEnd();
    334 
    335     // Top face (positive Y)
    336     if (g_Renderer.GetRenderPath() == CRenderer::RP_SHADER)
    337         shader->BindTexture("baseTex", m_SkyTexture[TOP]);
    338     else
    339         m_SkyTexture[TOP]->Bind();
    340    
    341     glBegin( GL_QUADS );
    342         glTexCoord2f( 1, 0 );
    343         glVertex3f( +D, +D, -D );
    344         glTexCoord2f( 0, 0 );
    345         glVertex3f( -D, +D, -D );
    346         glTexCoord2f( 0, 1 );
    347         glVertex3f( -D, +D, +D );
    348         glTexCoord2f( 1, 1 );
    349         glVertex3f( +D, +D, +D );
    350     glEnd();
    351    
    352     if (g_Renderer.GetRenderPath() == CRenderer::RP_SHADER)
    353         skytech->EndPass();
    354 
     329    {
     330        glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
     331        glDisable(GL_TEXTURE_CUBE_MAP);
     332        glEnable(GL_TEXTURE_2D);
     333    }
     334   
    355335    glPopMatrix();
    356336
Note: See TracChangeset for help on using the changeset viewer.