Background:
I'm attempting to fix bugs in Ogre 1.9, and Sample_VolumeTerrain falls back to no texturing on my Radeon card, at least on Linux. That's because it's a glsl150 shader [1]. No problem, I'm not complaining or anything, but to get it to work on my card, I'm attempting to backport it to glsl. I'm fairly sure it's because I'm using the GL RenderSystem instead of GL3+. I honestly haven't tried out GL3+ because it appears GL3+ is still in alpha.
Problem:
After fixing the obvious issues, I get this output: (on both an NVidia and a Radeon card) It looks like it's sortof working, but since triplanar texturing isn't that complicated of a concept, the problem is most likely some finicky bit of fragment shader code that a newbie like me won't know anything about. Is there someone with some more experience who could point out what's going on here?
Here are the changes I made to the triplanarReference.program:
Code: Select all
diff r 05f0ce02f60d Samples/Media/volumeTerrain/triplanarReference.program
 a/Samples/Media/volumeTerrain/triplanarReference.program Sun Nov 17 23:17:48 2013 0600
+++ b/Samples/Media/volumeTerrain/triplanarReference.program Wed Nov 20 18:31:40 2013 0700
@@ 128,7 +128,7 @@
vertex_program TriplanarReferenceHigh_VSGLSL glsl
{
source triplanarReferenceVS.glsl
 syntax glsl150
+ syntax glsl
default_params
{
// Uncomment for Fog
@@ 142,7 +142,7 @@
fragment_program TriplanarReferenceHigh_PSGLSL glsl
{
source triplanarReferencePS.glsl
 syntax glsl150
+ syntax glsl
default_params
{
@@ 190,7 +190,7 @@
vertex_program TriplanarReferenceLow_VSGLSL glsl
{
source triplanarReferenceVS.glsl
 syntax glsl150
+ syntax glsl
default_params
{
// Uncomment for Fog
@@ 204,7 +204,7 @@
fragment_program TriplanarReferenceLow_PSGLSL glsl
{
source triplanarReferencePS.glsl
 syntax glsl150
+ syntax glsl
default_params
{
param_named_auto lightSpecular0 light_specular_colour 0
diff r 05f0ce02f60d Samples/Media/volumeTerrain/triplanarReferencePS.glsl
 a/Samples/Media/volumeTerrain/triplanarReferencePS.glsl Sun Nov 17 23:17:48 2013 0600
+++ b/Samples/Media/volumeTerrain/triplanarReferencePS.glsl Wed Nov 20 18:31:40 2013 0700
@@ 1,8 +1,6 @@
#version 150

in vec3 oPos;
in vec4 oNormAndFogVal;
in vec3 oEyePos;
+varying vec3 oPos;
+varying vec4 oNormAndFogVal;
+varying vec3 oEyePos;
#if LIGHT0
uniform vec4 lightPosition0;
@@ 47,11 +45,9 @@
uniform sampler2D texFromZ;
uniform sampler2D texFromZNormal;
out vec4 fragColour;

vec3 expand(vec3 v)
{
 return (v  0.5) * 2;
+ return (v  0.5) * 2.0;
}
vec4 lit(float NdotL, float NdotH, float m)
@@ 83,7 +79,7 @@
float nDotH = dot(halfAngle, normal);
vec4 lighting = lit(nDotL, nDotH, exponent);
 float attenuation = 1;
+ float attenuation = 1.0;
#if ATTENUATION
if (lightPosition.w != 0) {
float distance = length(lightPosition.xyz  oPos);
@@ 91,8 +87,8 @@
}
#endif
 float spot = 1;
 if (!(lightSpotlight.x == 1 && lightSpotlight.y == 0 && lightSpotlight.z == 0 && lightSpotlight.w == 1)) {
+ float spot = 1.0;
+ if (!(lightSpotlight.x == 1.0 && lightSpotlight.y == 0.0 && lightSpotlight.z == 0.0 && lightSpotlight.w == 1.0)) {
spot = clamp(
(dot(lightDir, normalize(lightSpotDir))  lightSpotlight.y) /
(lightSpotlight.x  lightSpotlight.y), 0.0, 1.0);
@@ 103,14 +99,13 @@
void main()
{

vec3 unitNormal = normalize(oNormAndFogVal.xyz);
vec3 eyeDir = normalize(oEyePos  oPos);
// Ported from http://http.developer.nvidia.com/GPUGems3/gpugems3_ch01.html
vec3 blendWeights = abs(unitNormal);
blendWeights = blendWeights  plateauSize;
 blendWeights = pow(max(blendWeights, 0), vec3(transitionSpeed));
+ blendWeights = pow(max(blendWeights, 0.0), vec3(transitionSpeed));
blendWeights /= vec3(blendWeights.x + blendWeights.y + blendWeights.z );
// Move the planar mapping a bit according to the normal length to avoid bad looking skirts.
float nLength = length(oNormAndFogVal.xyz  1.0);
@@ 118,9 +113,9 @@
vec2 coord2 = (oPos.zx + nLength) * texScale;
vec2 coord3 = (oPos.xy + nLength) * texScale;
 vec4 col1 = texture(texFromX, coord1);
 vec4 col2 = texture(texFromY, coord2);
 vec4 col3 = texture(texFromZ, coord3);
+ vec4 col1 = texture2D(texFromX, coord1);
+ vec4 col2 = texture2D(texFromY, coord2);
+ vec4 col3 = texture2D(texFromZ, coord3);
vec4 textColour = vec4(col1.xyz * blendWeights.x +
col2.xyz * blendWeights.y +
col3.xyz * blendWeights.z, 1);
@@ 132,9 +127,9 @@
tangent = normalize(cross(unitNormal, binormal));
mat3 TBN = mat3(tangent, binormal, unitNormal);
vec3 eyeDir2 = normalize(TBN * eyeDir);
 vec3 bumpFetch1 = expand(texture(texFromXNormal, coord1).rgb);
 vec3 bumpFetch2 = expand(texture(texFromYNormal, coord2).rgb);
 vec3 bumpFetch3 = expand(texture(texFromZNormal, coord3).rgb);
+ vec3 bumpFetch1 = expand(texture2D(texFromXNormal, coord1).rgb);
+ vec3 bumpFetch2 = expand(texture2D(texFromYNormal, coord2).rgb);
+ vec3 bumpFetch3 = expand(texture2D(texFromZNormal, coord3).rgb);
vec3 normal2 = bumpFetch1.xyz * blendWeights.x +
bumpFetch2.xyz * blendWeights.y +
bumpFetch3.xyz * blendWeights.z;
@@ 190,9 +185,9 @@
lightContribution += doLighting(oPos, normal2, eyeDir2, exponent, specularFactor, lightDir22, lightPosition2, lightDiffuse2, lightSpecular2, lightAttenuation2, lightSpotlight2, lightSpotDir22);
#endif
 fragColour = clamp(textColour * (lightContribution + ambient), 0.0, 1.0);
+ gl_FragColor = clamp(textColour * (lightContribution + ambient), 0.0, 1.0);
#if FOGLINEAR  FOGEXPONENTIAL  FOGEXPONENTIAL2
 fragColour = mix(oColor, fogColour, oNormAndFogVal.w);
+ gl_FragColor = mix(oColor, fogColour, oNormAndFogVal.w);
#endif
}
diff r 05f0ce02f60d Samples/Media/volumeTerrain/triplanarReferenceVS.glsl
 a/Samples/Media/volumeTerrain/triplanarReferenceVS.glsl Sun Nov 17 23:17:48 2013 0600
+++ b/Samples/Media/volumeTerrain/triplanarReferenceVS.glsl Wed Nov 20 18:31:40 2013 0700
@@ 1,7 +1,5 @@
#version 150

in vec4 position;
in vec3 normal;
+attribute vec4 position;
+attribute vec3 normal;
uniform vec3 eyePosition;
uniform mat4 worldviewproj;
@@ 10,9 +8,9 @@
uniform vec4 fogParams;
#endif
out vec3 oPos;
out vec4 oNormAndFogVal;
out vec3 oEyePos;
+varying vec3 oPos;
+varying vec4 oNormAndFogVal;
+varying vec3 oEyePos;
void main()
{
[1] see Samples/Media/volumeTerrain/triplanarReference.program, search for "syntax glsl150"
"Supported Shader Profiles" only lists glsl in my log:
Code: Select all
RenderSystem capabilities

RenderSystem Name: OpenGL Rendering Subsystem
GPU Vendor: amd
Device Name: AMD Radeon HD 7900 Series
Driver Version: 4.2.12422.0
* Fixed function pipeline: yes
* Hardware generation of mipmaps: no
* Texture blending: yes
* Anisotropic texture filtering: yes
* Dot product texture operation: yes
* Cube mapping: yes
* Hardware stencil buffer: yes
 Stencil depth: 8
 Two sided stencil support: yes
 Wrap stencil values: yes
8<8< snip 8<8<
* Compute programs: no
* Number of floatingpoint constants for compute programs: 0
* Number of integer constants for compute programs: 0
* Number of boolean constants for compute programs: 0
* Supported Shader Profiles: arbfp1 arbvp1 glsl gp4gp gpu_gp nvgp4 ps_1_1 ps_1_2 ps_1_3 ps_1_4