2010-04-13 16 views
5

me he dado cuenta que mis sombreadores GLSL no son compilables cuando la versión GLSL es inferior a 130.hacia atrás glsl compatibilidad

Cuáles son los elementos más importantes para tener una fuente de sombreado compatible con versiones anteriores? No quiero tener una completa compatibilidad con versiones anteriores, pero me gustaría entender las principales pautas para tener sombreadores simples (compatibles con versiones anteriores) que se ejecutan en GPU con GLSL menor que 130.

Por supuesto, el problema podría resolverse con el preprocesador

#if __VERSION__ < 130 
#define VERTEX_IN attribute 
#else 
#define VERTER_IN in 
#endif 

Pero probablemente haya muchos problemas que ignoro.

Respuesta

2

Las actividades recientes han llevado a cabo esta vieja pregunta, y me di cuenta de que resolví el problema. No fue fácil, pero es una solución exitosa, probada por muchos sombreadores basados ​​en ella y la cantidad de controladores que compila la fuente del sombreador.

Esencialmente, he utilizado la extensión GL_ARB_shading_language_include (y yo también he implementado un preprocesador fuente para los sistema que no ponerla en práctica), y terminé de definir la siguiente shader incluir fuente:

// Copyright (C) 2011-2013 Luca Piccioni 
// 
// This program is free software: you can redistribute it and/or modify 
// it under the terms of the GNU General Public License as published by 
// the Free Software Foundation, either version 3 of the License, or 
// (at your option) any later version. 
// 
// This program is distributed in the hope that it will be useful, 
// but WITHOUT ANY WARRANTY; without even the implied warranty of 
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
// GNU General Public License for more details. 
// 
// You should have received a copy of the GNU General Public License 
// along with this program. If not, see <http://www.gnu.org/licenses/>. 

// @BeginInterface 

// Shader renderer 

// Symbol defined if running on NVIDIA renderer. 
#define DS_VENDOR_NVIDIA   1 
// Symbol defined if running on ATI/AMD renderer. 
#define DS_VENDOR_AMD    2 
// Symbol defined if running on INTEL renderer 
#define DS_VENDOR_INTEL    3 

// Shader inputs and outputs keywords 
// 
// - ATTRIBUTE: used to mark a vertex shader inputs 
// - SHADER_IN: used to mark a non-vertex shader inputs 
// - SHADER_OUT: used to mark a non-fragment shader output 
// - OUT: used to mark a fragment shader output 
#if __VERSION__ >= 130 

#define ATTRIBUTE in 
#define SHADER_IN in 
#define SHADER_OUT out 
#define OUT out 

#else 

#define ATTRIBUTE attribute 
#define SHADER_IN varying 
#define SHADER_OUT varying 
#define OUT 

#endif 

// Support array attributes 
#if __VERSION__ >= 130 

#define ARRAY_ATTRIBUTE(name, size) name[size] 

#else 

#define ARRAY_ATTRIBUTE(name, size) name[size] 

#endif 

// Uniform blocks 
#if __VERSION__ >= 130 

#define BEGIN_UNIFORM_BLOCK(name) uniform name { 

#define END_UNIFORM_BLOCK() }; 

#else 

#define BEGIN_UNIFORM_BLOCK(name) 

#define END_UNIFORM_BLOCK() 

#endif 

// Input and output blocks 
#if __VERSION__ >= 150 

#define BEGIN_INPUT_BLOCK(name) in name { 
#define END_INPUT_BLOCK() }; 

#define BEGIN_OUTPUT_BLOCK(name) out name { 
#define END_OUTPUT_BLOCK() }; 

#else 

#define BEGIN_INPUT_BLOCK(name) 
#define END_INPUT_BLOCK() 

#define BEGIN_OUTPUT_BLOCK(name) 
#define END_OUTPUT_BLOCK() 

#endif 

// Texturing functions 
#if __VERSION__ >= 130 

#define TEXTURE_2D texture 
#define TEXTURE_3D texture 
#define TEXTURE_RECT texture 
#define TEXTURE_CUBE texture 

#if __VERSION__ >= 150 
#define TEXTURE_SIZE(sampler) textureSize(sampler) 
#else 
#define TEXTURE_SIZE(sampler) sampler ## _Size 
#endif 

#else 

#define TEXTURE_2D texture2D 
#define TEXTURE_3D texture3D 
#define TEXTURE_RECT texture2DRect 
#define TEXTURE_CUBE textureCube 

#endif 

// Invariance 
#if __VERSION__ >= 120 
#define INVARIANT invariant 
#else 
#define INVARIANT 
#endif 

// Attribute location 
#if defined(GL_ARB_explicit_attrib_location) 
#define LOCATION(loc)  layout(location = loc) 
#else 
#define LOCATION(loc) 
#endif 

// Geometry shader layout 
#if __VERSION__ >= 150 
#define GEOMETRY_LAYOUT_IN(from) layout (from) in 
#define GEOMETRY_LAYOUT(to, max) layout (to, max_vertices = max) out 
#else 
#define GEOMETRY_LAYOUT_IN(from) 
#define GEOMETRY_LAYOUT(to, max) 
#endif 

// @EndInterface 

De hecho, incluso el sombreador incluye antes de la fuente del sombreador, el marco puede compilar en una amplia gama de compiladores. Por supuesto, el marco debe detectar las capacidades reales del sistema y definir los parámetros del compilador para que las cosas se hagan bien (piense en un sombreador de línea porque el ancho de línea> 1.0 está en desuso).

Por supuesto, la infraestructura del sombreador puede definir requisitos mínimos. Una vez que el sombreador requiere un perfil de núcleo GLSL 1.50 o posterior, ya no es necesario incluir el sombreador arriba.

1
  • #version puesto 110 o 120 #version como la primera línea de sus shaders
  • prueba de ellos en el ShaderAnalyst de ATI
  • prueba su código en una gran cantidad de tarjetas gráficas reales de diferentes proveedores
0

Lea "OpenGL Shading Language, Bill Licea-Kane, AMD, SIGGRAPH 2009". Usted probablemente tiene que añadir el siguiente código a su aplicación con el fin de apoyar GLSL-140, 130 y 120 versiones:

#version 150 compatibility 
+0

Gracias, pero lo que estaba intentando es evitar el indicador de compatibilidad, haciendo que el código fuente del sombreador compilable para diferentes versiones solo con el preprocesador. – Luca

0

sacar la línea de #version de sus shaders y probar su código en muchas computadoras diferentes con diferentes capacidades de GPU. Verás que la compatibilidad de tu sombreador aumentará. La directiva #version a veces hará que un shader falle aunque la GPU en esa máquina pueda ejecutar todo el código de sombreado cuando no se le da un número de versión.

+0

Sí, la directiva #version se inserta en tiempo de ejecución según las capacidades del sistema desde el principio. Es esencial tener un motor escalable; sin embargo, la mayoría del sistema admite características avanzadas de GLSL. – Luca

+0

Omitiendo #version por defecto a GLSL 1.1 – Luca

Cuestiones relacionadas