The lights are set to change with the space key atm
A quick explanation there are 4 textures the first one completely colors the traffic light
the second texture is just the green color where it should be mapped on the texture
with the rest of it transparent the third is orange ……etc etc
// show all errors
SetErrorMode(2)
#constant screenWidth=1920
#constant screenHeight=1080
SetWindowSize(screenWidth,screenHeight,0)
Setvirtualresolution(screenWidth,screenHeight)
// set variables for camera's starting position
lightID=1
SetCameraPosition(1,0,100,-250)
SetFogMode( 1 )
SetFogColor(10,10,10)
SetFogRange(6,16)
//loadObject(lightID,"trafficLights.obj")
loadObject(lightID,"TLIGHTS2.obj")
SetObjectScale(lightID,10,10,10)
createShader()
loadImage(1,"TLIGHTS2.png") //the complete normal texture
loadImage(2,"TLIGHTS2GREEN.png")
loadImage(3,"TLIGHTS2ORANGE.png")
loadImage(4,"TLIGHTS2RED.png")
SetObjectImage(lightID,1,0)
SetObjectImage(lightID,2,1)
SetObjectImage(lightID,3,2)
SetObjectImage(lightID,4,3)
//createShader()
Shader=LoadShader( "neon.vs","neon.ps" )
SetObjectShader(lightID,Shader)
stage#=1.0
lightint#=1.0
lightson=1
SetShaderConstantByName(Shader,"lightint",lightint#,0.0,0.0,0.0)
SetShaderConstantByName(Shader,"lightson",lightson*1.0,0.0,0.0,0.0)
SetShaderConstantByName(Shader,"stage",1.0,0.0,0.0,0.0)
do
time#=timer()
r#=7-time#
g#=7-time#
b#=7-time#
RotateObjectLocalY(lightId,.5)
//SetShaderConstantByName(Shader,"pointPos",1,1,1,1)
//SetShaderConstantByName(Shader,"myColor",r#,g#,b#,0.02) //red green blue factor
if GetRawKeyState(49)=1
lightint#=lightint#-0.01
if lightint#<0.0 then lightint#=0.0
SetShaderConstantByName(Shader,"lightint",lightint#,0.0,0.0,0.0)
endif
if GetRawKeyState(50)=1
lightint#=lightint#+0.01
if lightint#>1.0 then lightint#=1.0
SetShaderConstantByName(Shader,"lightint",lightint#,0.0,0.0,0.0)
endif
if GetRawKeypressed(76)=1
lightson=1-lightson
SetShaderConstantByName(Shader,"lightson",lightson*1.0,0.0,0.0,0.0)
endif
if GetRawKeypressed(32)=1
if stage#<3
inc stage#
else
stage#=1.0
endif
SetShaderConstantByName(Shader,"stage",stage#,0.0,0.0,0.0)
endif
Print("Press space to change the light color") //the colors
print("Press L to toggle lights working or not")
print("Use 1 and 2 to increase/decrease light")
print ("Current lighting "+str(lightint#))
sync()
loop
function createShader()
file = OpenToWrite("neon.vs")
WriteLine(file,"attribute highp vec3 position;")
WriteLine(file,"attribute mediump vec3 normal;")
WriteLine(file,"attribute mediump vec2 uv;")
WriteLine(file,"varying highp vec3 posVarying;")
WriteLine(file,"varying mediump vec3 normalVarying;")
WriteLine(file,"varying mediump vec2 uvVarying;")
WriteLine(file,"varying mediump vec3 lightVarying;")
WriteLine(file,"uniform highp mat3 agk_WorldNormal;")
WriteLine(file,"uniform highp mat4 agk_World;")
WriteLine(file,"uniform highp mat4 agk_ViewProj;")
WriteLine(file,"uniform mediump vec4 uvBounds0;")
WriteLine(file,"mediump vec3 GetVSLighting( mediump vec3 normal, highp vec3 pos );")
WriteLine(file,"void main()")
WriteLine(file,"{")
WriteLine(file," uvVarying = uv * uvBounds0.xy + uvBounds0.zw;")
WriteLine(file," highp vec4 pos = agk_World * vec4(position,1.0);")
WriteLine(file," gl_Position = agk_ViewProj * pos;")
WriteLine(file," mediump vec3 norm = normalize(agk_WorldNormal * normal);")
WriteLine(file," posVarying = pos.xyz;")
WriteLine(file," normalVarying = norm;")
WriteLine(file," lightVarying = GetVSLighting( norm, posVarying );")
WriteLine(file,"}")
CloseFile(file)
//pixel shader
file = OpenToWrite("neon.ps")
WriteLine(file,"uniform sampler2D texture0;")
WriteLine(file,"uniform sampler2D texture1;")
WriteLine(file,"uniform sampler2D texture2;")
WriteLine(file,"uniform sampler2D texture3;")
WriteLine(file,"varying highp vec3 posVarying;")
WriteLine(file,"varying mediump vec3 normalVarying;")
WriteLine(file,"varying mediump vec2 uvVarying;")
WriteLine(file,"varying mediump vec3 lightVarying;")
WriteLine(file,"mediump vec3 GetPSLighting( mediump vec3 normal, highp vec3 pos );")
WriteLine(file,"mediump vec3 ApplyFog( mediump vec3 color, highp vec3 pointPos );")
WriteLine(file,"uniform vec4 myColor;")
WriteLine(file,"uniform mediump vec4 agk_MeshDiffuse;")
WriteLine(file,"mediump vec4 colorResult;")
WriteLine(file,"uniform float lightint;")
WriteLine(file,"uniform float lightson;")
WriteLine(file,"uniform float stage;")
WriteLine(file,"void main()")
WriteLine(file,"{")
WriteLine(file," mediump vec3 norm = normalize(normalVarying);")
WriteLine(file," mediump vec3 light = lightVarying + GetPSLighting( norm, posVarying );")
WriteLine(file," vec4 colorA = texture2D(texture0, uvVarying);")
WriteLine(file," vec4 colorB;")
WriteLine(file," if (stage < 1.1) {")
WriteLine(file," colorB = texture2D(texture1, uvVarying);")
WriteLine(file," } else {")
WriteLine(file," if (stage < 2.1) {")
WriteLine(file," colorB = texture2D(texture2, uvVarying);")
WriteLine(file," } else {")
WriteLine(file," if (stage < 3.1) {")
WriteLine(file," colorB = texture2D(texture3, uvVarying);")
WriteLine(file," }")
WriteLine(file," }")
WriteLine(file," }")
WriteLine(file," if (lightson < 1.0) {")
WriteLine(file," colorResult = vec4(colorA * vec4(light,1.0))*lightint;")
WriteLine(file," } else {")
WriteLine(file," if (colorB.a > 0.0) {")
WriteLine(file," colorResult = vec4 ((colorA * vec4(light,1.0))*lightint) + (colorB*colorB.a);")
WriteLine(file," } else {")
WriteLine(file," colorResult =vec4(colorA * vec4(light,1.0))*lightint;")
WriteLine(file," }")
WriteLine(file," }")
WriteLine(file,"gl_FragColor = colorResult;")
WriteLine(file,"}")
CloseFile(file)
endfunction
An example project with media can be found here
Source attached here