Topic: Working with shaders

Hi there,

I'm recently stumbled across some problems, forcing me to use shaders. However, I'm not even close to getting it to work at all. I'm trying to use this shader (latest version on last page). My code so far is...

Type MyShaderCallBack Extends IShaderConstantSetCallBack
    Field fLightStrength1:Float
    Field fLightStrength2:Float
    Field fLightStrength3:Float
    Field fLightStrength4:Float
    
    Field fvLightPosition1:Float[3]
    Field fvLightPosition2:Float[3]
    Field fvLightPosition3:Float[3]
    Field fvLightPosition4:Float[3]
    
    Field fvLightColor1:Float[4]
    Field fvLightColor2:Float[4]
    Field fvLightColor3:Float[4]
    Field fvLightColor4:Float[4]
    
    Field fvAmbientColor:Float[4]
    
    Field fSpecularPower:Float = 0.0        'S=pow(fDiffuseIntensity,fSpecularPower)*fSpecularStrength;
    Field fSpecularStrength:Float = 0.0    'will result in less glossing surfaces
    Field fBumpStrength:Float = 0.8        'strength of the bumpmapping.. higher values will result in more "bumpy" surfaces 
    
    Method OnSetConstants(services:IMaterialRendererServices,userdata:Int)
        Local driver:IVideoDriver = services.getVideoDriver()
        
        Local var0:Float = 0
        Local var1:Float = 1
        
        services.setPixelShaderConstantFromName("baseMap", Varptr var0, 1)
        services.setPixelShaderConstantFromName("bumpMap", Varptr var1, 1)
        
        Local invWorld:matrix4 = driver.getTransform(ETS_WORLD)
        invWorld.makeInverse()
        services.setPixelShaderConstantFromName("matWorldInverse", invWorld.pointer(), 16)
        
        services.setPixelShaderConstantFromName("fLightStrength1", Varptr(fLightStrength1), 1)
        services.setPixelShaderConstantFromName("fLightStrength2", Varptr(fLightStrength2), 1)
        services.setPixelShaderConstantFromName("fLightStrength3", Varptr(fLightStrength3), 1)
        services.setPixelShaderConstantFromName("fLightStrength4", Varptr(fLightStrength4), 1)
        
        services.setPixelShaderConstantFromName("fvLightPosition1", Varptr(fvLightPosition1)[0], 3)
        services.setPixelShaderConstantFromName("fvLightPosition2", Varptr(fvLightPosition2)[0], 3)
        services.setPixelShaderConstantFromName("fvLightPosition3", Varptr(fvLightPosition3)[0], 3)
        services.setPixelShaderConstantFromName("fvLightPosition4", Varptr(fvLightPosition4)[0], 3)
        
        services.setPixelShaderConstantFromName("fvAmbient", Varptr(fvAmbientColor)[0], 4)
        services.setPixelShaderConstantFromName("fvLight1Color", Varptr(fvLightColor1)[0], 4)
        services.setPixelShaderConstantFromName("fvLight2Color", Varptr(fvLightColor2)[0], 4)
        services.setPixelShaderConstantFromName("fvLight3Color", Varptr(fvLightColor3)[0], 4)
        services.setPixelShaderConstantFromName("fvLight4Color", Varptr(fvLightColor4)[0], 4)
        
        services.setPixelShaderConstantFromName("fSpecularPower", Varptr(fSpecularPower), 1)
        services.setPixelShaderConstantFromName("fSpecularStrength", Varptr(fSpecularStrength), 1)
        services.setPixelShaderConstantFromName("fBumpStrength", Varptr(fBumpStrength), 1)
    EndMethod

    ' we must override the generate function in order for instantiation to work properly
    Function generate:IShaderConstantSetCallBack()
        Return New MyShaderCallBack
    EndFunction
EndType
Local gpu:IGPUProgrammingServices = gIrrlichtDriver.getGPUProgrammingServices()
Local newMaterialType1:Int = 0

If (gpu)
    Local mc:IShaderConstantSetCallBack = ..
        IShaderConstantSetCallBack.Create(MyShaderCallback.generate)

        newMaterialType1 = gpu.addHighLevelShaderMaterialFromFilesNoGeometryShaders( ..
            "./Media/Shader/animNormal.vert", "vertexMain", EVST_VS_1_1, ..
            "./Media/Shader/animNormal.frag", "pixelMain", EPST_PS_1_1, ..
            mc, EMT_SOLID)
    mc.drop()
EndIf

newMaterialType1 is always -1. The Lighting is completely vertex-based (as opposed to beeing pixel-based as it should), and most textures have a awesome (well, actually not so awesome...) blue tint and/or other weird texture errors. Of course, I dont get any normal mapping effect whatsoever wink

Any thoughts?

So long,
Kernle

Re: Working with shaders

greetings!  could you whip up a quick running example?