I am lucky enough to own the shader pack and trying to learn so as I don't just copy code from it
using this example online [href]https://en.wikipedia.org/wiki/Blinn–Phong_reflection_model[/href]
I converted to
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "shinyness" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 60, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
obj=LoadObject("zombie.fbx")
img=loadimage("zombie.png")
SetObjectImage(obj,img,0)
SetObjectPosition(obj,0,0,0)
shininess#=16.0
createShader()
shader=LoadShader( "phong.vs","phong.ps" )
SetObjectShader(obj,shader)
SetShaderConstantByName(shader,"shininess",shininess#,0,0,0)
do
sync()
loop
function createShader()
file = OpenToWrite("phong.vs")
WriteLine(file,"attribute vec3 inputPosition;")
WriteLine(file,"attribute vec2 inputTexCoord;")
WriteLine(file,"attribute vec3 inputNormal;")
WriteLine(file,"varying mat4 agk_Proj, agk_View, agk_WorldNormal;")
WriteLine(file,"varying vec3 normalInterp;")
WriteLine(file,"varying vec3 vertPos;")
WriteLine(file,"void main() {")
WriteLine(file," gl_Position = agk_Proj * agk_View * vec4(inputPosition, 1.0);")
WriteLine(file," vec4 vertPos4 = agk_View * vec4(inputPosition, 1.0);")
WriteLine(file," vertPos = vec3(vertPos4) / vertPos4.w;")
WriteLine(file," normalInterp = vec3(agk_WorldNormal * vec4(inputNormal, 0.0));")
WriteLine(file,"}")
CloseFile(file)
//pixel shader
file = OpenToWrite("phong.ps")
WriteLine(file,"precision mediump float;")
WriteLine(file,"varying vec3 normalInterp;")
WriteLine(file,"varying vec3 vertPos;")
WriteLine(file,"uniform int mode;")
WriteLine(file,"const vec3 lightPos = vec3(1.0, 1.0, 1.0);")
WriteLine(file,"const vec3 lightColor = vec3(1.0, 1.0, 1.0);")
WriteLine(file,"const float lightPower = 40.0;")
WriteLine(file,"const vec3 ambientColor = vec3(0.1, 0.0, 0.0);")
WriteLine(file,"const vec3 diffuseColor = vec3(0.5, 0.0, 0.0);")
WriteLine(file,"const vec3 specColor = vec3(1.0, 1.0, 1.0);")
//WriteLine(file,"const float shininess = 16.0;")
WriteLine(file,"uniform float shininess;")
WriteLine(file,"const float screenGamma = 2.2; // Assume the monitor is calibrated to the sRGB color space")
WriteLine(file,"void main() {")
WriteLine(file," vec3 normal = normalize(normalInterp);")
WriteLine(file," vec3 lightDir = lightPos - vertPos;")
WriteLine(file," float distance = length(lightDir);")
WriteLine(file," distance = distance * distance;")
WriteLine(file," lightDir = normalize(lightDir);")
WriteLine(file," float lambertian = max(dot(lightDir, normal), 0.0);")
WriteLine(file," float specular = 0.0;")
WriteLine(file," if (lambertian > 0.0) {")
WriteLine(file," vec3 viewDir = normalize(-vertPos);")
WriteLine(file," // this is blinn phong")
WriteLine(file," vec3 halfDir = normalize(lightDir + viewDir);")
WriteLine(file," float specAngle = max(dot(halfDir, normal), 0.0);")
WriteLine(file," specular = pow(specAngle, shininess);")
WriteLine(file," // this is phong (for comparison)")
WriteLine(file," if (mode == 2) {")
WriteLine(file," vec3 reflectDir = reflect(-lightDir, normal);")
WriteLine(file," specAngle = max(dot(reflectDir, viewDir), 0.0);")
WriteLine(file," // note that the exponent is different here")
WriteLine(file," specular = pow(specAngle, shininess/4.0);")
WriteLine(file," }")
WriteLine(file," }")
WriteLine(file," vec3 colorLinear = ambientColor +")
WriteLine(file," diffuseColor * lambertian * lightColor * lightPower / distance +")
WriteLine(file," specColor * specular * lightColor * lightPower / distance;")
WriteLine(file," // apply gamma correction (assume ambientColor, diffuseColor and specColor")
WriteLine(file," // have been linearized, i.e. have no gamma correction in them)")
WriteLine(file," vec3 colorGammaCorrected = pow(colorLinear, vec3(1.0 / screenGamma));")
WriteLine(file," // use the gamma corrected color in the fragment")
WriteLine(file," gl_FragColor = vec4(colorGammaCorrected, 1.0);")
WriteLine(file,"}")
CloseFile(file)
endfunction
I suspect the problem is with these variables mat4 agk_Proj, agk_View, agk_WorldNormal; which I changed from projection * modelview and normalMat
I just get total blackness. There may be commands missing that are compulsory aswell any ideas would be greatly appreciated.
And raven that looks great im going to have to try that next