Can anyone tell me if this shader will work (HLSL)

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Asimov
Posts: 246
Joined: Thu Dec 04, 2014 7:41 pm
Contact:

Can anyone tell me if this shader will work (HLSL)

Post by Asimov »

Hi,
I have just built a shader in 3ds Max using shaderfx. It exports to HLSL 3 and 5.
Now the problem is that so far I haven't worked out how to get the code working in irrlicht for shaders. I have tried pulling apart tutorial 10 and trying to load my shader into it, but I think I am doing it wrong anyway. I haven't pasted my code yet as I think I had it so wrong it would be embarrassing.

Also I know even if a shader is in HLSL format it might not be compatible with the irrlicht engine. So I am wondering if there are any shader experts who can tell me if my shader will work, or how it needs to be modified to work in irrlicht. I am making a game where I need a shader with normalmaps and five light sources. I think the one I made here has only 3 light sources at the moment. I have been watching tutorials on shaders, but I have limited understanding on how they work.

PS. I keep reading on the forum that there is no such thing as an irrlicht shader and go and learn HLSL. Well the problem is that when you have an HLSL shader you can't load it in. Surely if a shader has the HLSL standard and irrlicht is supposed to work with HLSL why should it be changed before it will work in irrlicht. The other problem I am finding is that there is no documentation anywhere on how to make an HLSL work in irrlight apart from tutorial 10 and that does not say what works and what doesn't work in irrlicht at all. So how do I make my shader work with little or no documentation?

Code: Select all

// ----------------------------------- Per Frame --------------------------------------
float4x4 viewI : ViewInverse < string UIType = "None"; >;
 
 
// --------------------------------------- Per Object -----------------------------------------
int texcoord0 : Texcoord <int Texcoord = 0; int MapChannel = 1;> = 0;
 
float4x4 world : World < string UIType = "None"; >;
 
int ClampDynamicLights
<
    float UIMin = 0;
    float UISoftMin = 0;
    float UIMax = 99;
    float UISoftMax = 99;
    float UIStep = 1;
    string UIName = "ClampDynamicLights";
    string UIType = "IntSpinner";
> = 99;
 
float4x4 wvp : WorldViewProjection < string UIType = "None"; >;
 
 
// ----------------------------------- Lights --------------------------------------
int Light0Type : LIGHTTYPE
<
    string UIName =  "Light 0 Type (2:spot 3:omni 4:dir)";
    float UIMin = 0;
    float UIMax = 5;
    float UIStep = 1;
    int LightRef = 1;
> = {3};
 
int Light1Type : LIGHTTYPE
<
    string UIName =  "Light 1 Type (2:spot 3:omni 4:dir)";
    float UIMin = 0;
    float UIMax = 5;
    float UIStep = 1;
    int LightRef = 2;
> = {3};
 
int Light2Type : LIGHTTYPE
<
    string UIName =  "Light 2 Type (2:spot 3:omni 4:dir)";
    float UIMin = 0;
    float UIMax = 5;
    float UIStep = 1;
    int LightRef = 3;
> = {3};
 
float3 Light0Color : LIGHTCOLOR
<
    string UIType = "None";
    int LightRef = 1;
> = { 1.0, 1.0, 1.0};
 
float3 Light1Color : LIGHTCOLOR
<
    string UIType = "None";
    int LightRef = 2;
> = { 1.0, 1.0, 1.0};
 
float3 Light2Color : LIGHTCOLOR
<
    string UIType = "None";
    int LightRef = 3;
> = { 1.0, 1.0, 1.0};
 
float Light0Intensity : LIGHTINTENSITY
<
    float UIMin = 0;
    float UIStep = 0.1;
    string UIType = "None";
    int LightRef = 1;
> = 1.0;
 
float Light1Intensity : LIGHTINTENSITY
<
    float UIMin = 0;
    float UIStep = 0.1;
    string UIType = "None";
    int LightRef = 2;
> = 1.0;
 
float Light2Intensity : LIGHTINTENSITY
<
    float UIMin = 0;
    float UIStep = 0.1;
    string UIType = "None";
    int LightRef = 3;
> = 1.0;
 
float3 Light0Pos : POSITION
<
    string UIName =  "Light 0 Position";
    string Space = "World";
    string UIType = "None";
    int RefID = 1;
    string Object = "PointLight";
> = {1.0, 1.0, 1.0};
 
float3 Light1Pos : POSITION
<
    string UIName =  "Light 1 Position";
    string Space = "World";
    string UIType = "None";
    int RefID = 2;
    string Object = "PointLight";
> = {1.0, 1.0, 1.0};
 
float3 Light2Pos : POSITION
<
    string UIName =  "Light 2 Position";
    string Space = "World";
    string UIType = "None";
    int RefID = 3;
    string Object = "PointLight";
> = {1.0, 1.0, 1.0};
 
float3 Light0Dir : DIRECTION
<
    string UIName =  "Light 0 Direction";
    string Space = "World";
    string UIType = "None";
    int RefID = 100;
    string Object = "TargetLight";
> = {0.0, -1.0, 0.0};
 
float3 Light1Dir : DIRECTION
<
    string UIName =  "Light 1 Direction";
    string Space = "World";
    string UIType = "None";
    int RefID = 101;
    string Object = "TargetLight";
> = {0.0, -1.0, 0.0};
 
float3 Light2Dir : DIRECTION
<
    string UIName =  "Light 2 Direction";
    string Space = "World";
    string UIType = "None";
    int RefID = 102;
    string Object = "TargetLight";
> = {0.0, -1.0, 0.0};
 
float Light0Attenuation
<
    float UIMin = 0;
    float UIStep = 1;
    string UIType = "None";
    int LightRef = 1;
> = 0.0;
 
float Light1Attenuation
<
    float UIMin = 0;
    float UIStep = 1;
    string UIType = "None";
    int LightRef = 2;
> = 0.0;
 
float Light2Attenuation
<
    float UIMin = 0;
    float UIStep = 1;
    string UIType = "None";
    int LightRef = 3;
> = 0.0;
 
float Light0ConeAngle : LightHotSpot
<
    float UIMin = 0;
    float UIMax = 1.571;
    float UIStep = 0.05;
    string Space = "World";
    string UIType = "None";
    int LightRef = 1;
> = 0.46;
 
float Light1ConeAngle : LightHotSpot
<
    float UIMin = 0;
    float UIMax = 1.571;
    float UIStep = 0.05;
    string Space = "World";
    string UIType = "None";
    int LightRef = 2;
> = 0.46;
 
float Light2ConeAngle : LightHotSpot
<
    float UIMin = 0;
    float UIMax = 1.571;
    float UIStep = 0.05;
    string Space = "World";
    string UIType = "None";
    int LightRef = 3;
> = 0.46;
 
float Light0Falloff : LightFallOff
<
    float UIMin = 0;
    float UIMax = 1.571;
    float UIStep = 0.05;
    string UIType = "None";
    int LightRef = 1;
> = 0.7;
 
float Light1Falloff : LightFallOff
<
    float UIMin = 0;
    float UIMax = 1.571;
    float UIStep = 0.05;
    string UIType = "None";
    int LightRef = 2;
> = 0.7;
 
float Light2Falloff : LightFallOff
<
    float UIMin = 0;
    float UIMax = 1.571;
    float UIStep = 0.05;
    string UIType = "None";
    int LightRef = 3;
> = 0.7;
 
bool Light0ShadowOn : SHADOWFLAG
<
    string UIType = "None";
    int LightRef = 1;
> = true;
 
bool Light1ShadowOn : SHADOWFLAG
<
    string UIType = "None";
    int LightRef = 2;
> = true;
 
bool Light2ShadowOn : SHADOWFLAG
<
    string UIType = "None";
    int LightRef = 3;
> = true;
 
float4x4 Light0ViewPrj : SHADOWMAPMATRIX
<
    string Object =  "Light 0";
    string UIName =  "Light 0 Matrix";
    string UIType = "None";
>;
 
float4x4 Light1ViewPrj : SHADOWMAPMATRIX
<
    string Object =  "Light 1";
    string UIName =  "Light 1 Matrix";
    string UIType = "None";
>;
 
float4x4 Light2ViewPrj : SHADOWMAPMATRIX
<
    string Object =  "Light 2";
    string UIName =  "Light 2 Matrix";
    string UIType = "None";
>;
 
float3 Light0ShadowColor : SHADOWCOLOR
<
    string UIType = "None";
    int LightRef = 1;
> = {0, 0, 0};
 
float3 Light1ShadowColor : SHADOWCOLOR
<
    string UIType = "None";
    int LightRef = 2;
> = {0, 0, 0};
 
float3 Light2ShadowColor : SHADOWCOLOR
<
    string UIType = "None";
    int LightRef = 3;
> = {0, 0, 0};
 
 
// ---------------------------------------- Textures -----------------------------------------
Texture2D Diffuse2copytga
<
    string ResourceName = "Diffuse.tga";
    string ResourceType = "2D";
    string UIType = "Bitmap";
>;
 
sampler2D Diffuse2copytgaSampler = sampler_state 
{
    Texture = <Diffuse2copytga>;
    MinFilter = Linear;
    MagFilter = Linear;
    AddressU = WRAP;
    AddressV = WRAP;
    AddressW = WRAP;
};
 
Texture2D nrmtga
<
    string ResourceName = "nrm.tga";
    string ResourceType = "2D";
    string UIType = "Bitmap";
>;
 
sampler2D nrmtgaSampler = sampler_state 
{
    Texture = <nrmtga>;
    MinFilter = Linear;
    MagFilter = Linear;
    AddressU = WRAP;
    AddressV = WRAP;
    AddressW = WRAP;
};
 
Texture2D Light0ShadowMap : SHADOWMAP
<
    string ResourceName = "";
    string ResourceType = "2D";
    string UIType = "None";
    int LightRef = 1;
>;
 
Texture2D Light1ShadowMap : SHADOWMAP
<
    string ResourceName = "";
    string ResourceType = "2D";
    string UIType = "None";
    int LightRef = 2;
>;
 
Texture2D Light2ShadowMap : SHADOWMAP
<
    string ResourceName = "";
    string ResourceType = "2D";
    string UIType = "None";
    int LightRef = 3;
>;
 
sampler2D Light0ShadowMapSampler = sampler_state 
{
    Texture = <Light0ShadowMap>;
    MinFilter = Point;
    MagFilter = Point;
    AddressU = BORDER;
    AddressV = BORDER;
    AddressW = BORDER;
    BorderColor = float4(1.0,1.0,1.0,1.0);
};
 
sampler2D Light1ShadowMapSampler = sampler_state 
{
    Texture = <Light1ShadowMap>;
    MinFilter = Point;
    MagFilter = Point;
    AddressU = BORDER;
    AddressV = BORDER;
    AddressW = BORDER;
    BorderColor = float4(1.0,1.0,1.0,1.0);
};
 
sampler2D Light2ShadowMapSampler = sampler_state 
{
    Texture = <Light2ShadowMap>;
    MinFilter = Point;
    MagFilter = Point;
    AddressU = BORDER;
    AddressV = BORDER;
    AddressW = BORDER;
    BorderColor = float4(1.0,1.0,1.0,1.0);
};
 
 
// ---------------------------------------- Functions -----------------------------------------
int GetLightType(int ActiveLightIndex) 
{ 
    if (ActiveLightIndex == 0) 
        return Light0Type; 
    else if (ActiveLightIndex == 1) 
        return Light1Type; 
    else 
        return Light2Type; 
}
 
float3 GetLightColor(int ActiveLightIndex) 
{ 
    if (ActiveLightIndex == 0) 
        return Light0Color; 
    else if (ActiveLightIndex == 1) 
        return Light1Color; 
    else 
        return Light2Color; 
}
 
float GetLightIntensity(int ActiveLightIndex) 
{ 
    if (ActiveLightIndex == 0) 
        return Light0Intensity; 
    else if (ActiveLightIndex == 1) 
        return Light1Intensity; 
    else 
        return Light2Intensity; 
}
 
float3 GetLightPos(int ActiveLightIndex) 
{ 
    if (ActiveLightIndex == 0) 
        return Light0Pos; 
    else if (ActiveLightIndex == 1) 
        return Light1Pos; 
    else 
        return Light2Pos; 
}
 
float3 GetLightDir(int ActiveLightIndex) 
{ 
    if (ActiveLightIndex == 0) 
        return Light0Dir; 
    else if (ActiveLightIndex == 1) 
        return Light1Dir; 
    else 
        return Light2Dir; 
}
 
float GetLightAttenuation(int ActiveLightIndex) 
{ 
    if (ActiveLightIndex == 0) 
        return Light0Attenuation; 
    else if (ActiveLightIndex == 1) 
        return Light1Attenuation; 
    else 
        return Light2Attenuation; 
}
 
float GetLightConeAngle(int ActiveLightIndex) 
{ 
    if (ActiveLightIndex == 0) 
        return Light0ConeAngle; 
    else if (ActiveLightIndex == 1) 
        return Light1ConeAngle; 
    else 
        return Light2ConeAngle; 
}
 
float GetLightFalloff(int ActiveLightIndex) 
{ 
    if (ActiveLightIndex == 0) 
        return Light0Falloff; 
    else if (ActiveLightIndex == 1) 
        return Light1Falloff; 
    else 
        return Light2Falloff; 
}
 
bool GetLightShadowOn(int ActiveLightIndex) 
{ 
    if (ActiveLightIndex == 0) 
        return Light0ShadowOn; 
    else if (ActiveLightIndex == 1) 
        return Light1ShadowOn; 
    else 
        return Light2ShadowOn; 
}
 
float4x4 GetLightViewPrj(int ActiveLightIndex) 
{ 
    if (ActiveLightIndex == 0) 
        return Light0ViewPrj; 
    else if (ActiveLightIndex == 1) 
        return Light1ViewPrj; 
    else 
        return Light2ViewPrj; 
}
 
Texture2D GetLightShadowMap(int ActiveLightIndex) 
{ 
    if (ActiveLightIndex == 0) 
        return Light0ShadowMap; 
    else if (ActiveLightIndex == 1) 
        return Light1ShadowMap; 
    else 
        return Light2ShadowMap; 
}
 
float4 SampleFromShadowMap( int ActiveLightIndex, float2 UVs) 
{ 
    if (ActiveLightIndex == 0) 
        return tex2Dlod(Light0ShadowMapSampler, float4(UVs, 0.0, 0.0) ); 
    else if (ActiveLightIndex == 1) 
        return tex2Dlod(Light1ShadowMapSampler, float4(UVs, 0.0, 0.0) ); 
    else 
        return tex2Dlod(Light2ShadowMapSampler, float4(UVs, 0.0, 0.0) ); 
}
 
float3 GetLightShadowColor(int ActiveLightIndex) 
{ 
    if (ActiveLightIndex == 0) 
        return Light0ShadowColor; 
    else if (ActiveLightIndex == 1) 
        return Light1ShadowColor; 
    else 
        return Light2ShadowColor; 
}
 
 
// -------------------------------------- APP and DATA  --------------------------------------
struct APPDATA
{
    float3 Position : POSITION;
    float2 map1 : TEXCOORD0;
    float3 Tangent : TANGENT;
    float3 Normal : NORMAL;
    float3 BiNormal : BINORMAL;
};
 
struct SHADERDATA
{
    float4 Position : POSITION;
    float4 map1 : TEXCOORD0;
    float4 Tangent : TEXCOORD1;
    float4 Normal : TEXCOORD2;
    float4 WorldPosition : TEXCOORD3;
};
 
// -------------------------------------- ExpandRangeFunction --------------------------------------
struct ExpandRangeOutput
{
    float3 ExpandedVector;
};
 
ExpandRangeOutput ExpandRangeFunction(float3 Vector)
{
    ExpandRangeOutput OUT;
 
    float3 NormalMap = (Vector * 2.0);
    float3 NormalMap1363 = (NormalMap - 1.0);
    OUT.ExpandedVector = NormalMap1363;
 
    return OUT;
}
 
// -------------------------------------- TangentWorldConvertFunction --------------------------------------
struct TangentWorldConvertOutput
{
    float3 Vector;
};
 
TangentWorldConvertOutput TangentWorldConvertFunction(float TangentDirection, float3 Normal, float3 Tangent, float3 Vector)
{
    TangentWorldConvertOutput OUT;
 
    float3 Bn = (cross(Normal, Tangent) * TangentDirection);
    float3x3 toWorld = float3x3(Tangent, Bn, Normal);
    float3 TangentToWorld = mul(Vector, toWorld);
    OUT.Vector = TangentToWorld;
 
    return OUT;
}
 
// -------------------------------------- AmbientLightFunction --------------------------------------
struct AmbientLightOutput
{
    float3 LightColor;
};
 
AmbientLightOutput AmbientLightFunction(int ActiveLightIndex, float3 AlbedoColor, float3 LightColor, float LightIntensity)
{
    AmbientLightOutput OUT;
 
    float3 MulOp = (LightIntensity * (AlbedoColor * LightColor));
    OUT.LightColor = MulOp;
 
    return OUT;
}
 
// -------------------------------------- GetLightVectorFunction --------------------------------------
struct GetLightVectorOutput
{
    float3 Result;
};
 
GetLightVectorOutput GetLightVectorFunction(int ActiveLightIndex, float3 LightPosition, float3 VertexWorldPosition, int LightType, float3 LightDirection)
{
    GetLightVectorOutput OUT;
 
    bool IsDirectionalLight = (LightType == 4);
    float3 LerpOp = lerp((LightPosition - VertexWorldPosition), -(LightDirection), IsDirectionalLight);
    OUT.Result = LerpOp;
 
    return OUT;
}
 
// -------------------------------------- LambertDiffuseFunction --------------------------------------
struct LambertDiffuseOutput
{
    float3 Color;
};
 
LambertDiffuseOutput LambertDiffuseFunction(int ActiveLightIndex, float3 AlbedoColor, float3 Normal, float3 LightVector)
{
    LambertDiffuseOutput OUT;
 
    float SatOp = saturate(dot(Normal, LightVector));
    float3 Diffuse = (AlbedoColor * SatOp);
    OUT.Color = Diffuse;
 
    return OUT;
}
 
// -------------------------------------- LightDecayFunction --------------------------------------
struct LightDecayOutput
{
    float Attenuation;
};
 
LightDecayOutput LightDecayFunction(int ActiveLightIndex, float3 LightVectorUN, float Attenuation)
{
    LightDecayOutput OUT;
 
    bool IsAttenuationUsed = (Attenuation > 0.001);
    float DecayContribution459 = 0.0;
    if (IsAttenuationUsed)
    {
        float PowOp = pow(length(LightVectorUN), Attenuation);
        float DivOp = (1.0 / PowOp);
        DecayContribution459 = DivOp;
    }
    else
    {
        DecayContribution459 = 1.0;
    }
    OUT.Attenuation = DecayContribution459;
 
    return OUT;
}
 
// -------------------------------------- LightConeAngleFunction --------------------------------------
struct LightConeAngleOutput
{
    float ConeAngle;
};
 
LightConeAngleOutput LightConeAngleFunction(int ActiveLightIndex, float3 LightVector, float3 LightDirection, float ConeAngle, float ConeFalloff)
{
    LightConeAngleOutput OUT;
 
    float CosOp = cos(max(ConeFalloff, ConeAngle));
    float DotOp = dot(LightVector, -(LightDirection));
    float SmoothStepOp = smoothstep(CosOp, cos(ConeAngle), DotOp);
    OUT.ConeAngle = SmoothStepOp;
 
    return OUT;
}
 
// -------------------------------------- ShadowMapFunction --------------------------------------
struct ShadowMapOutput
{
    float LightGain;
};
 
ShadowMapOutput ShadowMapFunction(int ActiveLightIndex, float4x4 LightViewPrj, float ShadowMapBias, float3 VertexWorldPosition)
{
    ShadowMapOutput OUT;
 
    float IfElseOp542 = 0.0;
    float4 VectorConstruct = float4(VertexWorldPosition.x, VertexWorldPosition.y, VertexWorldPosition.z, 1.0);
    float4 MulOp = mul(VectorConstruct, LightViewPrj);
    float3 DivOp = (MulOp.xyz / MulOp.w);
    if (DivOp.x > -1.0 && DivOp.x < 1.0 && DivOp.y > -1.0 && DivOp.y < 1.0 && DivOp.z > 0.0 && DivOp.z < 1.0)
    {
        float Val = 0.5;
        float2 AddOp = ((DivOp.xy * Val) + Val);
        float SubOp = (DivOp.z - (ShadowMapBias / MulOp.w));
        float ShadowTotal = 0.0;
        for(int i=0; i<10; i+=1)
        {
            Texture2D _LightShadowMap = GetLightShadowMap(ActiveLightIndex);
            float2 MulOp582 = (float2(1.0, 1.0) * 0.00195313);
            float4 Sampler = SampleFromShadowMap(ActiveLightIndex, (AddOp + MulOp582));
            float IfElseOp536 = ((SubOp - Sampler.x) >= 0.0) ? (0.0) : (0.1);
            ShadowTotal += IfElseOp536;
        }
        IfElseOp542 = ShadowTotal;
    }
    else
    {
        IfElseOp542 = 1.0;
    }
    OUT.LightGain = IfElseOp542;
 
    return OUT;
}
 
// -------------------------------------- LightContributionFunction --------------------------------------
struct LightContributionOutput
{
    float3 Light;
};
 
LightContributionOutput LightContributionFunction(int ActiveLightIndex, float3 VertexWorldPosition, float3 LightVectorUN)
{
    LightContributionOutput OUT;
 
    float _LightIntensity = GetLightIntensity(ActiveLightIndex);
    int _LightType = GetLightType(ActiveLightIndex);
    bool IsDirectionalLight = (_LightType == 4);
    float DecayMul505 = 0.0;
    if (IsDirectionalLight)
    {
        DecayMul505 = 1.0;
    }
    else
    {
        float LightAttenuation = GetLightAttenuation(ActiveLightIndex);
        LightDecayOutput LightDecay453 = LightDecayFunction(ActiveLightIndex, LightVectorUN, LightAttenuation);
        DecayMul505 = LightDecay453.Attenuation;
    }
    bool IsSpotLight = (_LightType == 2);
    float ConeMul507 = 1.0;
    if (IsSpotLight)
    {
        float3 NormOp = normalize(LightVectorUN);
        float3 _LightDir = GetLightDir(ActiveLightIndex);
        float _LightConeAngle = GetLightConeAngle(ActiveLightIndex);
        float _LightFalloff = GetLightFalloff(ActiveLightIndex);
        LightConeAngleOutput LightConeAngle395 = LightConeAngleFunction(ActiveLightIndex, NormOp, -_LightDir, _LightConeAngle, _LightFalloff);
        ConeMul507 = LightConeAngle395.ConeAngle;
    }
    bool _LightShadowOn = GetLightShadowOn(ActiveLightIndex);
    float ShadowMul508 = 1.0;
    if (_LightShadowOn)
    {
        float4x4 _LightViewPrj = GetLightViewPrj(ActiveLightIndex);
        ShadowMapOutput ShadowMap521 = ShadowMapFunction(ActiveLightIndex, _LightViewPrj, 0.01, VertexWorldPosition);
        float3 _LightShadowColor = GetLightShadowColor(ActiveLightIndex);
        float ShadowColorMix = lerp(ShadowMap521.LightGain, 1.0, _LightShadowColor.x);
        ShadowMul508 = ShadowColorMix;
    }
    float DecayShadowConeMul = (DecayMul505 * (ConeMul507 * ShadowMul508));
    float3 LightColor = GetLightColor(ActiveLightIndex);
    float3 MulItensity = (_LightIntensity * (DecayShadowConeMul * LightColor));
    OUT.Light = MulItensity;
 
    return OUT;
}
 
// -------------------------------------- BlinnSpecularFunction --------------------------------------
struct BlinnSpecularOutput
{
    float3 SpecularColor;
};
 
BlinnSpecularOutput BlinnSpecularFunction(int ActiveLightIndex, float3 LightVector, float3 Normal, float3 CameraVector, float SpecularPower, float3 SpecularColor)
{
    BlinnSpecularOutput OUT;
 
    float3 NormOp = normalize((LightVector + CameraVector));
    float SatOp = saturate(dot(Normal, NormOp));
    float3 BlinnSpec = (pow(SatOp, SpecularPower) * SpecularColor);
    float SatOp970 = saturate(dot(Normal, LightVector));
    float3 MulOp = (BlinnSpec * SatOp970);
    OUT.SpecularColor = MulOp;
 
    return OUT;
}
 
// -------------------------------------- DesaturateColorFunction --------------------------------------
struct DesaturateColorOutput
{
    float DesaturateColor;
};
 
DesaturateColorOutput DesaturateColorFunction(int ActiveLightIndex, float3 Color)
{
    DesaturateColorOutput OUT;
 
    float3 Col = float3(0.300008,0.6,0.100008);
    float DotOp = dot(saturate(Color), Col.xyz);
    OUT.DesaturateColor = DotOp;
 
    return OUT;
}
 
// -------------------------------------- DesaturateColorFunction --------------------------------------
DesaturateColorOutput DesaturateColorFunction(float3 Color)
{
    DesaturateColorOutput OUT;
 
    float3 Col = float3(0.300008,0.6,0.100008);
    float DotOp = dot(saturate(Color), Col.xyz);
    OUT.DesaturateColor = DotOp;
 
    return OUT;
}
 
// -------------------------------------- ShaderVertex --------------------------------------
SHADERDATA ShaderVertex(APPDATA IN)
{
    SHADERDATA OUT;
 
    OUT.Position = float4(IN.Position, 1);
    float4 OutUVs = float4(IN.map1.x, IN.map1.y, 0.0, 0.0);
    OUT.map1 = OutUVs;
    float3 MulOp = mul(IN.Tangent, ((float3x3)world));
    float3 TangentNorm = normalize(MulOp);
    float4 WorldTangent = float4(TangentNorm.x, TangentNorm.y, TangentNorm.z, 1.0);
    OUT.Tangent = WorldTangent;
    float DotOp = dot(cross(IN.Normal, IN.Tangent), IN.BiNormal);
    float BiNormalDir1297 = (DotOp < 0.0) ? (-1.0) : (1.0);
    float4 VectorConstruct = float4(OUT.Tangent.xyz.x, OUT.Tangent.xyz.y, OUT.Tangent.xyz.z, BiNormalDir1297);
    OUT.Tangent = VectorConstruct;
    float3 MulOp1325 = mul(IN.Normal, ((float3x3)world));
    float3 NormalN = normalize(MulOp1325);
    float4 WorldNormal = float4(NormalN.x, NormalN.y, NormalN.z, 1.0);
    OUT.Normal = WorldNormal;
    float4 WorldPos = mul(OUT.Position, world);
    OUT.WorldPosition = WorldPos;
    float4 WVSpace = mul(OUT.Position, wvp);
    OUT.Position = WVSpace;
 
    return OUT;
}
 
// -------------------------------------- ShaderPixel --------------------------------------
struct PIXELDATA
{
    float4 Color : COLOR0;
};
 
PIXELDATA ShaderPixel(SHADERDATA IN, bool FrontFace : VFACE)
{
    PIXELDATA OUT;
 
    float InvertSatMask = (1.0 - saturate(0.0));
    float4 Sampler = tex2D(Diffuse2copytgaSampler, float2(IN.map1.xy.x, 1-IN.map1.xy.y));
    float3 ReplaceDiffuseWithReflection = (InvertSatMask * Sampler.xyz);
    float3 NormOp = normalize(IN.Normal.xyz);
    float3 NormOp1344 = normalize(IN.Tangent.xyz);
    float4 Sampler1472 = tex2D(nrmtgaSampler, float2(IN.map1.xy.x, 1-IN.map1.xy.y));
    ExpandRangeOutput ExpandRange1359 = ExpandRangeFunction(Sampler1472.xyz);
    float3 VectorConstruct = float3(1.0, 1.0, 1.0);
    float3 NormalMapH = (ExpandRange1359.ExpandedVector * VectorConstruct.xyz);
    TangentWorldConvertOutput TangentWorldConvert1346 = TangentWorldConvertFunction(IN.Tangent.w, NormOp, NormOp1344, NormalMapH);
    float3 TangentSpace = normalize(TangentWorldConvert1346.Vector);
    float3 FlippedNormals = lerp(-(TangentSpace), TangentSpace, !FrontFace);
    float ClampOpacity = saturate(1.0);
    float3 CameraPosition = viewI[3].xyz;
    float3 CamVec = (CameraPosition - IN.WorldPosition.xyz);
    float3 CamVecNorm = normalize(CamVec);
    float4 LightLoopTotal11 = float4(0,0,0,0);
    for (int ActiveLightIndex = 0; ActiveLightIndex < 3; ++ActiveLightIndex)
    {
        if (ActiveLightIndex >= ClampDynamicLights) {continue;}
        int _LightType = GetLightType(ActiveLightIndex);
        bool IsAmbientLight = (_LightType == 5);
        float4 IfAmbientLight380 = float4(0, 0, 0, 0);
        if (IsAmbientLight)
        {
            float3 LightColor = GetLightColor(ActiveLightIndex);
            float _LightIntensity = GetLightIntensity(ActiveLightIndex);
            AmbientLightOutput AmbientLight385 = AmbientLightFunction(ActiveLightIndex, ReplaceDiffuseWithReflection, LightColor, _LightIntensity);
            float3 AmbientLightAndAO = (1.0 * AmbientLight385.LightColor);
            float4 VectorConstruct665 = float4(AmbientLightAndAO.x, AmbientLightAndAO.y, AmbientLightAndAO.z, 0.0);
            IfAmbientLight380 = VectorConstruct665;
        }
        else
        {
            float3 NoTranslucency = float3(0.0,0.0,0.0);
            float3 _LightPos = GetLightPos(ActiveLightIndex);
            float3 _LightDir = GetLightDir(ActiveLightIndex);
            GetLightVectorOutput GetLightVector840 = GetLightVectorFunction(ActiveLightIndex, _LightPos, IN.WorldPosition.xyz, _LightType, -_LightDir);
            float3 LightVecNorm = normalize(GetLightVector840.Result);
            LambertDiffuseOutput LambertDiffuse815 = LambertDiffuseFunction(ActiveLightIndex, ReplaceDiffuseWithReflection, FlippedNormals, LightVecNorm);
            LightContributionOutput LightContribution393 = LightContributionFunction(ActiveLightIndex, IN.WorldPosition.xyz, GetLightVector840.Result);
            float3 AddTranslucency = (NoTranslucency.xyz + (LambertDiffuse815.Color * LightContribution393.Light));
            BlinnSpecularOutput BlinnSpecular958 = BlinnSpecularFunction(ActiveLightIndex, LightVecNorm, FlippedNormals, CamVecNorm, 20.0, Sampler.xyz);
            float3 SpecLightIntensity = (LightContribution393.Light * BlinnSpecular958.SpecularColor);
            float3 Diffuse_Spec = ((AddTranslucency * ClampOpacity) + SpecLightIntensity);
            DesaturateColorOutput DesaturateColor656 = DesaturateColorFunction(ActiveLightIndex, SpecLightIntensity);
            float4 Color_Alpha = float4(Diffuse_Spec.x, Diffuse_Spec.y, Diffuse_Spec.z, DesaturateColor656.DesaturateColor);
            IfAmbientLight380 = Color_Alpha;
        }
        float4 ApplyWeight391 = IfAmbientLight380;
        LightLoopTotal11 += ApplyWeight391;
    }
    float3 NoReflection = float3(0.0,0.0,0.0);
    float3 ReflectXmask = (0.0 * NoReflection.xyz);
    float3 DefaultEmissiveColor = float3(0.0,0.0,0.0);
    float3 DefaultIBLColor = float3(0.0,0.0,0.0);
    float3 PreMultipliedAlpha = ((DefaultEmissiveColor.xyz + DefaultIBLColor.xyz) * ClampOpacity);
    float3 AddReflection = (ReflectXmask + PreMultipliedAlpha);
    DesaturateColorOutput DesaturateColor359 = DesaturateColorFunction(ReflectXmask);
    float OpacityAndReflection = (ClampOpacity + DesaturateColor359.DesaturateColor);
    float4 TotalAmbientAndOpacity = float4(AddReflection.x, AddReflection.y, AddReflection.z, OpacityAndReflection);
    float4 LightLoopAndAfterLoop = (LightLoopTotal11 + TotalAmbientAndOpacity);
    float SatOp = saturate(LightLoopAndAfterLoop.w);
    float4 VectorConstruct31 = float4(LightLoopAndAfterLoop.xyz.x, LightLoopAndAfterLoop.xyz.y, LightLoopAndAfterLoop.xyz.z, SatOp);
    OUT.Color = VectorConstruct31;
 
    return OUT;
}
 
// -------------------------------------- technique T0 ---------------------------------------
technique T0
{
    pass P0
    {
        VertexShader = compile vs_3_0 ShaderVertex();
        PixelShader = compile ps_3_0 ShaderPixel();
    }
 
}
 
 
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Can anyone tell me if this shader will work (HLSL)

Post by CuteAlien »

That's one huge-ass shader man. But sorry, it's not that easy.

For example you have lines like: float4x4 viewI : ViewInverse < string UIType = "None"; >;

I have to admit part of that syntax looks unfamiliar to me, either because it's some newer DX than DX9 I'm used to, or because there's some custom stuff from Maya. But basically it means - pass some 4x4 matrix called "viewI" each frame to the shader which contains some inverse view matrix (and no idea what that string UIType stuff is about, but my guess would be - some UI tool to set the values needs that part). So you have to calculate that matrix on c++ side and then pass it to the shader. Same for all other global variables.

And then it seems to have all kind of annotations like "SHADOWMAPMATRIX" which kinda describe things like - use some shadowmatrix as generated by Maya.So you would need for example another shader to calculate the shadowmap (in the exact same format as Maya uses). And then you have to pass that as well in some way (not quite sure from a quick view how that's done here, probably it's send as some texture).

Sorry, having Maya shaders work directly would be a cool feature. But I can't offer that.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Asimov
Posts: 246
Joined: Thu Dec 04, 2014 7:41 pm
Contact:

Re: Can anyone tell me if this shader will work (HLSL)

Post by Asimov »

Hi CuteAlien,

Well it is a 3ds max shaderfx shader exported to HLSL. I even exported it as an older hlsl 3 standard.
The problem is how do I know what works in irrlicht. Like I said I have read lots of posts saying there is no such thing as an irrlicht shader and learn hlsl.
The problem is that I don't know what to learn to make it work in irrlicht.

Does irrlicht use some really old version of HLSL or is it a version of HLSL that only works in irrlicht?
If it is a special form of HLSL where do I find documention on where to write this?

If it is a specific version of HLSL I can probably find tutorials and documentation on that.
I have actually spent many weeks looking for tutorials, then I found out about shaderfx in max which is a node based shader maker, and it exports to HLSL 3 and HLSL 5 and I was hoping this would work.
I have actually paid for a shader course which I have started following, but I am not sure if what I am learning will actually work in irrlicht at all.

I have usually tried to avoid making shaders, but I need one which does normalmaps and 5 light sources.

PS This is a very simple shader that I have in the course I am following, but even that doesn't work. I am not good enough at this point to know what to change to make it work . If I can't get a simple shader working I have no chance of getting a complicated shader working. What I really need is some good documentation of how to do a shader in irrlicht, and there isn't any, that I can see.

How does anyone else learn this arcane magic? Where do they learn from?

Code: Select all

/***********************************************/
/*** automatically-tracked "tweakables" ********/
/***********************************************/
 
float4x4 wvp : WorldViewProjection < string UIWidget = "None"; >;
 
 
/****************************************************/
/********** SHADER STRUCTS **************************/
/****************************************************/
 
// input from application 
struct app2vertex
{ 
    float4 position     : POSITION;
}; 
 
 
// output to pixel shader 
struct vertex2pixel
{ 
        float4 position     : POSITION;
}; 
 
 
 
/**************************************/
/***** VERTEX SHADER ******************/
/**************************************/
 
vertex2pixel vertex(app2vertex In) 
{ 
    vertex2pixel Out = (vertex2pixel)0; 
    Out.position = mul(In.position, wvp);   // transform vert position to homogeneous clip space 
    return Out; 
} 
 
 
 
/**************************************/
/***** PIXEL SHADER *******************/
/**************************************/
 
float4 pixel(vertex2pixel In) : COLOR 
{ 
    float4 col = float4(1.0, 1.0, 1.0, 1.0);
    return col; 
} 
 
 
 
/****************************************************/
/********** TECHNIQUES ******************************/
/****************************************************/
 
technique Complete 
{  
    pass simple  
    {        
    VertexShader = compile vs_1_1 vertex(); 
    ZEnable = true; 
    ZWriteEnable = true; 
    CullMode = cw; 
    AlphaBlendEnable = false; 
    PixelShader = compile ps_2_0 pixel(); 
    }  
 
}  
 
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Can anyone tell me if this shader will work (HLSL)

Post by CuteAlien »

I'm not that familar with shaders to know what the above is. I can guess what it does, but I'm also unfamiliar with parts of it. For example I never worked with techniques and passes. Not even sure if Irrlicht would have to add something to support those or if that already works in some way. I've also never seen the "string UIWidget" stuff. Might be a more modern hlsl, Irrlicht only supports hlsl in DX9. Or simply some feature I never used.

Irrlicht uses hlsl without anything special. But - you also need to send some data from CPU to GPU - and that part is somewhat different in each tool. Irrlicht shader example shows how Irrlicht sends it's variables. The way to learn Irrlicht way is to look at the shader example. It's pretty short. The way to learn HLSL is googling for introductions and then checking specific stuff in the MSDN documentation.

In your above example: Your "tweakables" are global variables which are send each frame for each model (or each time something changes at least) from your main program to the shader using c++. Irrlicht example shows how to send it. wvp probably stands for world-view-projection matrix. So it transforms your model into world-space (so the model is positioned, rotated, scaled correctly in the world), then mulitplied by the view matrix - which you get from the camera so the world is now viewed from the camera - and lastly the projection matrix which will take the view the camera produced (which is kinda looking like a cut-off pyramid and called a frustum) and then scale all values to fit into a box with the sizes of -1 to 1 (or 0 to 1 for depth) to map it into a flat rectangle (or not so flat as it also has those depth values in the case of 3D). So basically by multiplying by your mvp matrix the vertex shaders ensures all the vertices are put into the texture of your pixel-shader (everything that lands outside the -1 to 1 ranges will just be clipped by the hardware).

The input is defined by the vertex-type used by your model. For S3DVertex type it usually looks like that:

Code: Select all

 
float3 Position : POSITION0,
float2 TexCoords : TEXCOORD0,
float4 Color : COLOR0,
float3 Normal : NORMAL
 
For the other 2 vertex types supported by Irrlicht - I have to test (I only used one other but no time right now to look for it).

The output is pretty much defined by you - depends on how much information you want to pass from vertex to pixel shader. Thought there is a limit, so you can't pass too much information that way (if you need to pass more info you'll have to use tricks like abuse a texture to pass on data). A more complex struct for your vertex2pixel might for example look like:

Code: Select all

 
float4 Position             : POSITION0;
float4 ShadowMapSamplingPos : TEXCOORD0; 
float2 TexCoords            : TEXCOORD1;
float4 View                 : TEXCOORD2;
float4 LightDir             : TEXCOORD3;
float4 Normal               : TEXCOORD4;
float3 tangent              : TEXCOORD5;
float3 binormal             : TEXCOORD6;
float4 ScreenProj           : TEXCOORD7;
 
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Asimov
Posts: 246
Joined: Thu Dec 04, 2014 7:41 pm
Contact:

Re: Can anyone tell me if this shader will work (HLSL)

Post by Asimov »

Hi CuteAlien,

Thanks for the reply. Your explanation was clear, and it seems I have to find some older tutorials that are specifically for dx9.
I have spent about a month trying to get this to work, and failing miserably.

Just tried the H-craft game. It has improved a lot since I first played it a few years ago. Still keep flying off the road though LOL.

I have a greater understand of shaders and how they work, but I have a lot to learn before I can make my own that work in irrlicht.
It is hard trying to learn this stuff on your own. I was making so much progress with the game and I have been shot in the foot trying to get the shader right LOL.
Asimov
Posts: 246
Joined: Thu Dec 04, 2014 7:41 pm
Contact:

Re: Can anyone tell me if this shader will work (HLSL)

Post by Asimov »

Hi CuteAlien,

I have just tried to load d3d9.hlsl which is the one in tutorial 10, and even that one is not compiling, so that leads me to believe that when I cut my code down to just load hlsl I am doing something wrong, so here is my code

Code: Select all

   #include <irrlicht.h>
    #include <iostream>
    #include "driverChoice.h"
 
    using namespace irr;
    using namespace core;
    using namespace scene;
    using namespace video;
    using namespace io;
    using namespace gui;
 
    #ifdef _MSC_VER
    #pragma comment(lib, "Irrlicht.lib")
    #endif
 
   IrrlichtDevice* device = 0;
    bool UseHighLevelShaders = true;
 //   bool UseCgShaders = false;
 
    class MyShaderCallBack : public video::IShaderConstantSetCallBack
    {
    public:
 
        virtual void OnSetConstants(video::IMaterialRendererServices* services,
                s32 userData)
        {
            video::IVideoDriver* driver = services->getVideoDriver();
 
            core::matrix4 invWorld = driver->getTransform(video::ETS_WORLD);
            invWorld.makeInverse();
 
            services->setVertexShaderConstant("matView", invWorld.pointer(), 16);
 
            // set clip matrix
            core::matrix4 worldViewProj;
            worldViewProj = driver->getTransform(video::ETS_PROJECTION);
            worldViewProj *= driver->getTransform(video::ETS_VIEW);
            worldViewProj *= driver->getTransform(video::ETS_WORLD);
 
            services->setVertexShaderConstant("matViewProjection", worldViewProj.pointer(), 16);
            // set camera position
            core::vector3df pos = device->getSceneManager()->getActiveCamera()->getAbsolutePosition();
 
            services->setVertexShaderConstant("fvEyePosition", reinterpret_cast<f32*>(&pos), 3);
 
            services->setVertexShaderConstant("fvLightPosition", reinterpret_cast<f32*>(&pos), 3);
 
            // set transposed world matrix
            core::matrix4 world = driver->getTransform(video::ETS_WORLD);
            world = world.getTransposed();
 
            // set texture, for textures you can use both an int and a float setPixelShaderConstant interfaces (You need it only for an OpenGL driver).
            s32 TextureLayerID = 0;
 
            services->setPixelShaderConstant("baseMap", &TextureLayerID, 0);
            services->setPixelShaderConstant("bumpMap", &TextureLayerID, 1);
 
        }
    };
 
    int main()
    {
        // create device
        IrrlichtDevice *device = createDevice(EDT_DIRECT3D9, dimension2d<u32>(800, 600),32, false, true, false);
        if (device == 0) return 1; // could not create selected driver.
 
        video::IVideoDriver* driver = device->getVideoDriver();
        scene::ISceneManager* smgr = device->getSceneManager();
        gui::IGUIEnvironment* gui = device->getGUIEnvironment();
 
        io::path vsFileName; // filename for the vertex shader
        io::path psFileName; // filename for the pixel shader
 
        psFileName = "d3d9.hlsl";
        vsFileName = psFileName; // both shaders are in the same file
 
        if (!driver->queryFeature(video::EVDF_PIXEL_SHADER_1_1) && !driver->queryFeature(video::EVDF_ARB_FRAGMENT_PROGRAM_1))
        {
            device->getLogger()->log("WARNING: Pixel shaders disabled "\
                "because of missing driver/hardware support.");
            psFileName = "";
        }
 
        if (!driver->queryFeature(video::EVDF_VERTEX_SHADER_1_1) && !driver->queryFeature(video::EVDF_ARB_VERTEX_PROGRAM_1))
        {
            device->getLogger()->log("WARNING: Vertex shaders disabled "\
                "because of missing driver/hardware support.");
            vsFileName = "";
        }
 
        // create materials
        video::IGPUProgrammingServices* gpu = driver->getGPUProgrammingServices();
        s32 newMaterialType1 = 0;
        s32 newMaterialType2 = 0;
 
        if (gpu)
        {
            MyShaderCallBack* mc = new MyShaderCallBack();
 
          if (UseHighLevelShaders)
           {
 
               const video::E_GPU_SHADING_LANGUAGE shadingLanguage = video::EGSL_DEFAULT;
 
 
                // create material from high level shaders (hlsl, glsl or cg)
                newMaterialType1 = gpu->addHighLevelShaderMaterialFromFiles(
                    vsFileName, "vs_main", video::EVST_VS_2_0,
                    psFileName, "ps_main", video::EPST_PS_2_0,
                    mc, video::EMT_SOLID, 0, shadingLanguage);
 
                newMaterialType2 = gpu->addHighLevelShaderMaterialFromFiles(
                    vsFileName, "vs_main", video::EVST_VS_2_0,
                    psFileName, "ps_main", video::EPST_PS_2_0,
                    mc, video::EMT_TRANSPARENT_ADD_COLOR, 0 , shadingLanguage);
            }
            mc->drop();
       }
 
        // create test scene node 1, with the new created material type 1
        scene::ISceneNode* node = smgr->addCubeSceneNode(50);
        node->setPosition(core::vector3df(0,0,0));
        node->setMaterialTexture(0, driver->getTexture("data/grenade/diffuse.tga"));
        node->setMaterialTexture(1, driver->getTexture("data/grenade/diffuse.tga"));
        node->setMaterialFlag(video::EMF_LIGHTING, false);
        node->setMaterialType((video::E_MATERIAL_TYPE)newMaterialType1);
 
        scene::ISceneNodeAnimator* anim = smgr->createRotationAnimator(core::vector3df(0,0.3f,0));
        node->addAnimator(anim);
        anim->drop();
 
 
      //  Same for the second cube, but with the second material we created.
        node = smgr->addCubeSceneNode(50);
        node->setPosition(core::vector3df(0,-10,50));
        node->setMaterialTexture(0, driver->getTexture("data/grenade/diffuse.tga"));
        node->setMaterialFlag(video::EMF_LIGHTING, false);
        node->setMaterialFlag(video::EMF_BLEND_OPERATION, true);
        node->setMaterialType((video::E_MATERIAL_TYPE)newMaterialType2);
 
        anim = smgr->createRotationAnimator(core::vector3df(0,0.3f,0));
        node->addAnimator(anim);
        anim->drop();
 
        scene::ILightSceneNode* node_sun = 0;
        node_sun = smgr->addLightSceneNode(0,core::vector3df(0,0,0),video::SColorf(0.5,0.5,0.5,0.0),5000.0f);
        node_sun->setLightType(ELT_POINT);
 
 
smgr->addSkyDomeSceneNode(driver->getTexture("data/skydome.jpg"),16,16,1.0f,2.5f);
 
smgr->addCameraSceneNode(0,vector3df(-100,50,100), vector3df(0,0,0));
 
        /*
        Now draw everything. That's all.
        */
 
        int lastFPS = -1;
 
        while(device->run())
            if (device->isWindowActive())
        {
            driver->beginScene(true, true, video::SColor(255,0,0,0));
            smgr->drawAll();
            driver->endScene();
 
            int fps = driver->getFPS();
 
            if (lastFPS != fps)
            {
                core::stringw str = L"Irrlicht Engine - Vertex and pixel shader example [";
                str += driver->getName();
                str += "] FPS:";
                str += fps;
 
                device->setWindowCaption(str.c_str());
                lastFPS = fps;
            }
        }
 
        device->drop();
 
        return 0;
    }
 
And I get these errors
HLSL vertex shader compilation failed:
memory X3206: implicit truncation of vector type

This is repeated a few times of course and then I get
error X3501: 'vs_main' : entry point not found.

I thought I would try the demo d3d9.hlsl and then try and alter it, but I can't even get the base one to work, so I think I have made an error in my code.
So if the base one isn't working no matter what shader I write it will not work, so I now know my code is wrong or I am missing something.

It is because tutorial 10 has everything in and I think I may have made a mistake when I tried to cut it down to just HLSL.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Can anyone tell me if this shader will work (HLSL)

Post by CuteAlien »

You changed vertexMain and pixelMain to vs_main and ps_main, but those functions do not exist.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Asimov
Posts: 246
Joined: Thu Dec 04, 2014 7:41 pm
Contact:

Re: Can anyone tell me if this shader will work (HLSL)

Post by Asimov »

Hi CuteAlien,

You are right, and I don't even remember changing them. I know I still have something wrong though because I got this error.
I am going though the code now to see if I have missed something else. Once I got the base one to load again, I will at least have more of a channce when I start on my own shader.
Image
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Can anyone tell me if this shader will work (HLSL)

Post by CuteAlien »

yeah, error is just as it says. Your shader has no variable matView. And then it lists the variables which are available.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Can anyone tell me if this shader will work (HLSL)

Post by CuteAlien »

yeah, error is just as it says. Your shader has no variable matView. And then it lists the variables which are available. So setVertexShaderConstant requires the name of a real variable in the shader.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Asimov
Posts: 246
Joined: Thu Dec 04, 2014 7:41 pm
Contact:

Re: Can anyone tell me if this shader will work (HLSL)

Post by Asimov »

Hi CuteAlien,

I found where the problem was, it was in the callback. I am not even sure how the callback functions, and what the purpose for it, other than it calls back LOL.
Anyway to cut a long story short I have now altered the callback class and now it crashes on startup doh. I haven't posted my code because I am determined to work out why it is crashing now.
The program kinda starts and then terminates. I am definately out of my depth on this, but if others can work it out, why can't I grrr :twisted:
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Re: Can anyone tell me if this shader will work (HLSL)

Post by devsh »

Try an online editor such as ShaderToy or some GUI Shader composer (I have one for GLSL its called ShaderMaker) and make your shader work (at least compile) there first.

As long as the shader is valid DX9 HLSL (which you don't tend to see in the wild anymore, most tutorials will feed you DX10+ HLSL) or GLSL (with "#version XXX compatibility" at the top) the only thing that needs adapting to irrlicht is just the way you send your cosntants/uniforms from the app.

If you used GLSL and have a card capable of OpenGL 4.3, you could use some of the legacy uniforms called "gl_LightSource[]", "gl_NormalMatrix", as well as explicit layout qualifier to avoid setting up things like vertex attribute mapping, texture slot ID for samplers in GLSL etc.

The legacy uniforms will actually automagically get populated with irrlicht's IVideoDriver projection matrices and hardware light data.
Asimov
Posts: 246
Joined: Thu Dec 04, 2014 7:41 pm
Contact:

Re: Can anyone tell me if this shader will work (HLSL)

Post by Asimov »

Hi devsh,

I had a look at Shader Toy but it was only for GL shaders and my project is directx, so I need to use HLSL shaders.
I haven't got much farther at this point. Getting a bit disappointed with my terrible efforts so far LOL.

I have messed with fx composer and produced some simple shaders, but none of them seem to work in irrlicht so far.
Still have to work out why it isn't working.

I am an average programmer in c++ and I understand the principles of shaders, but that is as far as I am at the moment.
Plus I broke the E string on my guitar so I am having a real bad day heh heh.

I have watched lots of shader tutorials and I think I am grasping it, but there isn't much documentation on converting them to irrlicht.
Example 10 seriously needs to be split up into smaller examples for beginners like me.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Can anyone tell me if this shader will work (HLSL)

Post by CuteAlien »

No worries - your guitar will sound so much better with a new set of strings. Always does :-)
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
TheMormegil
Posts: 3
Joined: Wed Mar 21, 2018 4:47 pm

Re: Can anyone tell me if this shader will work (HLSL)

Post by TheMormegil »

Hi Asimov,

Part of your problem is that you are playing around with effect (fx) files in other apps and irrlicht does not support these (there isn't really an equivalent in glsl afaik, so it couldn't be supported in a cross-platform way).
The directx function that loads such files is documented here:
https://docs.microsoft.com/en-us/window ... ctfromfile
Your second problem is that googling for HLSL help tends to give you results about these effects.
I think you can sort of get irrlicht to use an effect file but it will just be parsing it and trying to compile the vertex & pixel shader functions you specify out of it.
All techniques, sampler states, renderstates, passes etc, will be ignored and you have to set these yourself in the way irrlicht allows/expects.
If you don't already have it, I'd recommend downloading the directx9c SDK. There are samples and tutorials in there that I have found exceptionally useful.
https://www.microsoft.com/en-gb/downloa ... px?id=6812
One of the samples is called 'HLSLwithoutEffects' and should help to illustrate some of the differences you are going to have to get to grips with.
It's a while since I've had a chance to work on my irrlicht stuff, so I've forgotten some of the specific stuff I found hard to work out with this, hopefully I can get back into it soon and be able to give some more specific pointers.
Post Reply