Shaders’ Outpost
Moderators: winston, another_commander
- Griff
- Oolite 2 Art Director
- Posts: 2483
- Joined: Fri Jul 14, 2006 12:29 pm
- Location: Probably hugging his Air Fryer
Pagroove's Station Textures thread got me in the mood to try adding the new shader effects to an old trade outpost station model i've had kicking around for a while, it's basically an excuse to go over the top on glow maps!
I've put the model in an .oxp using LittleBear's and Commander McLane's tip to give it a coriolis role so it should appear in-game as a replacement to the usual system coriolis station every now and again as you make your way around the galaxy.
It's quite shader heavy and although it does work quite happily on non-shader enabled systems, it does look a bit dark and drab and difficult to spot, so if you're not running oolite with shaders i recommend saving yourself the 2.6MB download (blimey! 2.6MB for 1 ship ) and a lot of faff mucking about with your monitors brightness & contrast levels!
Some screenies:-
Download here:- http://www.box.net/shared/uisjeppusk (2.6MB)
Edit: this version fixes the problem texture, the 'const float' shader error and renames the shaders
I've put the model in an .oxp using LittleBear's and Commander McLane's tip to give it a coriolis role so it should appear in-game as a replacement to the usual system coriolis station every now and again as you make your way around the galaxy.
It's quite shader heavy and although it does work quite happily on non-shader enabled systems, it does look a bit dark and drab and difficult to spot, so if you're not running oolite with shaders i recommend saving yourself the 2.6MB download (blimey! 2.6MB for 1 ship ) and a lot of faff mucking about with your monitors brightness & contrast levels!
Some screenies:-
Download here:- http://www.box.net/shared/uisjeppusk (2.6MB)
Edit: this version fixes the problem texture, the 'const float' shader error and renames the shaders
Last edited by Griff on Sun Feb 17, 2008 9:17 pm, edited 3 times in total.
- JensAyton
- Grand Admiral Emeritus
- Posts: 6657
- Joined: Sat Apr 02, 2005 2:43 pm
- Location: Sweden
- Contact:
griff_no_shader_screen.png is 255 pixels wide, and will be rescaled to 256 pixels at loading time.
I looked at all those textures – 17 of them – and went “eek”, especially with the talk of memory usage in other threads. But I make it a mere 5.7 MiB in total, uncompressed. That’s less than one and a half 1024x1024 textures! In case it wasn’t obvious before, if you want to learn the art of cramming in details, study Griff.
I looked at all those textures – 17 of them – and went “eek”, especially with the talk of memory usage in other threads. But I make it a mere 5.7 MiB in total, uncompressed. That’s less than one and a half 1024x1024 textures! In case it wasn’t obvious before, if you want to learn the art of cramming in details, study Griff.
E-mail: [email protected]
- Griff
- Oolite 2 Art Director
- Posts: 2483
- Joined: Fri Jul 14, 2006 12:29 pm
- Location: Probably hugging his Air Fryer
Cheers Ahruman! I've fixed the problem texture and re-uploaded the oxp.
Yep, it is a bit of a whopper. I wanted to do a ship that used all the shader effects we've got so far. The Freaky Thargoid shader i used for the lights running up the pole on the station roof is a bit of a mind bender! I've no idea how it does the stuff it does but just messing about with it in rendermonkey using various texture maps produced some pretty 'far out' effects (man)!
Yep, it is a bit of a whopper. I wanted to do a ship that used all the shader effects we've got so far. The Freaky Thargoid shader i used for the lights running up the pole on the station roof is a bit of a mind bender! I've no idea how it does the stuff it does but just messing about with it in rendermonkey using various texture maps produced some pretty 'far out' effects (man)!
- Arexack_Heretic
- Dangerous Subversive Element
- Posts: 1876
- Joined: Tue Jun 07, 2005 7:32 pm
- Location: [%H] = Earth surface, Lattitude 52°10'58.19"N, longtitude 4°30'0.25"E.
- Contact:
- JensAyton
- Grand Admiral Emeritus
- Posts: 6657
- Joined: Sat Apr 02, 2005 2:43 pm
- Location: Sweden
- Contact:
OK, griff, now I’ve got some real complaints:
The bit where it tells you which shader is causing a problem is brand new, by the way. It tells me that you’re using my name for your shaders. Bad Griff, no cookie. (The actual problem is that it’s not valid to base a const on a uniform.)
Code: Select all
[shader.compile.vertex.failure]: ***** GLSL vertex shader compilation failed for ahruman-animated.vertex:
>>>>> GLSL log:
ERROR: 0:16: '=' : assigning non-constant to 'const float'
>>>>> GLSL source code:
#define OO_USER_DEFINED_BINDINGS 1
#define OO_TEXTURE_UNIT_COUNT 8
// Information from Oolite.
uniform float uTime;
uniform float FrameCount;
uniform float TimePerFrame;
varying vec3 v_normal; // Surface normal
varying vec3 v_pos; // Vertex/fragment position in eye space
// Control factors.
// Derived constants.
const float kAnimCycleTime = TimePerFrame * FrameCount;
void main(void)
{
v_normal = normalize(gl_NormalMatrix * gl_Normal);
v_pos = vec3(gl_ModelViewMatrix * gl_Vertex);
gl_Position = ftransform();
vec4 coord = gl_TextureMatrix[0] * gl_MultiTexCoord0;
// Select frame.
coord.t += floor(mod(uTime, kAnimCycleTime) / TimePerFrame);
// Scale texture co-ordinates to 0..1
coord.t /= FrameCount;
gl_TexCoord[0] = coord;
}
[shader.compile.vertex.failure]: ***** GLSL vertex shader compilation failed for ahruman-animated_w_rollbars.vertex:
>>>>> GLSL log:
ERROR: 0:16: '=' : assigning non-constant to 'const float'
>>>>> GLSL source code:
#define OO_USER_DEFINED_BINDINGS 1
#define OO_TEXTURE_UNIT_COUNT 8
// Information from Oolite.
uniform float uTime;
varying vec3 v_normal; // Surface normal
varying vec3 v_pos; // Vertex/fragment position in eye space
// Control factors.
uniform float TimePerFrame;
uniform float FrameCount;
// Derived constants.
const float kAnimCycleTime = TimePerFrame * FrameCount;
varying vec2 vTexCoordnoise;
void main(void)
{
v_normal = normalize(gl_NormalMatrix * gl_Normal);
v_pos = vec3(gl_ModelViewMatrix * gl_Vertex);
gl_Position = ftransform();
vec4 coord = gl_TextureMatrix[0] * gl_MultiTexCoord0;
// Select frame.
coord.t += floor(mod(uTime, kAnimCycleTime) / TimePerFrame);
// Scale texture co-ordinates to 0..1
coord.t /= FrameCount;
gl_TexCoord[0] = coord;
// Create a set of UV coordinates shifted in Y axis by current uTime value
vTexCoordnoise.x = gl_MultiTexCoord0.x;
vTexCoordnoise.y = gl_MultiTexCoord0.y + uTime / (5.0);
}
E-mail: [email protected]
- Griff
- Oolite 2 Art Director
- Posts: 2483
- Joined: Fri Jul 14, 2006 12:29 pm
- Location: Probably hugging his Air Fryer
Ah yes, the shader didn't work unless i changed the variable type from "const float" to "uniform float" - the timing was all weird and the texture was stretched across the polygon as if like the shader couldn't understand the numbers or something.
I'll explain what i was trying to do, the "ahruman-animated_w_rollbars.vertex" problem shader is based on the ahruman-billboard.fragment shader from the shady_billboards oxp. In your example you've hardcoded the DisplayTime and FrameCount settings in the shader code using:-
i wanted to use the same shader for animations of either 2 frames or 4 frames in length and different playback speeds, so i was hoping if i put:-
in the Uniforms section of the shipdata.plist and i removed these hardcoded values in the shader, it would use whatever values i gave it in the uniforms declarations. well, it didn't work until i changed the shader code from
to
I wonderd at the time if this was bad, but it seemed to work OK so i just left it
I'll explain what i was trying to do, the "ahruman-animated_w_rollbars.vertex" problem shader is based on the ahruman-billboard.fragment shader from the shady_billboards oxp. In your example you've hardcoded the DisplayTime and FrameCount settings in the shader code using:-
Code: Select all
const float TimePerFrame = 5.0;
const float FrameCount = 4.0;
Code: Select all
FrameCount = { type = "float"; value = 2.0; };
TimePerFrame = { type = "float"; value = 0.7; };
Code: Select all
const float TimePerFrame;
const float FrameCount;
Code: Select all
uniform float TimePerFrame;
uniform float FrameCount;
- JensAyton
- Grand Admiral Emeritus
- Posts: 6657
- Joined: Sat Apr 02, 2005 2:43 pm
- Location: Sweden
- Contact:
Your uniforms must indeed be declared as uniforms. The fix here is to change kAnimCycleTime from const float to float. And rename the files “griff-station-animated-w-rollbars” or similar. :-)
On a different note, you have been chosen as a participant in my very first official Oolitepr0npromo. By “a pariticipant in” I mean “the subject of”.
On a different note, you have been chosen as a participant in my very first official Oolite
E-mail: [email protected]
- Griff
- Oolite 2 Art Director
- Posts: 2483
- Joined: Fri Jul 14, 2006 12:29 pm
- Location: Probably hugging his Air Fryer
sorry about the shader name thing, thanks for your help but i still can't get this working, it flickers like mad and looks like this:-
It seems like on one poly the texture is being repeated across it vertically about 7 times and on the other poly it looks like 1 row of pixels is being smeared accross the whole surface
in the shipdata uniforms i've got
and in the relevant vertex shader i've got
is that right?
Awesome vid by the way!
It seems like on one poly the texture is being repeated across it vertically about 7 times and on the other poly it looks like 1 row of pixels is being smeared accross the whole surface
in the shipdata uniforms i've got
Code: Select all
shaders =
{
"griff_no_shader_screen.png" =
{
vertex_shader = "griff_station_animated_w_rollbars.vertex";
fragment_shader = "griff_station_animated_w_rollbars.fragment";
textures = ({name = "griff_madam_hiss_2frames_1x1.png"; repeat_t = "yes";});
uniforms =
{
FrameCount = { type = "float"; value = 2.0; };
TimePerFrame = { type = "float"; value = 2.0; };
uTime = "timeElapsedSinceSpawn";
};
};
};
};
Code: Select all
// Information from Oolite.
uniform float uTime;
float TimePerFrame;
float FrameCount;
varying vec3 v_normal; // Surface normal
varying vec3 v_pos; // Vertex/fragment position in eye space
// Derived constants.
float kAnimCycleTime = TimePerFrame * FrameCount;
varying vec2 vTexCoordnoise;
Awesome vid by the way!
- JensAyton
- Grand Admiral Emeritus
- Posts: 6657
- Joined: Sat Apr 02, 2005 2:43 pm
- Location: Sweden
- Contact:
Clearly the texture co-ordinates are getting messed up. Weird; as you’ve seen, it works here. I can’t seen any obvious reason for it in the shader.Griff wrote:sorry about the shader name thing, thanks for your help but i still can't get this working, it flickers like mad and looks like this:-
It seems like on one poly the texture is being repeated across it vertically about 7 times and on the other poly it looks like 1 row of pixels is being smeared accross the whole surface
E-mail: [email protected]
- Griff
- Oolite 2 Art Director
- Posts: 2483
- Joined: Fri Jul 14, 2006 12:29 pm
- Location: Probably hugging his Air Fryer
hmm, putting the shader into rendermonkey gives the same messed up texture as well as these errors:-
warning C7522: OpenGL requires constants to be initialized
warning C7522: OpenGL requires constants to be initialized
warning C7050: "TimePerFrame" might be used before being initialized
warning C7050: "FrameCount" might be used before being initialized
this happens as soon as i remove hard coded values from these variables in the shader code eg,
const float kTimePerFrame = 3.0;
const float kFrameCount = 5.0;
and instead link them to sliders (to emulate values being passed to the shader from oolite), it seems anything other than a Uniform Float sends the shader nuts.
edit:
what happens if i leave 'TimePerFrame' and 'FrameCount' as uniform floats but change 'kAnimCycleTime' to a float (rather than a const float), is that OK from a programming viewpoint?
i just tried this out and Oolite and Rendermonky are both happy, and i can't see anything in the stderr log (after pausing game and pressing s for shader debug)
Durr! What a massive berk i am, that's what you told me to do isn't it, when you told me how to fix the shader! *smacks palm to forehead*
I've edited the download link above with a version that fixes this problem, thanks for your help sorting that out Ahruman.
warning C7522: OpenGL requires constants to be initialized
warning C7522: OpenGL requires constants to be initialized
warning C7050: "TimePerFrame" might be used before being initialized
warning C7050: "FrameCount" might be used before being initialized
this happens as soon as i remove hard coded values from these variables in the shader code eg,
const float kTimePerFrame = 3.0;
const float kFrameCount = 5.0;
and instead link them to sliders (to emulate values being passed to the shader from oolite), it seems anything other than a Uniform Float sends the shader nuts.
what happens if i leave 'TimePerFrame' and 'FrameCount' as uniform floats but change 'kAnimCycleTime' to a float (rather than a const float), is that OK from a programming viewpoint?
i just tried this out and Oolite and Rendermonky are both happy, and i can't see anything in the stderr log (after pausing game and pressing s for shader debug)
Durr! What a massive berk i am, that's what you told me to do isn't it, when you told me how to fix the shader! *smacks palm to forehead*
I've edited the download link above with a version that fixes this problem, thanks for your help sorting that out Ahruman.
- Griff
- Oolite 2 Art Director
- Posts: 2483
- Joined: Fri Jul 14, 2006 12:29 pm
- Location: Probably hugging his Air Fryer
coloured specular:
I've added a vec4 called "lightColor"to the fragment shader as so:
vec4 lightColor = vec4(0.8, 0.5, 0.2, 1.0); // a nice golden orange colour
and changed the line that adds the specular effect in the light function to this:
specular = mix(specular * lightColor, specular * diffuse, 0.0);
It just occured to me that the 'suns' in the game might already give off coloured light, so if they do then uh, ignore this since the specular will already be coloured correctly, but i suppose this might be useful if you want to force a particular specular highlight colour.
I've added a vec4 called "lightColor"to the fragment shader as so:
vec4 lightColor = vec4(0.8, 0.5, 0.2, 1.0); // a nice golden orange colour
and changed the line that adds the specular effect in the light function to this:
specular = mix(specular * lightColor, specular * diffuse, 0.0);
It just occured to me that the 'suns' in the game might already give off coloured light, so if they do then uh, ignore this since the specular will already be coloured correctly, but i suppose this might be useful if you want to force a particular specular highlight colour.
- JensAyton
- Grand Admiral Emeritus
- Posts: 6657
- Joined: Sat Apr 02, 2005 2:43 pm
- Location: Sweden
- Contact:
Yes. :-)Griff wrote:It just occured to me that the 'suns' in the game might already give off coloured light,
For reference, specular reflections in metal are coloured by the metal, most noticeable with yellow metals. My recent examples using the default shader use a slight blue tint for steel. Other shiny surfaces are almost always transparent with no inherent colour (coloured plastics and resins, for instance, are almost always a transparent medium with particles of pigments and titanium dioxide embedded in it; varnished wood consists of a layer of transparent varnish on top of wood), and reflect uncoloured light (i.e., the same colour as the incoming light).
E-mail: [email protected]