Changeset 12727
- Timestamp:
- Oct 3, 2012, 2:40:01 PM (12 years ago)
- Location:
- ps/trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
ps/trunk/binaries/data/mods/public/shaders/arb/sky.fp
r12551 r12727 1 1 !!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 14 PARAM c[1] = { { 0.25, 0, 1, 4 } }; 15 TEMP R0; 16 TEMP R1; 17 TEMP R2; 18 SLT R2.x, c[0].y, fragment.texcoord[0].y; 19 ABS R2.x, R2; 20 TEX R0, fragment.texcoord[0], texture[0], CUBE; 21 ADD R1.x, -fragment.texcoord[0].y, c[0]; 22 MUL R1, R0, R1.x; 23 MUL R1, R1, c[0].w; 24 CMP R2.x, -R2, c[0].y, c[0].z; 25 CMP result.color, -R2.x, R0, R1; 5 26 END 27 -
ps/trunk/binaries/data/mods/public/shaders/arb/sky.xml
r12551 r12727 7 7 8 8 <fragment file="arb/sky.fp"> 9 <uniform name="baseTex" loc="0" type="sampler 2D"/>9 <uniform name="baseTex" loc="0" type="sampler"/> 10 10 </fragment> 11 11 -
ps/trunk/binaries/data/mods/public/shaders/glsl/sky.fs
r12551 r12727 1 1 #version 110 2 2 3 uniform sampler 2DbaseTex;4 varying vec 2v_tex;3 uniform sampler baseTex; 4 varying vec v_tex; 5 5 6 6 void main() 7 7 { 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 9 16 } -
ps/trunk/binaries/data/mods/public/shaders/glsl/sky.vs
r12557 r12727 1 1 #version 110 2 2 3 varying vec 2v_tex;3 varying vec v_tex; 4 4 attribute vec3 a_vertex; 5 attribute vec 2a_uv0;5 attribute vec a_uv0; 6 6 7 7 void main() 8 8 { 9 9 gl_Position = gl_ModelViewProjectionMatrix * vec4(a_vertex, 1.0); 10 v_tex = gl_MultiTexCoord0.xy ;10 v_tex = gl_MultiTexCoord0.xy; 11 11 } -
ps/trunk/source/graphics/ShaderManager.cpp
r12306 r12727 176 176 CShaderDefines defines = baseDefines; 177 177 std::map<CStrIntern, int> vertexUniforms; 178 std::map<CStrIntern, int> fragmentUniforms;178 std::map<CStrIntern, t> fragmentUniforms; 179 179 std::map<CStrIntern, int> vertexAttribs; 180 180 int streamFlags = 0; … … 241 241 if (Param.GetNodeName() == el_uniform) 242 242 { 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); 244 259 } 245 260 } -
ps/trunk/source/graphics/ShaderProgram.cpp
r11663 r12727 37 37 CShaderProgramARB(const VfsPath& vertexFile, const VfsPath& fragmentFile, 38 38 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, 40 40 int streamflags) : 41 41 CShaderProgram(streamflags), … … 148 148 } 149 149 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); 153 153 if (it == m_FragmentIndexes.end()) 154 return -1;154 return ; 155 155 return it->second; 156 156 } … … 158 158 virtual Binding GetTextureBinding(texture_id_t id) 159 159 { 160 int index = GetUniformFragmentIndex(CStrIntern(id)); 160 frag_index_pair_t fPair = GetUniformFragmentIndex(CStrIntern(id)); 161 int index = fPair.first; 161 162 if (index == -1) 162 163 return Binding(); 163 164 else 164 return Binding((int) GL_TEXTURE_2D, index);165 return Binding((int), index); 165 166 } 166 167 167 168 virtual void BindTexture(texture_id_t id, Handle tex) 168 169 { 169 int index = GetUniformFragmentIndex(CStrIntern(id)); 170 frag_index_pair_t fPair = GetUniformFragmentIndex(CStrIntern(id)); 171 int index = fPair.first; 170 172 if (index != -1) 171 173 { … … 173 175 ogl_tex_get_texture_id(tex, &h); 174 176 pglActiveTextureARB(GL_TEXTURE0+index); 175 glBindTexture( GL_TEXTURE_2D, h);177 glBindTexture(, h); 176 178 } 177 179 } … … 179 181 virtual void BindTexture(texture_id_t id, GLuint tex) 180 182 { 181 int index = GetUniformFragmentIndex(CStrIntern(id)); 183 frag_index_pair_t fPair = GetUniformFragmentIndex(CStrIntern(id)); 184 int index = fPair.first; 182 185 if (index != -1) 183 186 { 184 187 pglActiveTextureARB(GL_TEXTURE0+index); 185 glBindTexture( GL_TEXTURE_2D, tex);188 glBindTexture(, tex); 186 189 } 187 190 } … … 197 200 { 198 201 CStrIntern idIntern(id); 199 return Binding(GetUniformVertexIndex(idIntern), GetUniformFragmentIndex(idIntern) );202 return Binding(GetUniformVertexIndex(idIntern), GetUniformFragmentIndex(idIntern)); 200 203 } 201 204 202 205 virtual Binding GetUniformBinding(CStrIntern id) 203 206 { 204 return Binding(GetUniformVertexIndex(id), GetUniformFragmentIndex(id) );207 return Binding(GetUniformVertexIndex(id), GetUniformFragmentIndex(id)); 205 208 } 206 209 … … 248 251 249 252 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; 251 256 }; 252 257 … … 681 686 /*static*/ CShaderProgram* CShaderProgram::ConstructARB(const VfsPath& vertexFile, const VfsPath& fragmentFile, 682 687 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, 684 689 int streamflags) 685 690 { -
ps/trunk/source/graphics/ShaderProgram.h
r11663 r12727 68 68 69 69 public: 70 71 72 73 74 70 75 /** 71 76 * Construct based on ARB vertex/fragment program files. … … 73 78 static CShaderProgram* ConstructARB(const VfsPath& vertexFile, const VfsPath& fragmentFile, 74 79 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, 76 81 int streamflags); 77 82 … … 88 93 */ 89 94 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 95 96 /** 96 97 * Represents a uniform attribute or texture binding. -
ps/trunk/source/renderer/SkyManager.cpp
r12697 r12727 77 77 void SkyManager::LoadSkyTextures() 78 78 { 79 for (size_t i = 0; i < ARRAY_SIZE(m_SkyTexture); ++i)79 for (size_t i = 0; i < ARRAY_SIZE(m_SkyTexture); ++i) 80 80 { 81 81 VfsPath path = VfsPath("art/textures/skies") / m_SkySet / (Path::String(s_imageNames[i])+L".dds"); … … 86 86 texture->Prefetch(); 87 87 m_SkyTexture[i] = texture; 88 } 88 } 89 89 90 90 /////////////////////////////////////////////////////////////////////////// … … 246 246 const CCamera& camera = g_Renderer.GetViewCamera(); 247 247 CVector3D pos = camera.m_Orientation.GetTranslation(); 248 248 249 glTranslatef( pos.X, m_HorizonHeight, pos.Z ); 249 250 250 251 // Rotate so that the "left" face, which contains the brightest part of each 251 252 // 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 ); 253 254 254 255 // Distance to draw the faces at … … 263 264 skytech->BeginPass(); 264 265 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 268 324 if (g_Renderer.GetRenderPath() == CRenderer::RP_SHADER) 269 shader->BindTexture("baseTex", m_SkyTexture[FRONT]); 325 { 326 skytech->EndPass(); 327 } 270 328 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 355 335 glPopMatrix(); 356 336
Note:
See TracChangeset
for help on using the changeset viewer.