# GLSL PS1.3 fur shader, convert to PS2.0

Hi Guys

am learning GLSL at the moment, I am using irrlicht3D and am trying to compile a fur shader that was written for pixelshader1.3, however my card has ps2.0 so i am trying to convert it.

uniform float fFurLength;
uniform float fUVScale;
uniform float fLayer; // 0 to 1 for the level
uniform vec3 vGravity;

uniform vec4 vLightDir;

//textures
uniform sampler2D FurTexture;
uniform sampler2D ColourTexture;

varying vec3 normal;

mat4 mWorldViewProj= gl_ModelViewProjectionMatrix;
mat4 mWorld = gl_ModelViewMatrix;

vec3 vNormal = gl_Normal;
vec4 vVertex = gl_Vertex;

void main()
{
vec3 P = vVertex.xyz + (vNormal * ((fFurLength)*10));
vNormal = normalize( vNormal * mat3(mWorld ));

vec3 vGravity2 = vGravity *mat3(mWorld );
//float pp = 3.14 * 0.5 * Layer; // depth paramete
//float A = dot(normal, vGravity);  //A is the angle between surface normal and gravity vector
float k = pow(fLayer, 3.0); // We use the pow function, so that only the tips of the hairs bend
// As layer goes from 0 to 1, so by using pow(..) function is still
// goes form 0 to 1, but it increases faster! exponentially
P = P + vGravity2 * k;
// End Gravity Force Addit Code

gl_TexCoord[0] = gl_MultiTexCoord0 * fUVScale;
gl_TexCoord[1] = gl_MultiTexCoord0;
// UVScale??  Well we scale the fur texture alpha coords so this effects the fur thickness
// thinness, we don't change our T1 value as this is our actual texture!

//OUT.HPOS = P;
gl_Position = mWorldViewProj* vec4(P,1.0);
normal = vNormal;

## }

uniform float fFurLength;
uniform float fMaxLength;
uniform float fUVScale;
uniform float fForce;
uniform vec3 vGravity;
uniform vec4 vAmbient;
uniform float fLayer; // 0 to 1 for the level

uniform vec3 vLightDir;

//textures
uniform sampler2D FurTexture;
uniform sampler2D ColourTexture;

varying vec3 normal;

void main()
{
vec4 diffuseTexture = texture2D( FurTexture, vec2(gl_TexCoord[0]) ); // Fur Texture - alpha is VERY IMPORTANT!
vec4 ColourTexture = texture2D( ColourTexture, vec2(gl_TexCoord[1]) ); // Colour Texture for patterns

//return diffuseTexture; // Return just the fur colour (red in this demo)
//return (ColourTexture * (1,1,1,diffuseTexture.a));//Return texture colour looking like fur!

vec4 FinalColour = ColourTexture;
FinalColour.a = diffuseTexture;

//--------------------------
//Basic Directional Lighting
vec4 ambient = vAmbient * FinalColour;
vec4 diffuse = FinalColour;
//FinalColour = ambient + diffuse * (dot(vLightDir, normal) * 0.5);
FinalColour = ambient + diffuse;
//End Basic Lighting Code
//--------------------------

if(fFurLength==0)
{
FinalColour.a = 1;
}
else
{
FinalColour.a  = diffuseTexture * ( (fMaxLength-fFurLength));
}

//return diffuseTexture;  // fur colour only!
gl_FragColor = FinalColour;       // Use texture colour

## }

compile returns the following problems

## OpenGL driver version is 1.2 or better. GLSL version: 1.1 GLSL shader failed to compile (26) : warning C7011: implicit cast from “float4” to “float” (37) : warning C7011: implicit cast from “int” to “float” (39) : warning C7011: implicit cast from “int” to “float” (43) : warning C7011: implicit cast from “float4” to “float” (20) : error C1102: incompatible type for parameter #1 (“s”) (20) : error C1102: incompatible type for parameter #1 (“s”)

i have got rid of the warnings in the fragment shader by altering it to the following

## fur.frag

uniform float fFurLength;
uniform float fMaxLength;
uniform float fUVScale;
uniform float fForce;
uniform vec3 vGravity;
uniform vec4 vAmbient;
uniform float fLayer; // 0 to 1 for the level

uniform vec3 vLightDir;

//textures
uniform sampler2D FurTexture;
uniform sampler2D ColourTexture;

varying vec3 normal;

void main()
{
vec4 diffuseTexture = texture2D( FurTexture, vec2(gl_TexCoord[0]) ); // Fur Texture - alpha is VERY IMPORTANT!
vec4 ColourTexture = texture2D( ColourTexture, vec2(gl_TexCoord[1]) ); // Colour Texture for patterns

//return diffuseTexture; // Return just the fur colour (red in this demo)
//return (ColourTexture * (1,1,1,diffuseTexture.a));//Return texture colour looking like fur!

vec4 FinalColour = ColourTexture;
FinalColour.a = diffuseTexture.a;

//--------------------------
//Basic Directional Lighting
vec4 ambient = vAmbient * FinalColour;
vec4 diffuse = FinalColour;
//FinalColour = ambient + diffuse * (dot(vLightDir, normal) * 0.5);
FinalColour = ambient + diffuse;
//End Basic Lighting Code
//--------------------------

if(fFurLength==float(0))
{
FinalColour.a = float(1);
}
else
{
FinalColour.a  = diffuseTexture.a * ( (fMaxLength-fFurLength));
}

//return diffuseTexture;  // fur colour only!
gl_FragColor = FinalColour;       // Use texture colour

## }

could anyone provide a hint as to how i get rid of the two errors remaining
(20) : error C1102: incompatible type for parameter #1 (“s”)
(20) : error C1102: incompatible type for parameter #1 (“s”)

robbbbbbbbbbbbbbbb

The fragment code looks like it should be fine. (BTW instead of doing “float(1)” etc you can just do “1.0”)

The vertex shader does seem to have a few compile errors in it however. The “10” should be 10.0 and mat3(mWorld) is not valid unless you are using a higher level shader version (specify #version tag at the top)

What card / OS / Driver are you running?

that explains the warning, have changed all ints to have a .0 on the end, the shaders are being added under pixel/vertex shader model 2 as for what hardware, see below

Irrlicht Engine version 1.7.1
Microsoft Windows XP Professional Service Pack 3 (Build 2600)
Using renderer: OpenGL 2.0.1
OpenGL driver version is 1.2 or better.
GLSL version: 1.1

Checking available NVIDIA Corporation GPU features..
Is driver able to render to a surface?                          True
Is hardeware transform and lighting supported?                  True
Are multiple textures per material possible?                    True
Is driver able to render with a bilinear filter applied?        True
Can the driver handle mip maps?                                 True
Can the driver update mip maps automatically?                   True
Are stencilbuffers switched on/supported?                       True
Is Vertex Shader 1.1 supported?                                 True
Is Vertex Shader 2.0 supported?                                 True
Is Vertex Shader 3.0 supported?                                 False
Is Pixel Shader 1.1 supported?                                  True
Is Pixel Shader 1.2 supported?                                  True
Is Pixel Shader 1.3 supported?                                  False
Is Pixel Shader 1.4 supported?                                  False
Is Pixel Shader 2.0 supported?                                  True
Is Pixel Shader 3.0 supported?                                  False
Are ARB vertex programs v1.0 supported?                         True
Are ARB fragment programs v1.0 supported?                       True
Is GLSL supported?                                              True
Is HLSL supported?                                              False
Are non-square textures supported?                              True
Are non-power-of-two textures supported?                        True
Are framebuffer objects supported?                              True
Are vertex buffer objects supported?                            True
Supports Alpha To Coverage?                                     True
Supports Color masks (disabling color planes in output)?        True
Supports multiple render targets at once?                       True
Supports separate blend settings for multiple render targets?   False
Supports separate color masks for multiple render targets?      False
Supports separate blend functions for multiple render targets?  False

(20) : error C1102: incompatible type for parameter #1 ("s")
(20) : error C1102: incompatible type for parameter #1 ("s")

ga

Resizing window (800 600)

vec4 ColourTexture  = texture2D( ColourTexture, vec2(gl_TexCoord[1]) ); // Colour Texture for patterns

but as for the why, hmmmm?

vec4 ColourTexture = texture2D( ColourTexture, vec2(gl_TexCoord[1]).xy ); // Colour Texture for patterns

hyy ZbuffeR
have swapped the line above but the same errors are output, have also tried it this way

vec4 ColourTexture  = texture2D( ColourTexture, vec2(gl_TexCoord[1].xy) ); // Colour Texture for patterns

hmmm

** fixed it
actually the code is declaring a variable sampler2D ColourTexture and the declaring the variable again with the same name as a vec4 on the offending line

thanks for looking guys