Topic: Working with shaders

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

Re: Working with shaders

greetings!  could you whip up a quick running example?