miniB3D +! Would anyone be interested?

Archives Forums/General Discussion/miniB3D +! Would anyone be interested?

BLaBZ(Posted 2014) [#1]
Hello all,

After reading a significant amount of responses as to what would make blitzMAX awesome again I'm seeing that a lot of people think a modern 3d engine would do the trick, but I think miniB3D just needs a update.

MiniB3D is stable but I believe it has 3 primary shortcomings.
1. Modern Rendering
2. Particle Systems
3. Physics Engine

I've already heavily modified my version of miniB3D to support these but I'd like to offer something more developer friendly if enough people are interested.

My solution is to replace the RenderWorld() function and add a function before you're main game loop(CreateWorld()). You would just need to import an additional module on top of minib3d, without replacing it.

The graphics additions would include
- True Multi-Sampled Anti-Aliasing
- Normal Mapping
- Shadows
- Bloom
- Screen Space Ambient Occlusion
- High Dynamic Range (HDR)
- Custom Shader Support

Let me know your thoughts and if you think this is something worth producing! :)

Here's a picture what these changes can do for miniB3D



Banshee(Posted 2014) [#2]
I am your acolyte. Wherever you go I will worship you.

Your wish is my command.


Banshee(Posted 2014) [#3]
seriously. Can I have it now?


KronosUK(Posted 2014) [#4]
I'd be interested and I think Chapman7 would too as we indicated in your other thread.

I've been trying on and off to add a shader module to standard minib3d without success.

Thats all I ever wanted Minib3d with shaders and shadowmapping support, postprocessing effects doesn't hurt either.

Is there much of a performance hit with the current effects particularly shadows?


*(Posted 2014) [#5]
As long as it supports old hardware im in :)


Banshee(Posted 2014) [#6]
When you say old hardware, which decade are you referring too - as I believe I am correct in saying that MiniB3D is OpenGL2?


MadJack(Posted 2014) [#7]
Rendering speed is paramount for me - the ability to have lots of entities onscreen both animated/moving and static.

My understanding this would require features like auto LOD switching, occlusion and surface batching - but I'm not an expert...


Banshee(Posted 2014) [#8]

My understanding this would require features like auto LOD switching, occlusion and surface batching - but I'm not an expert...

Well auto LOD switching is pretty easy to code, but I don't think MiniB3D does any surface batching.

It's fairly easy to make your world combine it's own surfaces though, I've done that in MiniB3D before and it wasn't much work - but it's not as easy to do with dynamic objects like your tanks though.

I assume MiniB3D does occlusion by entity hierarchy and bounding boxes in which case you could likely speed up your game fairly easily by slaving tanks in each region off a parent with a bounding box and switching parents as the tanks move region. Or perhaps a squad level parent - depending upon how your AI and game levels are structured.

Perhaps a discussion for elsewhere is where your game loses most of it's time: In the tanks, the AI, or the track trails? There's likely a way to optimise your object hierarchy or creation technique for performance.


dynaman(Posted 2014) [#9]
Does your version handle the problem with rotation that core minib3d has?


*(Posted 2014) [#10]
Yeah that's a good question as we would need full rotation not the fps rotation that minib3d has, iirc Warner fixed it years ago but it was never implemented into mainstream minib3d


degac(Posted 2014) [#11]

Let me know your thoughts and if you think this is something worth producing! :)


Quick question: do you want to create a 3d-module for BlitzMax and sell it? I'm counting the money

I would like to know/see in it:
1 - what support for 3d object (what format, and in any case a ready-to-use solution to convert it+texture !)
2 - a built in basic collision system (like the current one I think box-2-box, box-2-sphere, box-2-plane)
3 - physic support (a must have nowadays!)
4 - keep the 3d engine 'light': no LUA support, no triggers, no complication in design
5 - post processing: I think there are/was experiment in the past; a quad with some shaders applied to it to simulate defocus and so on.

of course shader supports are welcome!

One suggestion: you could create (time and resource permitting) 2 different 'target engine' with same syntax; a low hardware engine and an high one. Without 'compromises' so everyone should be happy (!) and you can target your game better (or choose to make 2 version for old and new generation)


Banshee(Posted 2014) [#12]
what support for 3d object (what format, and in any case a ready-to-use solution to convert it+texture !)

I bought Ultimate Unwrap Pro and it was the best investment I've ever made for my art pipeline. It converts so many object formats and I've only ever found an error once and that was on a model that had too many bone weights per vertice - and Ultimate Unwrap Pro has a reducer/normaliser for that task but it didn't work as well as I had hoped on the model in question - which is hardly a fault!


KronosUK(Posted 2014) [#13]
From what Blabz has said he's only creating a graphical addon to existing minib3d not changing the core functionality of it or creating a new engine. The low hardware option is minib3d is as it is at the moment, the higher hardware option will be the one with the addon.

I think he's been pretty clear what he's offering, an addon for minib3d with the features he mentioned, nothing more and nothing less.


Who was John Galt?(Posted 2014) [#14]
As long as it supports old hardware im in :)
IMO, trying to support too wide a range of hardware, chronologically speaking, is a recipe for disaster.

Maybe two teams could create different forks, one for the old, one for the new.


Ian Thompson(Posted 2014) [#15]
I'd rather see some of these features on MonkeyX TBH. I can't see me moving back to BM. and loose multi platform support now.


MadJack(Posted 2014) [#16]
So the collision engine in minib3d is pretty much sorted?

Really just needs to replicate what was on hand in Blitz3d for me at least.


Banshee(Posted 2014) [#17]
So the collision engine in minib3d is pretty much sorted?

I used to use LinePick and build my own collisions that way which was faultless, but I'm fairly sure it's got all the standard B3D style collisions too.


Who was John Galt?(Posted 2014) [#18]
Okay so now we have a proposed system with modern features that caters to modern and old PC hardware and the lowest common denominator mobile hardware, for Monkey and Max... this is how it goes.

Can I suggest we:
a) Identify those interested in contributing.
b) Identify what languages/hardware they are interested in targeting.
c) Split them up into groups with a common interest- or find a compromise.
d) Start by investigating any goals that are common between teams- e.g. collision engine could be one. This code could be shared among teams.
e) Teams go off and work on their own versions, but discuss how this could all eventually fit into one configurable code base (but not necessarily to begin with.)


Banshee(Posted 2014) [#19]
I don't think that's what BLaBZ is suggesting John. He's developed MiniB3D to support quite a lot of new features for his RTS Creator ( http://steamcommunity.com/sharedfiles/filedetails/?id=223060487 ) and he is suggesting that he separates the engine from his game and rehashes it a little to make it easy to use and then releases that.

I can't speak for him, but I would be surprised if he wants to develop additional engine features or languages or build targets: When he's focused on is getting his game out on Steam.

I for one would love to get my hands on his engine.

Oh dear. That didn't read well.


Brucey(Posted 2014) [#20]
I'm interested in an up-to-date MiniB3D for BlitzMax.
Shader integration would help, I believe, in supporting OpenGL ES.


Chapman7(Posted 2014) [#21]

I'm interested in an up-to-date MiniB3D for BlitzMax.
Shader integration would help, I believe, in supporting OpenGL ES.



Why on desktops?


Hardcoal(Posted 2014) [#22]
You got my 100$ if ull make it!

Concentrate on the physical engine and like in xors the physical body is mixed with the displayed body so when you scale an entity the body is scaled as well.
Etc... In general.. Xors did many things very simple and correct
Beside the wimping side of it all.


BLaBZ(Posted 2014) [#23]
I don't want to modify or update minib3d, I want to create an add-on that provides modern features, like an extension. Because of this the backwards compatibility would still be preserved. :)


Banshee(Posted 2014) [#24]
I'm down with that and want it right now!

I'll hire you hookers if needs be.


Brucey(Posted 2014) [#25]
Why on desktops?

Well, not, obviously. I'm looking at things like the Raspberry Pi and iOS, which both use OpenGL ES 2.


BLaBZ(Posted 2014) [#26]
@Banshee LoL, thanks for your comment on steam :D

@Brucey, this won't be OpenGL ES as I'm just adding functions to the existing minib3d.


*(Posted 2014) [#27]
Excellent stuff when can we get a demo of the system :)


GaryV(Posted 2014) [#28]
BLaBZ: Very good looking game.


Hotshot2005(Posted 2014) [#29]
Yeah, I am looking forward buying your RTS Creator on steam!

miniB3D is sound interesting and looking forward to what you do with it :)


BLaBZ(Posted 2014) [#30]
OK! Here's the first release, I'm quite happy with it :)
It's a completely non-invasive approach to giving minib3d modern graphics. I plan to integrate the particle system and physics next, let me know if you guys notice any bugs.

Add the following module to blitzmax:

http://infotread.com/downloads/blabz.mod.zip

Here's some sample code:
format_code('
SuperStrict

Import sidesign.minib3d
Import blabz.minib3dplus

Graphics3D(1024,768,16,2)
CreateWorld()

EnableAntiAliasing()
EnableBloom()
EnableShadows()
EnableAmbientOcclusion()

Local cam:TCamera = CreateCamera()
PositionEntity(cam,5,5,-5)

Local shad:TCamera = CreateCamera()
PositionEntity(shad,-20,20,-20)
CameraShadow(shad,True)


Local light:TLight = CreateLight()
PositionEntity(light,-5,5,-5)

Local cube:TMesh = CreateCube()
PositionEntity(cube,0,0,10)
EntityColor(cube,255,0,0)
PointEntity(cam,cube)
PointEntity(shad,cube)


Local ground:TMesh = CreateCube()
PositionEntity(ground,0,-5,0)
ScaleEntity(ground,20,0.5,20)

Local wall:TMesh = CreateCube()
PositionEntity(wall,0,0,20)
ScaleEntity(wall,20,10,0.5)
EntityColor(wall,0,0,255)


While Not KeyHit(KEY_ESCAPE)

TurnEntity(cube,0.1,0.1,0.1)

RenderWorldX()

BeginMax2d()
DrawText("TEST 123",0,0)
EndMax2d()

Flip
Cls

Wend
')

Here's a list of the new commands.
format_code('
CreateWorld()
EnableAntiAliasing()
DisableAntiAliasing()
AntiAliasingActive:byte()
EnableBloom()
DisableBloom()
BloomActive:byte()
EnableShadows()
DisableShadows()
ShadowsActive:byte()
EnableAmbientOcclusion()
DisableAmbientOcclusion()
AmbientOcclusionActive:byte()
EnableHDR()
DisableHDR()
HDRActive:byte()
HDRExposure(Val:float)
CameraShadow(Camera:TCamera,Enabled:byte)
MeshADS(mesh:TMesh,ambient:float,diffuse:float,specular:float)
LightADS(light:TLight,ambient:float,diffuse:float,specular:float,intensity:float)
LightIntensity:float(light:TLight)
Ambient:float(Ent:TEntity)
Diffuse:float(Ent:TEntity)
Specular:float(Ent:TEntity)
RenderWorldX()
')

The Result:



Hotshot2005(Posted 2014) [#31]
I put in blitzmax mod and rebuild it then I get the error saying
gl/GLee.h: No such file or directory

how do I fixed that?


BLaBZ(Posted 2014) [#32]
You need the latest OpenGL and Glew mod to support newer OpenGL commands, overwrite those mods with the below link:

http://infotread.com/downloads/pub.mod.zip


Hotshot2005(Posted 2014) [#33]
thanks and I have delete the pub.mod then put your pub.mod in then rebuild the mod but I dont understand this one

[img]

[/img]

what is this telling me?


Chapman7(Posted 2014) [#34]
Hotshot2005 do you have the module 'pub.stdc'?

Also BLaBZ, how exactly did you update Glew mod?


Hotshot2005(Posted 2014) [#35]
no, I dont have that :(

where can I find it?


kmac(Posted 2014) [#36]
You shouldn't have deleted pub.mod, which contains about a dozen folders. The Blabz pub.mod.zip only replaced two of those.

Reinstall? Check your Recycle Bin?


Hotshot2005(Posted 2014) [#37]
well, the old pub.mod doesnt have pub.stdc!

I guess I going have restalled it?


BLaBZ(Posted 2014) [#38]
@Chapman7, this link explains how to update glew and opengl

http://www.blitzbasic.com/Community/posts.php?topic=90520

@Hotshot2005, you may need to reinstall blitzmax then reimport minib3d, blabz.minib3dplus, and the pub.mod

Has anyone else been able to run the sample?


Chapman7(Posted 2014) [#39]
One more Q BLaBZ - When I run minib3d hardware info with the old/regular pub.glew and pub.opengl, I get this:

format_codebox('
OpenGL Extensions:
GL_AMD_multi_draw_indirect
GL_AMD_seamless_cubemap_per_texture
GL_ARB_arrays_of_arrays
GL_ARB_base_instance
GL_ARB_bindless_texture
GL_ARB_blend_func_extended
GL_ARB_buffer_storage
GL_ARB_clear_buffer_object
GL_ARB_clear_texture
GL_ARB_color_buffer_float
GL_ARB_compatibility
GL_ARB_compressed_texture_pixel_storage
GL_ARB_conservative_depth
GL_ARB_compute_shader
GL_ARB_compute_variable_group_size
GL_ARB_copy_buffer
GL_ARB_copy_image
GL_ARB_debug_output
GL_ARB_depth_buffer_float
GL_ARB_depth_clamp
GL_ARB_depth_texture
GL_ARB_draw_buffers
GL_ARB_draw_buffers_blend
GL_ARB_draw_indirect
GL_ARB_draw_elements_base_vertex
GL_ARB_draw_instanced
GL_ARB_enhanced_layouts
GL_ARB_ES2_compatibility
GL_ARB_ES3_compatibility
GL_ARB_explicit_attrib_location
GL_ARB_explicit_uniform_location
GL_ARB_fragment_coord_conventions
GL_ARB_fragment_layer_viewport
GL_ARB_fragment_program
GL_ARB_fragment_program_shadow
GL_ARB_fragment_shader
GL_ARB_framebuffer_no_attachments
GL_ARB_framebuffer_object
GL_ARB_framebuffer_sRGB
GL_ARB_geometry_shader4
GL_ARB_get_program_binary
GL_ARB_gpu_shader5
GL_ARB_gpu_shader_fp64
GL_ARB_half_float_pixel
GL_ARB_half_float_vertex
GL_ARB_imaging
GL_ARB_indirect_parameters
GL_ARB_instanced_arrays
GL_ARB_internalformat_query
GL_ARB_internalformat_query2
GL_ARB_invalidate_subdata
GL_ARB_map_buffer_alignment
GL_ARB_map_buffer_range
GL_ARB_multi_bind
GL_ARB_multi_draw_indirect
GL_ARB_multisample
GL_ARB_multitexture
GL_ARB_occlusion_query
GL_ARB_occlusion_query2
GL_ARB_pixel_buffer_object
GL_ARB_point_parameters
GL_ARB_point_sprite
GL_ARB_program_interface_query
GL_ARB_provoking_vertex
GL_ARB_robust_buffer_access_behavior
GL_ARB_robustness
GL_ARB_sample_shading
GL_ARB_sampler_objects
GL_ARB_seamless_cube_map
GL_ARB_seamless_cubemap_per_texture
GL_ARB_separate_shader_objects
GL_ARB_shader_atomic_counters
GL_ARB_shader_bit_encoding
GL_ARB_shader_draw_parameters
GL_ARB_shader_group_vote
GL_ARB_shader_image_load_store
GL_ARB_shader_image_size
GL_ARB_shader_objects
GL_ARB_shader_precision
GL_ARB_query_buffer_object
GL_ARB_shader_storage_buffer_object
GL_ARB_shader_subroutine
GL_ARB_shader_texture_lod
GL_ARB_shading_language_100
GL_ARB_shading_language_420pack
GL_ARB_shading_language_include
GL_ARB_shading_language_packing
GL_ARB_shadow
GL_ARB_stencil_texturing
GL_ARB_sync
GL_ARB_tessellation_shader
GL_ARB_texture_border_clamp
GL_ARB_texture_buffer_object
GL_ARB_texture_buffer_object_rgb32
GL_ARB_texture_buffer_range
GL_ARB_texture_compression
GL_ARB_texture_compression_bptc
GL_ARB_texture_compression_rgtc
GL_ARB_texture_cube_map
GL_ARB_texture_cube_map_array
GL_ARB_texture_env_add
GL_ARB_texture_env_combine
GL_ARB_texture_env_crossbar
GL_ARB_texture_env_dot3
GL_ARB_texture_float
GL_ARB_texture_gather
GL_ARB_texture_mirror_clamp_to_edge
GL_ARB_texture_mirrored_repeat
GL_ARB_texture_multisample
GL_ARB_texture_non_power_of_two
GL_ARB_texture_query_levels
GL_ARB_texture_query_lod
GL_ARB_texture_rectangle
GL_ARB_texture_rg
GL_ARB_texture_rgb10_a2ui
GL_ARB_texture_stencil8
GL_ARB_texture_storage
GL_ARB_texture_storage_multisample
GL_ARB_texture_swizzle
GL_ARB_texture_view
GL_ARB_timer_query
GL_ARB_transform_feedback2
GL_ARB_transform_feedback3
GL_ARB_transform_feedback_instanced
GL_ARB_transpose_matrix
GL_ARB_uniform_buffer_object
GL_ARB_vertex_array_bgra
GL_ARB_vertex_array_object
GL_ARB_vertex_attrib_64bit
GL_ARB_vertex_attrib_binding
GL_ARB_vertex_buffer_object
GL_ARB_vertex_program
GL_ARB_vertex_shader
GL_ARB_vertex_type_10f_11f_11f_rev
GL_ARB_vertex_type_2_10_10_10_rev
GL_ARB_viewport_array
GL_ARB_window_pos
GL_ATI_draw_buffers
GL_ATI_texture_float
GL_ATI_texture_mirror_once
GL_S3_s3tc
GL_EXT_texture_env_add
GL_EXT_abgr
GL_EXT_bgra
GL_EXT_bindable_uniform
GL_EXT_blend_color
GL_EXT_blend_equation_separate
GL_EXT_blend_func_separate
GL_EXT_blend_minmax
GL_EXT_blend_subtract
GL_EXT_compiled_vertex_array
GL_EXT_Cg_shader
GL_EXT_depth_bounds_test
GL_EXT_direct_state_access
GL_EXT_draw_buffers2
GL_EXT_draw_instanced
GL_EXT_draw_range_elements
GL_EXT_fog_coord
GL_EXT_framebuffer_blit
GL_EXT_framebuffer_multisample
GL_EXTX_framebuffer_mixed_formats
GL_EXT_framebuffer_multisample_blit_scaled
GL_EXT_framebuffer_object
GL_EXT_framebuffer_sRGB
GL_EXT_geometry_shader4
GL_EXT_gpu_program_parameters
GL_EXT_gpu_shader4
GL_EXT_multi_draw_arrays
GL_EXT_packed_depth_stencil
GL_EXT_packed_float
GL_EXT_packed_pixels
GL_EXT_pixel_buffer_object
GL_EXT_point_parameters
GL_EXT_provoking_vertex
GL_EXT_rescale_normal
GL_EXT_secondary_color
GL_EXT_separate_shader_objects
GL_EXT_separate_specular_color
GL_EXT_shader_integer_mix
GL_EXT_shader_image_load_store
GL_EXT_shadow_funcs
GL_EXT_stencil_two_side
GL_EXT_stencil_wrap
GL_EXT_texture3D
GL_EXT_texture_array
GL_EXT_texture_buffer_object
GL_EXT_texture_compression_dxt1
GL_EXT_texture_compression_latc
GL_EXT_texture_compression_rgtc
GL_EXT_texture_compression_s3tc
GL_EXT_texture_cube_map
GL_EXT_texture_edge_clamp
GL_EXT_texture_env_combine
GL_EXT_texture_env_dot3
GL_EXT_texture_filter_anisotropic
GL_EXT_texture_integer
GL_EXT_texture_lod
GL_EXT_texture_lod_bias
GL_EXT_texture_mirror_clamp
GL_EXT_texture_object
GL_EXT_texture_shared_exponent
GL_EXT_texture_sRGB
GL_EXT_texture_sRGB_decode
GL_EXT_texture_storage
GL_EXT_texture_swizzle
GL_EXT_timer_query
GL_EXT_transform_feedback2
GL_EXT_vertex_array
GL_EXT_vertex_array_bgra
GL_EXT_vertex_attrib_64bit
GL_EXT_import_sync_object
GL_IBM_rasterpos_clip
GL_IBM_texture_mirrored_repeat
GL_KHR_debug
GL_KTX_buffer_region
GL_NV_bindless_multi_draw_indirect
GL_NV_bindless_texture
GL_NV_blend_equation_advanced
GL_NV_blend_square
GL_NV_compute_program5
GL_NV_conditional_render
GL_NV_copy_depth_to_color
GL_NV_copy_image
GL_NV_depth_buffer_float
GL_NV_depth_clamp
GL_NV_draw_texture
GL_NV_ES1_1_compatibility
GL_NV_explicit_multisample
GL_NV_fence
GL_NV_float_buffer
GL_NV_fog_distance
GL_NV_fragment_program
GL_NV_fragment_program_option
GL_NV_fragment_program2
GL_NV_framebuffer_multisample_coverage
GL_NV_geometry_shader4
GL_NV_gpu_program4
GL_NV_gpu_program4_1
GL_NV_gpu_program5
GL_NV_gpu_program5_mem_extended
GL_NV_gpu_program_fp64
GL_NV_gpu_shader5
GL_NV_half_float
GL_NV_light_max_exponent
GL_NV_multisample_coverage
GL_NV_multisample_filter_hint
GL_NV_occlusion_query
GL_NV_packed_depth_stencil
GL_NV_parameter_buffer_object
GL_NV_parameter_buffer_object2
GL_NV_path_rendering
GL_NV_pixel_data_range
GL_NV_point_sprite
GL_NV_primitive_restart
GL_NV_register_combiners
GL_NV_register_combiners2
GL_NV_shader_atomic_counters
GL_NV_shader_atomic_float
GL_NV_shader_buffer_load
GL_NV_shader_storage_buffer_object
GL_ARB_sparse_texture
GL_NV_texgen_reflection
GL_NV_texture_barrier
GL_NV_texture_compression_vtc
GL_NV_texture_env_combine4
GL_NV_texture_expand_normal
GL_NV_texture_multisample
GL_NV_texture_rectangle
GL_NV_texture_shader
GL_NV_texture_shader2
GL_NV_texture_shader3
GL_NV_transform_feedback
GL_NV_transform_feedback2
GL_NV_vertex_array_range
GL_NV_vertex_array_range2
GL_NV_vertex_attrib_integer_64bit
GL_NV_vertex_buffer_unified_memory
GL_NV_vertex_program
GL_NV_vertex_program1_1
GL_NV_vertex_program2
GL_NV_vertex_program2_option
GL_NV_vertex_program3
GL_NVX_conditional_render
GL_NVX_gpu_memory_info
GL_NVX_nvenc_interop
GL_NV_shader_thread_group
GL_NV_shader_thread_shuffle
GL_SGIS_generate_mipmap
GL_SGIS_texture_lod
GL_SGIX_depth_texture
GL_SGIX_shadow
GL_SUN_slice_accum
GL_WIN_swap_hint
WGL_EXT_swap_control
')

What exactly are the 'OpenGL Extensions'? Because in the standard glew2bmx, these would be caught by 'Else If n.length And isdigit(n[0]) And n<>"1"' and they wouldn't be added.

However you posted code that removed the 'And n<>"1"' so it becomes added to the output.

Why did the old glew2bmx exclude these and why did you change code to include them?


Hotshot2005(Posted 2014) [#40]
now I have restall it and I have latest version of BlitzMax 1.50 and then put your pub and your blabz.mod.zip then put in blitzmax of Mod

I rebuild it and put your sample code in.

Then I save it then I run it and I get the error saying

Cant find inferface for module 'sidesign.miniB3d'

Have you forgot put in the folder of blabz.mod?


Chapman7(Posted 2014) [#41]
You need minib3d. Download the latest version of it and put the module in your mod folder. It should look like this: 'blitzmax/mod/sidesign.mod/minib3d.mod'.

MiniB3D is the engine that Blabz's module, extends upon.


Banshee(Posted 2014) [#42]
I'm not going to be near my computer today, so I shall spend the day palpitating...


PhotonTom(Posted 2014) [#43]
Great work.
I think this requires a sticky :)


KronosUK(Posted 2014) [#44]
The demo works for me once i replaced the opengl and glew mod folders.

I get this output however.

Warning: resolving _glewInit by linking to _glewInit@0
Use --enable-stdcall-fixup to disable these warnings
Use --disable-stdcall-fixup to disable these fixups
Executing:blabztest.debug.exe
DebugLog:Shader Validation Succeeded
DebugLog:Shader Validation Succeeded
DebugLog:Shader Failed to Validate <-----this seems not to work
DebugLog:Shader Validation Succeeded
DebugLog:Shader Validation Succeeded
DebugLog:Shader Validation Succeeded

I tried adding animated b3d model to the scene but although its shadow appears the model itself doesn't.


Brucey(Posted 2014) [#45]
You need the latest OpenGL and Glew mod to support newer OpenGL commands

Are those backwards compatible?

If so, I'll put them here too : https://github.com/maxmods/pub.mod
... which has updates for lots of other modules too (jpeg, png, ogg, etc).

I prefer not to have to hunt around for things, that may not then be available at a later date.


Banshee(Posted 2014) [#46]
Well I found just enough time to get it set up and run the demo, looks great.

You mentioned customer shader support? Will that have animation support (ie: bone data passed to shader)? That would make me so happy I'd be grinning like a dope smoker.

EDIT: Did try swapping the cube mesh for a few .b3d files but ran into a MAV. I don't have time to debug right now but I'm not sure it's loading media. Can anyone confirm?


Hotshot2005(Posted 2014) [#47]
I have download iMiniB3D V0.54 then rebuild it then run it the program sample from BLaBZ but still get the error saying

compile error

cant find interface for module 'sigesign.minib3d'


degac(Posted 2014) [#48]
I installed on my dad computer (AMD Radeon 3000) BlitzMax 1.5+MinGw+Sidesign.minib3d+Blazbz.minib3dplus+pub.mod as indicated above.

format_code('

Warning: resolving _glewInit by linking to _glewInit@0
Use --enable-stdcall-fixup to disable these warnings
Use --disable-stdcall-fixup to disable these fixups
Executing:test1.debug.exe
DebugLog:Shader Validation Succeeded
DebugLog:Shader Validation Succeeded
DebugLog:Shader Validation Succeeded
DebugLog:Shader Validation Succeeded
DebugLog:Shader Validation Succeeded
DebugLog:Shader Validation Succeeded
')

MiniB3d examples work perfectly.
The above code shows only a black screen, with 'test 123' on the topleft of the screen.

I decided to change glew as indicated... too many errors. So I get back to previous version.

Whats' wrong?

@Hotshot2005: you need to download and install minib3d from here (the .mod folder)


Hotshot2005(Posted 2014) [#49]
thanks degac:)

Now I get another error saying cant find interface for module blabz.minib3dplus

* shaking head *

I hope that will be last one to fixed it lol


degac(Posted 2014) [#50]
This means you havent' installed BlabzMod (see [a Import sidesign.minib3d]his post[/a]

Then you should recompile all.


Hotshot2005(Posted 2014) [#51]
I am getting somewhere but error in code saying

Duplicate identifier 'CreateWorld' in modules 'pub.minib3dplus' and 'blabz.minib3dplus'

what does it mean?


PhotonTom(Posted 2014) [#52]
Would it not be easier to get your code combined into the official minib3d module? (https://github.com/si-design/minib3d)


Hotshot2005(Posted 2014) [#53]
I know what I did wrong...

The minib3dplus.mod was in pub.mod and so I take it outside of pub.mod folder then rebuild it and it worked! Thanks god for that! lol

It's looking good :)


Hotshot2005(Posted 2014) [#54]
The shader doesnt seem to be working :(

Building eh
Executing:eh.debug.exe
DebugLog:Shader Validation Succeeded
DebugLog:Shader Validation Succeeded
DebugLog:Shader Failed to Validate
DebugLog:Shader Validation Succeeded
DebugLog:Shader Validation Succeeded
DebugLog:Shader Validation Succeeded

Process complete

My graphics card is ATI 5800 1GB :)


BLaBZ(Posted 2014) [#55]
Hmm, the shader that renders MeshADS and shadows is failing to validate, I've updated the module to print the validation information to the debuglog, reimport the linked module and let me know what get's printed to the debug log.

http://infotread.com/downloads/blabz.mod2.zip


Steve Elliott(Posted 2014) [#56]
It seems the community is taking the baton and running with it...Looks a nice engine.


Hotshot2005(Posted 2014) [#57]
Building eh
Executing:eh.debug.exe
DebugLog:Shader Validation Succeeded
DebugLog:Shader Validation Succeeded
DebugLog:Shader Failed to Validate
DebugLog:Validation Error:
DebugLog:Shader Validation Succeeded
DebugLog:Shader Validation Succeeded
DebugLog:Shader Validation Succeeded

Process complete


BLaBZ(Posted 2014) [#58]
Ok that's not very useful, hmm, I'll have to try a few things on another computer.


Hotshot2005(Posted 2014) [#59]
you mean you want to know what PC Laptop I have?

2GHZ
4GB Ram
ATI 5870


Chapman7(Posted 2014) [#60]
He mean's he can't debug this issue knowing your specs, he will have to test it on other machines.

Just out of curiosity though, KronosUK, what video card do you use?

And BLaBz could it be the GLSL version their card supports?


BLaBZ(Posted 2014) [#61]
It's not the version of GLSL that the card supports but the way the card supports the version of GLSL. As weird as that sounds, it's one of the most finicky and frustrating aspects of GLSL programming.


Chapman7(Posted 2014) [#62]
Yeah I just learned that. I was like 'oh hurr durr, probably shadermodel stuff' - and went on to read about DirectX ShaderModel vs OpenGL GLSL


zoqfotpik(Posted 2014) [#63]
This looks great.

One idea for your RTS creator is to allow for different sorts of pseudorandom ground cover using perlin noise or the like.


degac(Posted 2014) [#64]
format_code('

Linking:test1.debug.exe
Warning: resolving _glewInit by linking to _glewInit@0
Use --enable-stdcall-fixup to disable these warnings
Use --disable-stdcall-fixup to disable these fixups
Executing:test1.debug.exe
DebugLog:Shader Validation Succeeded
DebugLog:Shader Validation Succeeded
DebugLog:Shader Validation Succeeded
DebugLog:Shader Validation Succeeded
DebugLog:Shader Validation Succeeded
DebugLog:Shader Validation Succeeded
')
Test with mod2: same results, black screen with 'test123' on the top left.
What other output I should find?
(dad' computer - Radeon3000)


KronosUK(Posted 2014) [#65]
same result as before with the new mod - no extra debuglogs

My gfx card is AMD RADEON HD 6800 series

I can run the demo in debug mode but when I build it as non debug it crashes.


Banshee(Posted 2014) [#66]
I got exactly the same issue when I replaced the cube with a .b3d file - but I'm at work now and can't check my card. I think it's a GeForce Ti 660 but not 100% sure. I'm going to have a proper play with it tonight.


degac(Posted 2014) [#67]
@Blabz
could you put on line a working example? So to check if there's wrong with the BlitzMax configuration or the hardware?

edit:

tested new mod on my computer (GPU: Radeon HD5700): same result, black screen, only 'test123' on video.


Banshee(Posted 2014) [#68]
Okay I'm a bit confused. I can load some b3d files but not others. It seems that simple things like plants are loading, but more complicated models like buildings with child meshes and the like, or animated characters, they just throw an MAV.

EDIT: It seems to be that when a mesh does happen to load it does not get any textures. I took out the EntityColor to allow the original texture to remain, and I just get a plain white mesh.


BLaBZ(Posted 2014) [#69]
@Banshee, thanks for the input! I think I may know what the issue is and will post an update soon.

I'm going to post a test script later that will help me figure out what part of the shader is failing to validate.

Thanks for all your help! :)


Banshee(Posted 2014) [#70]
No, THANK YOU!


BLaBZ(Posted 2014) [#71]
Hi All, If the validation\example failed or didn't work run the following code - this will help me diagnose where the issue is. :)

Post what shows up in the debuglog.

Thanks!

format_codebox('
SuperStrict

Import sidesign.minib3d

Global DiffuseVert:String = " #version 120 ~n" + ..
" ~n" + ..
" uniform bool FullBright; ~n" + ..
" uniform vec2 TexUVScale; ~n" + ..
" ~n" + ..
" //LIGHTING ~n" + ..
" struct LightInfo { ~n" + ..
" vec3 Position; ~n" + ..
" vec3 Intensity; ~n" + ..
" vec3 La; ~n" + ..
" vec3 Ld; ~n" + ..
" vec3 Ls; ~n" + ..
" }; ~n" + ..
" ~n" + ..
" struct MaterialInfo { ~n" + ..
" vec3 Ka; ~n" + ..
" vec3 Kd; ~n" + ..
" vec3 Ks; ~n" + ..
" float Shininess; ~n" + ..
" }; ~n" + ..
" uniform LightInfo Lights[7]; ~n" + ..
" uniform MaterialInfo Material; ~n" + ..
" //LIGHTING ~n" + ..
" ~n" + ..
" uniform vec3 LightPositions[7]; ~n" + ..
" uniform int LightCount; ~n" + ..
" ~n" + ..
" varying vec3 vertex_normal; ~n" + ..
" varying vec3 Position; ~n" + ..
" ~n" + ..
" //SHADOW VARIABLES ~n" + ..
" uniform bool EnableShadow; ~n" + ..
" uniform mat4 ModelMatrix; ~n" + ..
" uniform mat4 ShadowMatrix; ~n" + ..
" uniform mat4 Bias; ~n" + ..
" uniform mat4 ShadowProjection; ~n" + ..
" uniform mat4 ShadowModelView; ~n" + ..
" varying vec4 ShadowCoord; ~n" + ..
" //SHADOW VARIABLES ~n" + ..
" ~n" + ..
" //NORMAL MAPPING ~n" + ..
" uniform bool EnableNormalMap; ~n" + ..
" varying vec3 LightDir[7]; ~n" + ..
" varying vec3 ViewDir[7]; ~n" + ..
" //NORMAL MAPPING ~n" + ..
" ~n" + ..
" void main( void ) { ~n" + ..
" vertex_normal = normalize(gl_NormalMatrix * gl_Normal); ~n" + ..
" Position = vec3(gl_ModelViewMatrix * gl_Vertex); ~n" + ..
" if (EnableShadow) ~n" + ..
" { ~n" + ..
" ShadowCoord = Bias * ShadowProjection * ShadowModelView * ModelMatrix * gl_Vertex; ~n" + ..
" } ~n" + ..
" ~n" + ..
" if (EnableNormalMap) ~n" + ..
" { ~n" + ..
" vec3 vertex_tangent = normalize(gl_NormalMatrix * vec3(gl_Color)); ~n" + ..
" vec3 vertex_binormal = normalize(cross(vertex_normal,vertex_tangent)) * gl_Color.w; ~n" + ..
" //vec3 vertex_binormal = normalize(cross(vertex_tangent,vertex_normal)) * gl_Color.w; ~n" + ..
" mat3 toObjectLocal = mat3( vertex_tangent.x,vertex_binormal.x,vertex_normal.x, ~n" + ..
" vertex_tangent.y,vertex_binormal.y,vertex_normal.y, ~n" + ..
" vertex_tangent.z,vertex_binormal.z,vertex_normal.z); ~n" + ..
" ~n" + ..
" for( int i = 0; i < LightCount; i++ ) ~n" + ..
" { ~n" + ..
" LightDir[i] = normalize(toObjectLocal * (Lights[i].Position - Position)); ~n" + ..
" ViewDir[i] = toObjectLocal * normalize(-Position); ~n" + ..
" } ~n" + ..
" } ~n" + ..
" ~n" + ..
" gl_FrontColor = vec4(1.0,1.0,1.0,1.0); ~n" + ..
" gl_TexCoord[0] = gl_MultiTexCoord0 * vec4(TexUVScale,1.0,1.0); ~n" + ..
" gl_Position = ftransform(); ~n" + ..
" } ~n"
Global DiffuseFrag:String = " #version 120 ~n" + ..
" ~n" + ..
" uniform vec3 EntityColor; ~n" + ..
" uniform float EntityAlpha; ~n" + ..
" uniform bool FullBright; ~n" + ..
" ~n" + ..
" varying vec3 vertex_normal; ~n" + ..
" varying vec3 Position; ~n" + ..
" ~n" + ..
" //FOG VARIABLES ~n" + ..
" uniform bool EnableFog; ~n" + ..
" uniform vec3 FogColor; ~n" + ..
" uniform float FogStart; ~n" + ..
" uniform float FogEnd; ~n" + ..
" //FOG VARIABLES ~n" + ..
" ~n" + ..
" ~n" + ..
" //SHADOW VARIABLES ~n" + ..
" uniform bool EnableShadow; ~n" + ..
" uniform sampler2DShadow ShadowMap; ~n" + ..
" uniform int ShadowMapSize; ~n" + ..
" uniform float ShadowLightness; ~n" + ..
" varying vec4 ShadowCoord; ~n" + ..
" float xPixelOffset = 0.001; ~n" + ..
" float yPixelOffset = 0.001; ~n" + ..
" //SHADOW VARIABLES ~n" + ..
" ~n" + ..
" //DIFFUSE ~n" + ..
" uniform bool EnableDiffuseMap; ~n" + ..
" uniform sampler2D texture_diffuse; ~n" + ..
" //DIFFUSE ~n" + ..
" ~n" + ..
" //NORMAL MAPPING ~n" + ..
" uniform bool EnableNormalMap; ~n" + ..
" uniform sampler2D texture_normal; ~n" + ..
" varying vec3 ViewDir[7]; ~n" + ..
" varying vec3 LightDir[7]; ~n" + ..
" //NORMAL MAPPING ~n" + ..
" ~n" + ..
" ~n" + ..
" //LIGHTING ~n" + ..
" struct LightInfo { ~n" + ..
" vec3 Position; ~n" + ..
" vec3 Intensity; ~n" + ..
" vec3 La; ~n" + ..
" vec3 Ld; ~n" + ..
" vec3 Ls; ~n" + ..
" }; ~n" + ..
" ~n" + ..
" struct MaterialInfo { ~n" + ..
" vec3 Ka; ~n" + ..
" vec3 Kd; ~n" + ..
" vec3 Ks; ~n" + ..
" float Shininess; ~n" + ..
" }; ~n" + ..
" uniform int LightCount; ~n" + ..
" uniform LightInfo Lights[7]; ~n" + ..
" uniform vec3 LightPositions[7]; ~n" + ..
" uniform MaterialInfo Material; ~n" + ..
" //LIGHTING ~n" + ..
" ~n" + ..
" ~n" + ..
" vec3 refl( vec3 s, vec3 n) ~n" + ..
" { ~n" + ..
" return -s + 2 * (dot(s,n)) * n; ~n" + ..
" //return 2 * (dot(s,n))* n - s; ~n" + ..
" } ~n" + ..
" ~n" + ..
" vec3 ads( int LightIndex ) ~n" + ..
" { ~n" + ..
" vec3 n = normalize(vertex_normal); ~n" + ..
" vec3 s = normalize(Lights[LightIndex].Position - vec3(Position)); ~n" + ..
" vec3 v = normalize(vec3(-Position)); ~n" + ..
" vec3 h = refl(-s,n);//normalize(v+s); ~n" + ..
" ~n" + ..
" return Lights[LightIndex].Intensity * ((Lights[LightIndex].La * Material.Ka) + (Lights[LightIndex].Ld * Material.Kd) * max(dot(s,n),0.0) + (Lights[LightIndex].Ls * Material.Ks) * pow(max(dot(h,n),0.0),Material.Shininess)); ~n" + ..
" } ~n" + ..
" ~n" + ..
" vec3 adsn( vec3 norm, vec3 diffR, int LightIndex ) ~n" + ..
" { ~n" + ..
" vec3 n = normalize(norm); ~n" + ..
" vec3 s = normalize(Lights[LightIndex].Position - vec3(Position)); ~n" + ..
" vec3 v = normalize(vec3(-Position)); ~n" + ..
" vec3 h = refl(-LightDir[LightIndex],norm); ~n" + ..
" return Lights[LightIndex].Intensity * ((Lights[LightIndex].La * Material.Ka) + (Lights[LightIndex].Ld * Material.Kd) * max(dot(LightDir[LightIndex],n),0.0) + (Lights[LightIndex].Ls * Material.Ks) * pow(max(dot(h,ViewDir[LightIndex]),0.0),Material.Shininess)); ~n" + ..
" } ~n" + ..
" ~n" + ..
" float lookup( vec2 offSet) ~n" + ..
" { ~n" + ..
" return shadow2DProj(ShadowMap, ShadowCoord + vec4(offSet.x * xPixelOffset * ShadowCoord.w, offSet.y * yPixelOffset * ShadowCoord.w, 0.000025, 0.0) ).w; ~n" + ..
" } ~n" + ..
" ~n" + ..
" void main(void) { ~n" + ..
" ~n" + ..
" vec4 tex = vec4(0.0); ~n" + ..
" if (EnableDiffuseMap) ~n" + ..
" { ~n" + ..
" tex = texture2D(texture_diffuse, gl_TexCoord[0].st).rgba; ~n" + ..
" } else { ~n" + ..
" tex = vec4(EntityColor.rgb,1.0); ~n" + ..
" } ~n" + ..
" ~n" + ..
" vec3 lcolor = vec3(0.0); ~n" + ..
" if (FullBright) ~n" + ..
" { ~n" + ..
" lcolor = tex.rgb; ~n" + ..
" } else { ~n" + ..
" if (EnableNormalMap) ~n" + ..
" { ~n" + ..
" for( int i = 0; i < LightCount; i++ ) ~n" + ..
" lcolor += adsn(texture2D(texture_normal, gl_TexCoord[0].st).rgb,tex.rgb,i); ~n" + ..
" } else { ~n" + ..
" for( int i = 0; i < LightCount; i++ ) ~n" + ..
" lcolor += ads(i); ~n" + ..
" } ~n" + ..
" } ~n" + ..
" ~n" + ..
" ~n" + ..
" float shadow; ~n" + ..
" if (EnableShadow) ~n" + ..
" { ~n" + ..
" // Avoid counter shadow ~n" + ..
" if (ShadowCoord.w > 1.0) ~n" + ..
" { ~n" + ..
" float x,y; ~n" + ..
" for (y = -1.5 ; y <=1.5 ; y+=1.50) ~n" + ..
" for (x = -1.5 ; x <=1.5 ; x+=1.50) ~n" + ..
" shadow += lookup(vec2(x,y)); ~n" + ..
" ~n" + ..
" shadow /= 9.0 ; ~n" + ..
" } ~n" + ..
" } else { ~n" + ..
" shadow = 0.8; ~n" + ..
" } ~n" + ..
" ~n" + ..
" lcolor = (shadow+ShadowLightness) * (lcolor * tex.rgb); ~n" + ..
" ~n" + ..
" if (EnableFog) ~n" + ..
" { ~n" + ..
" float dist = abs(Position.z); ~n" + ..
" float fogFactor = (FogEnd - dist) / (FogEnd - FogStart); ~n" + ..
" fogFactor = clamp(fogFactor,0.0,1.0); ~n" + ..
" lcolor = mix(FogColor,lcolor,fogFactor); ~n" + ..
" } ~n" + ..
" ~n" + ..
" if (tex.a < 0.15) ~n" + ..
" { ~n" + ..
" discard; ~n" + ..
" } else { ~n" + ..
" gl_FragColor = vec4(lcolor,EntityAlpha); ~n" + ..
" } ~n" + ..
" } ~n"


Global ShadowVert:String = " #version 120 ~n" + ..
" ~n" + ..
" //SHADOW VARIABLES ~n" + ..
" uniform bool EnableShadow; ~n" + ..
" uniform mat4 ModelMatrix; ~n" + ..
" uniform mat4 ShadowMatrix; ~n" + ..
" uniform mat4 Bias; ~n" + ..
" uniform mat4 ShadowProjection; ~n" + ..
" uniform mat4 ShadowModelView; ~n" + ..
" varying vec4 ShadowCoord; ~n" + ..
" //SHADOW VARIABLES ~n" + ..
" ~n" + ..
" varying vec3 vertex_normal; ~n" + ..
" varying vec3 Position; ~n" + ..
" ~n" + ..
" void main( void ) { ~n" + ..
" vertex_normal = normalize(gl_NormalMatrix * gl_Normal); ~n" + ..
" Position = vec3(gl_ModelViewMatrix * gl_Vertex); ~n" + ..
" if (EnableShadow) ~n" + ..
" { ~n" + ..
" ShadowCoord = Bias * ShadowProjection * ShadowModelView * ModelMatrix * gl_Vertex; ~n" + ..
" } ~n" + ..
" gl_FrontColor = vec4(1.0,1.0,1.0,1.0); ~n" + ..
" gl_TexCoord[0] = gl_MultiTexCoord0; ~n" + ..
" gl_Position = ftransform(); ~n" + ..
" } ~n"

Global ShadowFrag:String = " #version 120 ~n" + ..
" ~n" + ..
" varying vec3 vertex_normal; ~n" + ..
" varying vec3 Position; ~n" + ..
" ~n" + ..
" ~n" + ..
" //SHADOW VARIABLES ~n" + ..
" uniform bool EnableShadow; ~n" + ..
" uniform sampler2DShadow ShadowMap; ~n" + ..
" uniform int ShadowMapSize; ~n" + ..
" uniform float ShadowLightness; ~n" + ..
" varying vec4 ShadowCoord; ~n" + ..
" float xPixelOffset = 0.001; ~n" + ..
" float yPixelOffset = 0.001; ~n" + ..
" //SHADOW VARIABLES ~n" + ..
" ~n" + ..
" float lookup( vec2 offSet) ~n" + ..
" { ~n" + ..
" return shadow2DProj(ShadowMap, ShadowCoord + vec4(offSet.x * xPixelOffset * ShadowCoord.w, offSet.y * yPixelOffset * ShadowCoord.w, 0.000025, 0.0) ).w; ~n" + ..
" } ~n" + ..
" ~n" + ..
" void main(void) { ~n" + ..
" vec3 lcolor = vec3(0.0); ~n" + ..
" ~n" + ..
" float shadow; ~n" + ..
" if (EnableShadow) ~n" + ..
" { ~n" + ..
" // Avoid counter shadow ~n" + ..
" if (ShadowCoord.w > 1.0) ~n" + ..
" { ~n" + ..
" float x,y; ~n" + ..
" for (y = -1.5 ; y <=1.5 ; y+=1.50) ~n" + ..
" for (x = -1.5 ; x <=1.5 ; x+=1.50) ~n" + ..
" shadow += lookup(vec2(x,y)); ~n" + ..
" ~n" + ..
" shadow /= 9.0 ; ~n" + ..
" } ~n" + ..
" } else { ~n" + ..
" shadow = 0.8; ~n" + ..
" } ~n" + ..
" ~n" + ..
" lcolor = (shadow+ShadowLightness) * (lcolor); ~n" + ..
" gl_FragColor = vec4(lcolor,1.0); ~n" + ..
" ~n" + ..
" } ~n"

Global LightVert:String = " #version 120 ~n" + ..
" ~n" + ..
" //LIGHTING ~n" + ..
" struct LightInfo { ~n" + ..
" vec3 Position; ~n" + ..
" vec3 Intensity; ~n" + ..
" vec3 La; ~n" + ..
" vec3 Ld; ~n" + ..
" vec3 Ls; ~n" + ..
" }; ~n" + ..
" ~n" + ..
" struct MaterialInfo { ~n" + ..
" vec3 Ka; ~n" + ..
" vec3 Kd; ~n" + ..
" vec3 Ks; ~n" + ..
" float Shininess; ~n" + ..
" }; ~n" + ..
" uniform LightInfo Lights[7]; ~n" + ..
" uniform MaterialInfo Material; ~n" + ..
" //LIGHTING ~n" + ..
" ~n" + ..
" uniform vec3 LightPositions[7]; ~n" + ..
" uniform int LightCount; ~n" + ..
" ~n" + ..
" varying vec3 vertex_normal; ~n" + ..
" varying vec3 Position; ~n" + ..
" ~n" + ..
" void main( void ) { ~n" + ..
" ~n" + ..
" vertex_normal = normalize(gl_NormalMatrix * gl_Normal); ~n" + ..
" Position = vec3(gl_ModelViewMatrix * gl_Vertex); ~n" + ..
" gl_FrontColor = vec4(1.0,1.0,1.0,1.0); ~n" + ..
" gl_TexCoord[0] = gl_MultiTexCoord0; ~n" + ..
" gl_Position = ftransform(); ~n" + ..
" } ~n"

Global LightFrag:String = " #version 120 ~n" + ..
" ~n" + ..
" varying vec3 vertex_normal; ~n" + ..
" varying vec3 Position; ~n" + ..
" ~n" + ..
" //LIGHTING ~n" + ..
" struct LightInfo { ~n" + ..
" vec3 Position; ~n" + ..
" vec3 Intensity; ~n" + ..
" vec3 La; ~n" + ..
" vec3 Ld; ~n" + ..
" vec3 Ls; ~n" + ..
" }; ~n" + ..
" ~n" + ..
" struct MaterialInfo { ~n" + ..
" vec3 Ka; ~n" + ..
" vec3 Kd; ~n" + ..
" vec3 Ks; ~n" + ..
" float Shininess; ~n" + ..
" }; ~n" + ..
" uniform int LightCount; ~n" + ..
" uniform LightInfo Lights[7]; ~n" + ..
" uniform vec3 LightPositions[7]; ~n" + ..
" uniform MaterialInfo Material; ~n" + ..
" //LIGHTING ~n" + ..
" ~n" + ..
" vec3 refl( vec3 s, vec3 n) ~n" + ..
" { ~n" + ..
" return -s + 2 * (dot(s,n)) * n; ~n" + ..
" } ~n" + ..
" ~n" + ..
" vec3 ads( int LightIndex ) ~n" + ..
" { ~n" + ..
" vec3 n = normalize(vertex_normal); ~n" + ..
" vec3 s = normalize(Lights[LightIndex].Position - vec3(Position)); ~n" + ..
" vec3 v = normalize(vec3(-Position)); ~n" + ..
" vec3 h = refl(-s,n);//normalize(v+s); ~n" + ..
" ~n" + ..
" return Lights[LightIndex].Intensity * ((Lights[LightIndex].La * Material.Ka) + (Lights[LightIndex].Ld * Material.Kd) * max(dot(s,n),0.0) + (Lights[LightIndex].Ls * Material.Ks) * pow(max(dot(h,n),0.0),Material.Shininess)); ~n" + ..
" } ~n" + ..
" ~n" + ..
" void main(void) { ~n" + ..
" ~n" + ..
" vec3 lcolor = vec3(0.0); ~n" + ..
" ~n" + ..
" for( int i = 0; i < LightCount; i++ ) ~n" + ..
" lcolor += ads(i); ~n" + ..
" ~n" + ..
" gl_FragColor = vec4(lcolor,1.0); ~n" + ..
" ~n" + ..
" } ~n"

Global NormalVert:String = " #version 120 ~n" + ..
" ~n" + ..
" //LIGHTING ~n" + ..
" struct LightInfo { ~n" + ..
" vec3 Position; ~n" + ..
" vec3 Intensity; ~n" + ..
" vec3 La; ~n" + ..
" vec3 Ld; ~n" + ..
" vec3 Ls; ~n" + ..
" }; ~n" + ..
" ~n" + ..
" struct MaterialInfo { ~n" + ..
" vec3 Ka; ~n" + ..
" vec3 Kd; ~n" + ..
" vec3 Ks; ~n" + ..
" float Shininess; ~n" + ..
" }; ~n" + ..
" uniform LightInfo Lights[7]; ~n" + ..
" uniform MaterialInfo Material; ~n" + ..
" //LIGHTING ~n" + ..
" ~n" + ..
" uniform vec3 LightPositions[7]; ~n" + ..
" uniform int LightCount; ~n" + ..
" ~n" + ..
" varying vec3 vertex_normal; ~n" + ..
" varying vec3 Position; ~n" + ..
" ~n" + ..
" //NORMAL MAPPING ~n" + ..
" uniform bool EnableNormalMap; ~n" + ..
" varying vec3 LightDir[7]; ~n" + ..
" varying vec3 ViewDir[7]; ~n" + ..
" //NORMAL MAPPING ~n" + ..
" ~n" + ..
" void main( void ) { ~n" + ..
" vertex_normal = normalize(gl_NormalMatrix * gl_Normal); ~n" + ..
" Position = vec3(gl_ModelViewMatrix * gl_Vertex); ~n" + ..
" ~n" + ..
" if (EnableNormalMap) ~n" + ..
" { ~n" + ..
" vec3 vertex_tangent = normalize(gl_NormalMatrix * vec3(gl_Color)); ~n" + ..
" vec3 vertex_binormal = normalize(cross(vertex_normal,vertex_tangent)) * gl_Color.w; ~n" + ..
" //vec3 vertex_binormal = normalize(cross(vertex_tangent,vertex_normal)) * gl_Color.w; ~n" + ..
" mat3 toObjectLocal = mat3( vertex_tangent.x,vertex_binormal.x,vertex_normal.x, ~n" + ..
" vertex_tangent.y,vertex_binormal.y,vertex_normal.y, ~n" + ..
" vertex_tangent.z,vertex_binormal.z,vertex_normal.z); ~n" + ..
" ~n" + ..
" for( int i = 0; i < LightCount; i++ ) ~n" + ..
" { ~n" + ..
" LightDir[i] = normalize(toObjectLocal * (Lights[i].Position - Position)); ~n" + ..
" ViewDir[i] = toObjectLocal * normalize(-Position); ~n" + ..
" } ~n" + ..
" } ~n" + ..
" ~n" + ..
" gl_FrontColor = vec4(1.0,1.0,1.0,1.0); ~n" + ..
" gl_TexCoord[0] = gl_MultiTexCoord0; ~n" + ..
" gl_Position = ftransform(); ~n" + ..
" } ~n"

Global NormalFrag:String = " #version 120 ~n" + ..
" ~n" + ..
" varying vec3 vertex_normal; ~n" + ..
" varying vec3 Position; ~n" + ..
" ~n" + ..
" //NORMAL MAPPING ~n" + ..
" uniform bool EnableNormalMap; ~n" + ..
" uniform sampler2D texture_normal; ~n" + ..
" varying vec3 ViewDir[7]; ~n" + ..
" varying vec3 LightDir[7]; ~n" + ..
" //NORMAL MAPPING ~n" + ..
" ~n" + ..
" //LIGHTING ~n" + ..
" struct LightInfo { ~n" + ..
" vec3 Position; ~n" + ..
" vec3 Intensity; ~n" + ..
" vec3 La; ~n" + ..
" vec3 Ld; ~n" + ..
" vec3 Ls; ~n" + ..
" }; ~n" + ..
" ~n" + ..
" struct MaterialInfo { ~n" + ..
" vec3 Ka; ~n" + ..
" vec3 Kd; ~n" + ..
" vec3 Ks; ~n" + ..
" float Shininess; ~n" + ..
" }; ~n" + ..
" uniform int LightCount; ~n" + ..
" uniform LightInfo Lights[7]; ~n" + ..
" uniform vec3 LightPositions[7]; ~n" + ..
" uniform MaterialInfo Material; ~n" + ..
" //LIGHTING ~n" + ..
" ~n" + ..
" vec3 refl( vec3 s, vec3 n) ~n" + ..
" { ~n" + ..
" return -s + 2 * (dot(s,n)) * n; ~n" + ..
" } ~n" + ..
" ~n" + ..
" vec3 adsn( vec3 norm, vec3 diffR, int LightIndex ) ~n" + ..
" { ~n" + ..
" vec3 n = normalize(norm); ~n" + ..
" vec3 s = normalize(Lights[LightIndex].Position - vec3(Position)); ~n" + ..
" vec3 v = normalize(vec3(-Position)); ~n" + ..
" vec3 h = refl(-LightDir[LightIndex],norm); ~n" + ..
" return Lights[LightIndex].Intensity * ((Lights[LightIndex].La * Material.Ka) + (Lights[LightIndex].Ld * Material.Kd) * max(dot(LightDir[LightIndex],n),0.0) + (Lights[LightIndex].Ls * Material.Ks) * pow(max(dot(h,ViewDir[LightIndex]),0.0),Material.Shininess)); ~n" + ..
" } ~n" + ..
" ~n" + ..
" float lookup( vec2 offSet) ~n" + ..
" { ~n" + ..
" return shadow2DProj(ShadowMap, ShadowCoord + vec4(offSet.x * xPixelOffset * ShadowCoord.w, offSet.y * yPixelOffset * ShadowCoord.w, 0.000025, 0.0) ).w; ~n" + ..
" } ~n" + ..
" ~n" + ..
" void main(void) { ~n" + ..
" ~n" + ..
" vec3 lcolor = vec3(0.0); ~n" + ..
" if (EnableNormalMap) ~n" + ..
" { ~n" + ..
" for( int i = 0; i < LightCount; i++ ) ~n" + ..
" lcolor += adsn(texture2D(texture_normal, gl_TexCoord[0].st).rgb,tex.rgb,i); ~n" + ..
" } ~n" + ..
" gl_FragColor = vec4(lcolor,1.0); ~n" + ..
" } ~n"

Graphics3D(800,600,0,2)
TShader.CheckCompatibility()
Local shad1:TShader = New TShader.Create(DiffuseVert,DiffuseFrag)
If shad1.Compiled Then Print "Full Shader Successfully Compiled" Else Print "Full Shader Failed To Compile"
Local shad2:TShader = New TShader.Create(ShadowVert,ShadowFrag)
If shad2.Compiled Then Print "Shadow Shader Successfully Compiled" Else Print "Shadow Shader Failed To Compile"
Local shad3:TShader = New TShader.Create(LightVert,LightFrag)
If shad3.Compiled Then Print "Light Shader Successfully Compiled" Else Print "Light Shader Failed To Compile"
Local shad4:TShader = New TShader.Create(NormalVert,NormalFrag)
If shad4.Compiled Then Print "Normal Map Shader Successfully Compiled" Else Print "Normal Map Shader Failed To Compile"




Print "Done"

Type TShader

Field ProgramObject:Int

Field Active:Byte = True

Field Compiled:Byte = False

Method Load:TShader(VertexPath:String, FragmentPath:String)

Local VertexCode:String, FragmentCode:String
Try
VertexCode = LoadText(VertexPath)
FragmentCode = LoadText(FragmentPath)
Catch Dummy:Object
DebugLog "Failed to Load Shader : " + VertexPath + " - " + FragmentPath
Return Null
EndTry

Create(VertexCode, FragmentCode)


Return Self
End Method

Method Create:TShader(VertexCode:String, FragmentCode:String)
If Not ProgramObject Then ProgramObject = glCreateProgram()

Local VertexShader :Int = glCreateShader(GL_VERTEX_SHADER)
Local FragmentShader:Int = glCreateShader(GL_FRAGMENT_SHADER)

Local ErrorMessage:String

_LoadShader(VertexCode, VertexShader)
glCompileShader(VertexShader)

If _CheckForErrors(VertexShader, ErrorMessage) Then
glDeleteShader(VertexShader)

Throw ErrorMessage
Return Self
EndIf

_LoadShader(FragmentCode, FragmentShader)
glCompileShader(FragmentShader)

If _CheckForErrors(FragmentShader, ErrorMessage) Then
glDeleteShader(VertexShader)
glDeleteShader(FragmentShader)

Throw ErrorMessage
Return Self
EndIf

glAttachShader(ProgramObject, VertexShader)
glAttachShader(ProgramObject, FragmentShader)



glDeleteShader(VertexShader)
glDeleteShader(FragmentShader)

glLinkProgram(ProgramObject)
If _CheckForErrors(ProgramObject, ErrorMessage, False)
Throw ErrorMessage
Return Self
EndIf



glValidateProgram(ProgramObject)

Local validated:Int
glGetProgramiv(ProgramObject, GL_VALIDATE_STATUS, Varptr validated)
If (validated)
DebugLog("Shader Validation Succeeded")
Else
DebugLog("Shader Failed to Validate")
_CheckForErrors(ProgramObject,ErrorMessage,True,False)
DebugLog("Validation Error: " + ErrorMessage)
EndIf

Compiled = True
Return Self
End Method


Method Enable()
glUseProgram(ProgramObject)
End Method

Method Disable()
glUseProgram(0)
End Method

Method Activate()
Self.Active = True
End Method

Method DeActivate()
Self.Active = False
End Method

Method GetUniformLocation:Int(Name:String)
Return glGetUniformLocationARB(ProgramObject, Name)
End Method

Method Delete()
glDeleteObjectARB(ProgramObject)
End Method

Function _LoadShader(ShaderCode:String, ShaderObject:Int)
Local ShaderCodeC:Byte Ptr = ShaderCode.ToCString()
Local ShaderCodeLen:Int = ShaderCode.Length

glShaderSource(ShaderObject, 1, Varptr ShaderCodeC, Varptr ShaderCodeLen)

MemFree(ShaderCodeC)
End Function

Function _CheckForErrors:Int(ShaderObject:Int, ErrorString:String Var, Compiled:Int = True, Validated:Int = True)
Local Successful:Int

If Compiled Then
glGetShaderiv(ShaderObject, GL_COMPILE_STATUS, Varptr Successful)
Else
glGetProgramiv(ShaderObject, GL_LINK_STATUS, Varptr Successful)
EndIf

If Not Validated Then
glGetProgramiv(ShaderObject, GL_VALIDATE_STATUS, Varptr Successful)
EndIf

If Not Successful Then
Local ErrorLength:Int
'glGetObjectParameterivARB(ShaderObject, GL_OBJECT_INFO_LOG_LENGTH_ARB, Varptr ErrorLength)
glGetShaderiv(ShaderObject,GL_INFO_LOG_LENGTH,Varptr ErrorLength)
Local Message:Byte Ptr = MemAlloc(ErrorLength), Dummy:Int

glGetInfoLogARB(ShaderObject, ErrorLength, Varptr Dummy, Message)

ErrorString = String.FromCString(Message)
MemFree(Message)

Return -1
EndIf

Return 0
End Function

Function CheckCompatibility:Int()
Local Extensions:String = String.FromCString(Byte Ptr glGetString(GL_EXTENSIONS))
Local GLVersion:String = String.FromCString(Byte Ptr glGetString(GL_VERSION))
Local GLVersionInt:Int = GLVersion[.. 3].Replace(".", "").ToInt()

DebugLog "GLVersion: " + GLVersion
DebugLog "iGLVerion: " + GLVersionInt

If Extensions.Find("GL_ARB_shader_objects" ) >= 0 And ..
Extensions.Find("GL_ARB_vertex_shader" ) >= 0 And ..
Extensions.Find("GL_ARB_fragment_shader") >= 0 Or GLVersionInt >= 20 Then Return True

Return False
End Function



End Type


')


Hotshot2005(Posted 2014) [#72]
DebugLog:GLVersion: 4.2.12217 Compatibility Profile Context 12.104.0.0
DebugLog:iGLVerion: 42
DebugLog:Shader Failed to Validate
DebugLog:Validation Error: DebugLog:Shader  ¼ZHO
Full Shader Successfully Compiled
DebugLog:Shader Validation Succeeded
Shadow Shader Successfully Compiled
DebugLog:Shader Validation Succeeded
Light Shader Successfully Compiled
DebugLog:Shader Validation Succeeded
Normal Map Shader Successfully Compiled


BLaBZ(Posted 2014) [#73]
Ooops! I just noticed an issue with the code, fixed it, can you run it again?!

Thanks for the Help Hotshot!


Hotshot2005(Posted 2014) [#74]
When i copy and paste your code then run it

It got error saying

Unhandled Expection: Fragment shader failed to compile with following error:



DebugLog:GLVersion: 4.2.12217 Compatibility Profile Context 12.104.0.0
DebugLog:iGLVerion: 42
DebugLog:Shader Failed to Validate
DebugLog:Validation Error: 
Full Shader Successfully Compiled
DebugLog:Shader Validation Succeeded
Shadow Shader Successfully Compiled
DebugLog:Shader Validation Succeeded
Light Shader Successfully Compiled
ERROR: 0:50: error(#143) Undeclared identifier: ShadowMap
ERROR: 0:50: error(#143) Undeclared identifier: ShadowCoord
ERROR: 0:50: error(#143) Undeclared identifier: xPixelOffset
ERROR: 0:50: error(#216) Vector field selection out of range "w"
ERROR: 0:50: error(#143) Undeclared identifier: yPixelOffset
ERROR: 0:50: error(#216) Vector field selection out of range "w"
ERROR: 0:50: error(#202) No matching overloaded function found: shadow2DProj
ERROR: 0:50: error(#216) Vector field selection out of range "w"
ERROR: 0:59: error(#143) Undeclared identifier: tex
ERROR: 0:59: error(#216) Vector field selection out of range "rgb"
ERROR: 0:59: error(#202) No matching overloaded function found: adsn
ERROR: error(#273) 11 compilation errors. No code generated


BLaBZ(Posted 2014) [#75]
Yay :)

Thanks Hotshot, this is actually very helpful. I'll take a look tonight.


BLaBZ(Posted 2014) [#76]
Ok, I'm sorry this is so tedious, I can't really think of a better way to test other than this.

I've changed the test script a little -


format_codebox('
SuperStrict

Import sidesign.minib3d

Global DiffuseVert:String = " #version 120 ~n" + ..
" ~n" + ..
" uniform bool FullBright; ~n" + ..
" uniform vec2 TexUVScale; ~n" + ..
" ~n" + ..
" //LIGHTING ~n" + ..
" struct LightInfo { ~n" + ..
" vec3 Position; ~n" + ..
" vec3 Intensity; ~n" + ..
" vec3 La; ~n" + ..
" vec3 Ld; ~n" + ..
" vec3 Ls; ~n" + ..
" }; ~n" + ..
" ~n" + ..
" struct MaterialInfo { ~n" + ..
" vec3 Ka; ~n" + ..
" vec3 Kd; ~n" + ..
" vec3 Ks; ~n" + ..
" float Shininess; ~n" + ..
" }; ~n" + ..
" uniform LightInfo Lights[7]; ~n" + ..
" uniform MaterialInfo Material; ~n" + ..
" //LIGHTING ~n" + ..
" ~n" + ..
" uniform vec3 LightPositions[7]; ~n" + ..
" uniform int LightCount; ~n" + ..
" ~n" + ..
" varying vec3 vertex_normal; ~n" + ..
" varying vec3 Position; ~n" + ..
" ~n" + ..
" //SHADOW VARIABLES ~n" + ..
" uniform bool EnableShadow; ~n" + ..
" uniform mat4 ModelMatrix; ~n" + ..
" uniform mat4 ShadowMatrix; ~n" + ..
" uniform mat4 Bias; ~n" + ..
" uniform mat4 ShadowProjection; ~n" + ..
" uniform mat4 ShadowModelView; ~n" + ..
" varying vec4 ShadowCoord; ~n" + ..
" //SHADOW VARIABLES ~n" + ..
" ~n" + ..
" //NORMAL MAPPING ~n" + ..
" uniform bool EnableNormalMap; ~n" + ..
" varying vec3 LightDir[7]; ~n" + ..
" varying vec3 ViewDir[7]; ~n" + ..
" //NORMAL MAPPING ~n" + ..
" ~n" + ..
" void main( void ) { ~n" + ..
" vertex_normal = normalize(gl_NormalMatrix * gl_Normal); ~n" + ..
" Position = vec3(gl_ModelViewMatrix * gl_Vertex); ~n" + ..
" if (EnableShadow) ~n" + ..
" { ~n" + ..
" ShadowCoord = Bias * ShadowProjection * ShadowModelView * ModelMatrix * gl_Vertex; ~n" + ..
" } ~n" + ..
" ~n" + ..
" if (EnableNormalMap) ~n" + ..
" { ~n" + ..
" vec3 vertex_tangent = normalize(gl_NormalMatrix * vec3(gl_Color)); ~n" + ..
" vec3 vertex_binormal = normalize(cross(vertex_normal,vertex_tangent)) * gl_Color.w; ~n" + ..
" //vec3 vertex_binormal = normalize(cross(vertex_tangent,vertex_normal)) * gl_Color.w; ~n" + ..
" mat3 toObjectLocal = mat3( vertex_tangent.x,vertex_binormal.x,vertex_normal.x, ~n" + ..
" vertex_tangent.y,vertex_binormal.y,vertex_normal.y, ~n" + ..
" vertex_tangent.z,vertex_binormal.z,vertex_normal.z); ~n" + ..
" ~n" + ..
" for( int i = 0; i < LightCount; i++ ) ~n" + ..
" { ~n" + ..
" LightDir[i] = normalize(toObjectLocal * (Lights[i].Position - Position)); ~n" + ..
" ViewDir[i] = toObjectLocal * normalize(-Position); ~n" + ..
" } ~n" + ..
" } ~n" + ..
" ~n" + ..
" gl_FrontColor = vec4(1.0,1.0,1.0,1.0); ~n" + ..
" gl_TexCoord[0] = gl_MultiTexCoord0 * vec4(TexUVScale,1.0,1.0); ~n" + ..
" gl_Position = ftransform(); ~n" + ..
" } ~n"
Global DiffuseFrag:String = " #version 120 ~n" + ..
" ~n" + ..
" uniform vec3 EntityColor; ~n" + ..
" uniform float EntityAlpha; ~n" + ..
" uniform bool FullBright; ~n" + ..
" ~n" + ..
" varying vec3 vertex_normal; ~n" + ..
" varying vec3 Position; ~n" + ..
" ~n" + ..
" //FOG VARIABLES ~n" + ..
" uniform bool EnableFog; ~n" + ..
" uniform vec3 FogColor; ~n" + ..
" uniform float FogStart; ~n" + ..
" uniform float FogEnd; ~n" + ..
" //FOG VARIABLES ~n" + ..
" ~n" + ..
" ~n" + ..
" //SHADOW VARIABLES ~n" + ..
" uniform bool EnableShadow; ~n" + ..
" uniform sampler2DShadow ShadowMap; ~n" + ..
" uniform int ShadowMapSize; ~n" + ..
" uniform float ShadowLightness; ~n" + ..
" varying vec4 ShadowCoord; ~n" + ..
" float xPixelOffset = 0.001; ~n" + ..
" float yPixelOffset = 0.001; ~n" + ..
" //SHADOW VARIABLES ~n" + ..
" ~n" + ..
" //DIFFUSE ~n" + ..
" uniform bool EnableDiffuseMap; ~n" + ..
" uniform sampler2D texture_diffuse; ~n" + ..
" //DIFFUSE ~n" + ..
" ~n" + ..
" //NORMAL MAPPING ~n" + ..
" uniform bool EnableNormalMap; ~n" + ..
" uniform sampler2D texture_normal; ~n" + ..
" varying vec3 ViewDir[7]; ~n" + ..
" varying vec3 LightDir[7]; ~n" + ..
" //NORMAL MAPPING ~n" + ..
" ~n" + ..
" ~n" + ..
" //LIGHTING ~n" + ..
" struct LightInfo { ~n" + ..
" vec3 Position; ~n" + ..
" vec3 Intensity; ~n" + ..
" vec3 La; ~n" + ..
" vec3 Ld; ~n" + ..
" vec3 Ls; ~n" + ..
" }; ~n" + ..
" ~n" + ..
" struct MaterialInfo { ~n" + ..
" vec3 Ka; ~n" + ..
" vec3 Kd; ~n" + ..
" vec3 Ks; ~n" + ..
" float Shininess; ~n" + ..
" }; ~n" + ..
" uniform int LightCount; ~n" + ..
" uniform LightInfo Lights[7]; ~n" + ..
" uniform vec3 LightPositions[7]; ~n" + ..
" uniform MaterialInfo Material; ~n" + ..
" //LIGHTING ~n" + ..
" ~n" + ..
" ~n" + ..
" vec3 refl( vec3 s, vec3 n) ~n" + ..
" { ~n" + ..
" return -s + 2 * (dot(s,n)) * n; ~n" + ..
" //return 2 * (dot(s,n))* n - s; ~n" + ..
" } ~n" + ..
" ~n" + ..
" vec3 ads( int LightIndex ) ~n" + ..
" { ~n" + ..
" vec3 n = normalize(vertex_normal); ~n" + ..
" vec3 s = normalize(Lights[LightIndex].Position - vec3(Position)); ~n" + ..
" vec3 v = normalize(vec3(-Position)); ~n" + ..
" vec3 h = refl(-s,n);//normalize(v+s); ~n" + ..
" ~n" + ..
" return Lights[LightIndex].Intensity * ((Lights[LightIndex].La * Material.Ka) + (Lights[LightIndex].Ld * Material.Kd) * max(dot(s,n),0.0) + (Lights[LightIndex].Ls * Material.Ks) * pow(max(dot(h,n),0.0),Material.Shininess)); ~n" + ..
" } ~n" + ..
" ~n" + ..
" vec3 adsn( vec3 norm, vec3 diffR, int LightIndex ) ~n" + ..
" { ~n" + ..
" vec3 n = normalize(norm); ~n" + ..
" vec3 s = normalize(Lights[LightIndex].Position - vec3(Position)); ~n" + ..
" vec3 v = normalize(vec3(-Position)); ~n" + ..
" vec3 h = refl(-LightDir[LightIndex],norm); ~n" + ..
" return Lights[LightIndex].Intensity * ((Lights[LightIndex].La * Material.Ka) + (Lights[LightIndex].Ld * Material.Kd) * max(dot(LightDir[LightIndex],n),0.0) + (Lights[LightIndex].Ls * Material.Ks) * pow(max(dot(h,ViewDir[LightIndex]),0.0),Material.Shininess)); ~n" + ..
" } ~n" + ..
" ~n" + ..
" float lookup( vec2 offSet) ~n" + ..
" { ~n" + ..
" return shadow2DProj(ShadowMap, ShadowCoord + vec4(offSet.x * xPixelOffset * ShadowCoord.w, offSet.y * yPixelOffset * ShadowCoord.w, 0.000025, 0.0) ).w; ~n" + ..
" } ~n" + ..
" ~n" + ..
" void main(void) { ~n" + ..
" ~n" + ..
" vec4 tex = vec4(0.0); ~n" + ..
" if (EnableDiffuseMap) ~n" + ..
" { ~n" + ..
" tex = texture2D(texture_diffuse, gl_TexCoord[0].st).rgba; ~n" + ..
" } else { ~n" + ..
" tex = vec4(EntityColor.rgb,1.0); ~n" + ..
" } ~n" + ..
" ~n" + ..
" vec3 lcolor = vec3(0.0); ~n" + ..
" if (FullBright) ~n" + ..
" { ~n" + ..
" lcolor = tex.rgb; ~n" + ..
" } else { ~n" + ..
" if (EnableNormalMap) ~n" + ..
" { ~n" + ..
" for( int i = 0; i < LightCount; i++ ) ~n" + ..
" lcolor += adsn(texture2D(texture_normal, gl_TexCoord[0].st).rgb,tex.rgb,i); ~n" + ..
" } else { ~n" + ..
" for( int i = 0; i < LightCount; i++ ) ~n" + ..
" lcolor += ads(i); ~n" + ..
" } ~n" + ..
" } ~n" + ..
" ~n" + ..
" ~n" + ..
" float shadow; ~n" + ..
" if (EnableShadow) ~n" + ..
" { ~n" + ..
" // Avoid counter shadow ~n" + ..
" if (ShadowCoord.w > 1.0) ~n" + ..
" { ~n" + ..
" float x,y; ~n" + ..
" for (y = -1.5 ; y <=1.5 ; y+=1.50) ~n" + ..
" for (x = -1.5 ; x <=1.5 ; x+=1.50) ~n" + ..
" shadow += lookup(vec2(x,y)); ~n" + ..
" ~n" + ..
" shadow /= 9.0 ; ~n" + ..
" } ~n" + ..
" } else { ~n" + ..
" shadow = 0.8; ~n" + ..
" } ~n" + ..
" ~n" + ..
" lcolor = (shadow+ShadowLightness) * (lcolor * tex.rgb); ~n" + ..
" ~n" + ..
" if (EnableFog) ~n" + ..
" { ~n" + ..
" float dist = abs(Position.z); ~n" + ..
" float fogFactor = (FogEnd - dist) / (FogEnd - FogStart); ~n" + ..
" fogFactor = clamp(fogFactor,0.0,1.0); ~n" + ..
" lcolor = mix(FogColor,lcolor,fogFactor); ~n" + ..
" } ~n" + ..
" ~n" + ..
" if (tex.a < 0.15) ~n" + ..
" { ~n" + ..
" discard; ~n" + ..
" } else { ~n" + ..
" gl_FragColor = vec4(lcolor,EntityAlpha); ~n" + ..
" } ~n" + ..
" } ~n"


Global ShadowVert:String = " #version 120 ~n" + ..
" ~n" + ..
" //SHADOW VARIABLES ~n" + ..
" uniform bool EnableShadow; ~n" + ..
" uniform mat4 ModelMatrix; ~n" + ..
" uniform mat4 ShadowMatrix; ~n" + ..
" uniform mat4 Bias; ~n" + ..
" uniform mat4 ShadowProjection; ~n" + ..
" uniform mat4 ShadowModelView; ~n" + ..
" varying vec4 ShadowCoord; ~n" + ..
" //SHADOW VARIABLES ~n" + ..
" ~n" + ..
" varying vec3 vertex_normal; ~n" + ..
" varying vec3 Position; ~n" + ..
" ~n" + ..
" void main( void ) { ~n" + ..
" vertex_normal = normalize(gl_NormalMatrix * gl_Normal); ~n" + ..
" Position = vec3(gl_ModelViewMatrix * gl_Vertex); ~n" + ..
" if (EnableShadow) ~n" + ..
" { ~n" + ..
" ShadowCoord = Bias * ShadowProjection * ShadowModelView * ModelMatrix * gl_Vertex; ~n" + ..
" } ~n" + ..
" gl_FrontColor = vec4(1.0,1.0,1.0,1.0); ~n" + ..
" gl_TexCoord[0] = gl_MultiTexCoord0; ~n" + ..
" gl_Position = ftransform(); ~n" + ..
" } ~n"

Global ShadowFrag:String = " #version 120 ~n" + ..
" ~n" + ..
" varying vec3 vertex_normal; ~n" + ..
" varying vec3 Position; ~n" + ..
" ~n" + ..
" ~n" + ..
" //SHADOW VARIABLES ~n" + ..
" uniform bool EnableShadow; ~n" + ..
" uniform sampler2DShadow ShadowMap; ~n" + ..
" uniform int ShadowMapSize; ~n" + ..
" uniform float ShadowLightness; ~n" + ..
" varying vec4 ShadowCoord; ~n" + ..
" float xPixelOffset = 0.001; ~n" + ..
" float yPixelOffset = 0.001; ~n" + ..
" //SHADOW VARIABLES ~n" + ..
" ~n" + ..
" float lookup( vec2 offSet) ~n" + ..
" { ~n" + ..
" return shadow2DProj(ShadowMap, ShadowCoord + vec4(offSet.x * xPixelOffset * ShadowCoord.w, offSet.y * yPixelOffset * ShadowCoord.w, 0.000025, 0.0) ).w; ~n" + ..
" } ~n" + ..
" ~n" + ..
" void main(void) { ~n" + ..
" vec3 lcolor = vec3(0.0); ~n" + ..
" ~n" + ..
" float shadow; ~n" + ..
" if (EnableShadow) ~n" + ..
" { ~n" + ..
" // Avoid counter shadow ~n" + ..
" if (ShadowCoord.w > 1.0) ~n" + ..
" { ~n" + ..
" float x,y; ~n" + ..
" for (y = -1.5 ; y <=1.5 ; y+=1.50) ~n" + ..
" for (x = -1.5 ; x <=1.5 ; x+=1.50) ~n" + ..
" shadow += lookup(vec2(x,y)); ~n" + ..
" ~n" + ..
" shadow /= 9.0 ; ~n" + ..
" } ~n" + ..
" } else { ~n" + ..
" shadow = 0.8; ~n" + ..
" } ~n" + ..
" ~n" + ..
" lcolor = (shadow+ShadowLightness) * (lcolor); ~n" + ..
" gl_FragColor = vec4(lcolor,1.0); ~n" + ..
" ~n" + ..
" } ~n"

Global LightVert:String = " #version 120 ~n" + ..
" ~n" + ..
" //LIGHTING ~n" + ..
" struct LightInfo { ~n" + ..
" vec3 Position; ~n" + ..
" vec3 Intensity; ~n" + ..
" vec3 La; ~n" + ..
" vec3 Ld; ~n" + ..
" vec3 Ls; ~n" + ..
" }; ~n" + ..
" ~n" + ..
" struct MaterialInfo { ~n" + ..
" vec3 Ka; ~n" + ..
" vec3 Kd; ~n" + ..
" vec3 Ks; ~n" + ..
" float Shininess; ~n" + ..
" }; ~n" + ..
" uniform LightInfo Lights[7]; ~n" + ..
" uniform MaterialInfo Material; ~n" + ..
" //LIGHTING ~n" + ..
" ~n" + ..
" uniform vec3 LightPositions[7]; ~n" + ..
" uniform int LightCount; ~n" + ..
" ~n" + ..
" varying vec3 vertex_normal; ~n" + ..
" varying vec3 Position; ~n" + ..
" ~n" + ..
" void main( void ) { ~n" + ..
" ~n" + ..
" vertex_normal = normalize(gl_NormalMatrix * gl_Normal); ~n" + ..
" Position = vec3(gl_ModelViewMatrix * gl_Vertex); ~n" + ..
" gl_FrontColor = vec4(1.0,1.0,1.0,1.0); ~n" + ..
" gl_TexCoord[0] = gl_MultiTexCoord0; ~n" + ..
" gl_Position = ftransform(); ~n" + ..
" } ~n"

Global LightFrag:String = " #version 120 ~n" + ..
" ~n" + ..
" varying vec3 vertex_normal; ~n" + ..
" varying vec3 Position; ~n" + ..
" ~n" + ..
" //LIGHTING ~n" + ..
" struct LightInfo { ~n" + ..
" vec3 Position; ~n" + ..
" vec3 Intensity; ~n" + ..
" vec3 La; ~n" + ..
" vec3 Ld; ~n" + ..
" vec3 Ls; ~n" + ..
" }; ~n" + ..
" ~n" + ..
" struct MaterialInfo { ~n" + ..
" vec3 Ka; ~n" + ..
" vec3 Kd; ~n" + ..
" vec3 Ks; ~n" + ..
" float Shininess; ~n" + ..
" }; ~n" + ..
" uniform int LightCount; ~n" + ..
" uniform LightInfo Lights[7]; ~n" + ..
" uniform vec3 LightPositions[7]; ~n" + ..
" uniform MaterialInfo Material; ~n" + ..
" //LIGHTING ~n" + ..
" ~n" + ..
" vec3 refl( vec3 s, vec3 n) ~n" + ..
" { ~n" + ..
" return -s + 2 * (dot(s,n)) * n; ~n" + ..
" } ~n" + ..
" ~n" + ..
" vec3 ads( int LightIndex ) ~n" + ..
" { ~n" + ..
" vec3 n = normalize(vertex_normal); ~n" + ..
" vec3 s = normalize(Lights[LightIndex].Position - vec3(Position)); ~n" + ..
" vec3 v = normalize(vec3(-Position)); ~n" + ..
" vec3 h = refl(-s,n);//normalize(v+s); ~n" + ..
" ~n" + ..
" return Lights[LightIndex].Intensity * ((Lights[LightIndex].La * Material.Ka) + (Lights[LightIndex].Ld * Material.Kd) * max(dot(s,n),0.0) + (Lights[LightIndex].Ls * Material.Ks) * pow(max(dot(h,n),0.0),Material.Shininess)); ~n" + ..
" } ~n" + ..
" ~n" + ..
" void main(void) { ~n" + ..
" ~n" + ..
" vec3 lcolor = vec3(0.0); ~n" + ..
" ~n" + ..
" for( int i = 0; i < LightCount; i++ ) ~n" + ..
" lcolor += ads(i); ~n" + ..
" ~n" + ..
" gl_FragColor = vec4(lcolor,1.0); ~n" + ..
" ~n" + ..
" } ~n"

Global NormalVert:String = " #version 120 ~n" + ..
" ~n" + ..
" //LIGHTING ~n" + ..
" struct LightInfo { ~n" + ..
" vec3 Position; ~n" + ..
" vec3 Intensity; ~n" + ..
" vec3 La; ~n" + ..
" vec3 Ld; ~n" + ..
" vec3 Ls; ~n" + ..
" }; ~n" + ..
" ~n" + ..
" struct MaterialInfo { ~n" + ..
" vec3 Ka; ~n" + ..
" vec3 Kd; ~n" + ..
" vec3 Ks; ~n" + ..
" float Shininess; ~n" + ..
" }; ~n" + ..
" uniform LightInfo Lights[7]; ~n" + ..
" uniform MaterialInfo Material; ~n" + ..
" //LIGHTING ~n" + ..
" ~n" + ..
" uniform vec3 LightPositions[7]; ~n" + ..
" uniform int LightCount; ~n" + ..
" ~n" + ..
" varying vec3 vertex_normal; ~n" + ..
" varying vec3 Position; ~n" + ..
" ~n" + ..
" //NORMAL MAPPING ~n" + ..
" uniform bool EnableNormalMap; ~n" + ..
" varying vec3 LightDir[7]; ~n" + ..
" varying vec3 ViewDir[7]; ~n" + ..
" //NORMAL MAPPING ~n" + ..
" ~n" + ..
" void main( void ) { ~n" + ..
" vertex_normal = normalize(gl_NormalMatrix * gl_Normal); ~n" + ..
" Position = vec3(gl_ModelViewMatrix * gl_Vertex); ~n" + ..
" ~n" + ..
" if (EnableNormalMap) ~n" + ..
" { ~n" + ..
" vec3 vertex_tangent = normalize(gl_NormalMatrix * vec3(gl_Color)); ~n" + ..
" vec3 vertex_binormal = normalize(cross(vertex_normal,vertex_tangent)) * gl_Color.w; ~n" + ..
" //vec3 vertex_binormal = normalize(cross(vertex_tangent,vertex_normal)) * gl_Color.w; ~n" + ..
" mat3 toObjectLocal = mat3( vertex_tangent.x,vertex_binormal.x,vertex_normal.x, ~n" + ..
" vertex_tangent.y,vertex_binormal.y,vertex_normal.y, ~n" + ..
" vertex_tangent.z,vertex_binormal.z,vertex_normal.z); ~n" + ..
" ~n" + ..
" for( int i = 0; i < LightCount; i++ ) ~n" + ..
" { ~n" + ..
" LightDir[i] = normalize(toObjectLocal * (Lights[i].Position - Position)); ~n" + ..
" ViewDir[i] = toObjectLocal * normalize(-Position); ~n" + ..
" } ~n" + ..
" } ~n" + ..
" ~n" + ..
" gl_FrontColor = vec4(1.0,1.0,1.0,1.0); ~n" + ..
" gl_TexCoord[0] = gl_MultiTexCoord0; ~n" + ..
" gl_Position = ftransform(); ~n" + ..
" } ~n"

Global NormalFrag:String = " #version 120 ~n" + ..
" ~n" + ..
" varying vec3 vertex_normal; ~n" + ..
" varying vec3 Position; ~n" + ..
" ~n" + ..
" //NORMAL MAPPING ~n" + ..
" uniform bool EnableNormalMap; ~n" + ..
" uniform sampler2D texture_normal; ~n" + ..
" varying vec3 ViewDir[7]; ~n" + ..
" varying vec3 LightDir[7]; ~n" + ..
" //NORMAL MAPPING ~n" + ..
" ~n" + ..
" //LIGHTING ~n" + ..
" struct LightInfo { ~n" + ..
" vec3 Position; ~n" + ..
" vec3 Intensity; ~n" + ..
" vec3 La; ~n" + ..
" vec3 Ld; ~n" + ..
" vec3 Ls; ~n" + ..
" }; ~n" + ..
" ~n" + ..
" struct MaterialInfo { ~n" + ..
" vec3 Ka; ~n" + ..
" vec3 Kd; ~n" + ..
" vec3 Ks; ~n" + ..
" float Shininess; ~n" + ..
" }; ~n" + ..
" uniform int LightCount; ~n" + ..
" uniform LightInfo Lights[7]; ~n" + ..
" uniform vec3 LightPositions[7]; ~n" + ..
" uniform MaterialInfo Material; ~n" + ..
" //LIGHTING ~n" + ..
" ~n" + ..
" vec3 refl( vec3 s, vec3 n) ~n" + ..
" { ~n" + ..
" return -s + 2 * (dot(s,n)) * n; ~n" + ..
" } ~n" + ..
" ~n" + ..
" vec3 adsn( vec3 norm, vec3 diffR, int LightIndex ) ~n" + ..
" { ~n" + ..
" vec3 n = normalize(norm); ~n" + ..
" vec3 s = normalize(Lights[LightIndex].Position - vec3(Position)); ~n" + ..
" vec3 v = normalize(vec3(-Position)); ~n" + ..
" vec3 h = refl(-LightDir[LightIndex],norm); ~n" + ..
" return Lights[LightIndex].Intensity * ((Lights[LightIndex].La * Material.Ka) + (Lights[LightIndex].Ld * Material.Kd) * max(dot(LightDir[LightIndex],n),0.0) + (Lights[LightIndex].Ls * Material.Ks) * pow(max(dot(h,ViewDir[LightIndex]),0.0),Material.Shininess)); ~n" + ..
" } ~n" + ..
" ~n" + ..
" ~n" + ..
" void main(void) { ~n" + ..
" ~n" + ..
" vec3 lcolor = vec3(0.0); ~n" + ..
" if (EnableNormalMap) ~n" + ..
" { ~n" + ..
" for( int i = 0; i < LightCount; i++ ) ~n" + ..
" lcolor += adsn(texture2D(texture_normal, gl_TexCoord[0].st).rgb,tex.rgb,i); ~n" + ..
" } ~n" + ..
" gl_FragColor = vec4(lcolor,1.0); ~n" + ..
" } ~n"

Graphics3D(800,600,0,2)
TShader.CheckCompatibility()
Local shad1:TShader = New TShader.Create(DiffuseVert,DiffuseFrag)
If shad1.Compiled Then Print "Full Shader Successfully Compiled" Else Print "Full Shader Failed To Compile"
Local shad2:TShader = New TShader.Create(ShadowVert,ShadowFrag)
If shad2.Compiled Then Print "Shadow Shader Successfully Compiled" Else Print "Shadow Shader Failed To Compile"
Local shad3:TShader = New TShader.Create(LightVert,LightFrag)
If shad3.Compiled Then Print "Light Shader Successfully Compiled" Else Print "Light Shader Failed To Compile"
Local shad4:TShader = New TShader.Create(NormalVert,NormalFrag)
If shad4.Compiled Then Print "Normal Map Shader Successfully Compiled" Else Print "Normal Map Shader Failed To Compile"




Print "Done"

Type TShader

Field ProgramObject:Int

Field Active:Byte = True

Field Compiled:Byte = False

Method Load:TShader(VertexPath:String, FragmentPath:String)

Local VertexCode:String, FragmentCode:String
Try
VertexCode = LoadText(VertexPath)
FragmentCode = LoadText(FragmentPath)
Catch Dummy:Object
DebugLog "Failed to Load Shader : " + VertexPath + " - " + FragmentPath
Return Null
EndTry

Create(VertexCode, FragmentCode)


Return Self
End Method

Method Create:TShader(VertexCode:String, FragmentCode:String)
If Not ProgramObject Then ProgramObject = glCreateProgram()

Local VertexShader :Int = glCreateShader(GL_VERTEX_SHADER)
Local FragmentShader:Int = glCreateShader(GL_FRAGMENT_SHADER)

Local ErrorMessage:String

_LoadShader(VertexCode, VertexShader)
glCompileShader(VertexShader)

If _CheckForErrors(VertexShader, ErrorMessage) Then
glDeleteShader(VertexShader)

Throw ErrorMessage
Return Self
EndIf

_LoadShader(FragmentCode, FragmentShader)
glCompileShader(FragmentShader)

If _CheckForErrors(FragmentShader, ErrorMessage) Then
glDeleteShader(VertexShader)
glDeleteShader(FragmentShader)

Throw ErrorMessage
Return Self
EndIf

glAttachShader(ProgramObject, VertexShader)
glAttachShader(ProgramObject, FragmentShader)



glDeleteShader(VertexShader)
glDeleteShader(FragmentShader)

glLinkProgram(ProgramObject)
If _CheckForErrors(ProgramObject, ErrorMessage, False)
Throw ErrorMessage
Return Self
EndIf



glValidateProgram(ProgramObject)

Local validated:Int
glGetProgramiv(ProgramObject, GL_VALIDATE_STATUS, Varptr validated)
If (validated)
DebugLog("Shader Validation Succeeded")
Else
DebugLog("Shader Failed to Validate")
_CheckForErrors(ProgramObject,ErrorMessage,True,False)
DebugLog("Validation Error: " + ErrorMessage)
EndIf

Compiled = True
Return Self
End Method


Method Enable()
glUseProgram(ProgramObject)
End Method

Method Disable()
glUseProgram(0)
End Method

Method Activate()
Self.Active = True
End Method

Method DeActivate()
Self.Active = False
End Method

Method GetUniformLocation:Int(Name:String)
Return glGetUniformLocationARB(ProgramObject, Name)
End Method

Method Delete()
glDeleteObjectARB(ProgramObject)
End Method

Function _LoadShader(ShaderCode:String, ShaderObject:Int)
Local ShaderCodeC:Byte Ptr = ShaderCode.ToCString()
Local ShaderCodeLen:Int = ShaderCode.Length

glShaderSource(ShaderObject, 1, Varptr ShaderCodeC, Varptr ShaderCodeLen)

MemFree(ShaderCodeC)
End Function

Function _CheckForErrors:Int(ShaderObject:Int, ErrorString:String Var, Compiled:Int = True, Validated:Int = True)
Local Successful:Int

If Compiled Then
glGetShaderiv(ShaderObject, GL_COMPILE_STATUS, Varptr Successful)
Else
glGetProgramiv(ShaderObject, GL_LINK_STATUS, Varptr Successful)
EndIf

If Not Validated Then
glGetProgramiv(ShaderObject, GL_VALIDATE_STATUS, Varptr Successful)
EndIf

If Not Successful Then
Local ErrorLength:Int
'glGetObjectParameterivARB(ShaderObject, GL_OBJECT_INFO_LOG_LENGTH_ARB, Varptr ErrorLength)
glGetShaderiv(ShaderObject,GL_INFO_LOG_LENGTH,Varptr ErrorLength)
Local Message:Byte Ptr = MemAlloc(ErrorLength), Dummy:Int

glGetInfoLogARB(ShaderObject, ErrorLength, Varptr Dummy, Message)

ErrorString = String.FromCString(Message)
MemFree(Message)

Return -1
EndIf

Return 0
End Function

Function CheckCompatibility:Int()
Local Extensions:String = String.FromCString(Byte Ptr glGetString(GL_EXTENSIONS))
Local GLVersion:String = String.FromCString(Byte Ptr glGetString(GL_VERSION))
Local GLVersionInt:Int = GLVersion[.. 3].Replace(".", "").ToInt()

DebugLog "GLVersion: " + GLVersion
DebugLog "iGLVerion: " + GLVersionInt

If Extensions.Find("GL_ARB_shader_objects" ) >= 0 And ..
Extensions.Find("GL_ARB_vertex_shader" ) >= 0 And ..
Extensions.Find("GL_ARB_fragment_shader") >= 0 Or GLVersionInt >= 20 Then Return True

Return False
End Function



End Type


')


Hotshot2005(Posted 2014) [#77]
Building untitled1
Compiling:untitled1.bmx
flat assembler version 1.69.14 (1046198 kilobytes memory)
4 passes, 50996 bytes.
Linking:untitled1.debug.exe
Warning: resolving _glewInit by linking to _glewInit@0
Use --enable-stdcall-fixup to disable these warnings
Use --disable-stdcall-fixup to disable these fixups
Executing:untitled1.debug.exe
DebugLog:GLVersion: 4.2.12217 Compatibility Profile Context 12.104.0.0
DebugLog:iGLVerion: 42
DebugLog:Shader Failed to Validate
DebugLog:Validation Error: 
Full Shader Successfully Compiled
DebugLog:Shader Validation Succeeded
Shadow Shader Successfully Compiled
DebugLog:Shader Validation Succeeded
Light Shader Successfully Compiled
ERROR: 0:55: error(#143) Undeclared identifier: tex
ERROR: 0:55: error(#216) Vector field selection out of range "rgb"
ERROR: 0:55: error(#202) No matching overloaded function found: adsn
ERROR: error(#273) 3 compilation errors. No code generated


BLaBZ(Posted 2014) [#78]
! Try this :)

format_codebox('
SuperStrict

Import sidesign.minib3d

Global DiffuseVert:String = " #version 120 ~n" + ..
" ~n" + ..
" uniform bool FullBright; ~n" + ..
" uniform vec2 TexUVScale; ~n" + ..
" ~n" + ..
" //LIGHTING ~n" + ..
" struct LightInfo { ~n" + ..
" vec3 Position; ~n" + ..
" vec3 Intensity; ~n" + ..
" vec3 La; ~n" + ..
" vec3 Ld; ~n" + ..
" vec3 Ls; ~n" + ..
" }; ~n" + ..
" ~n" + ..
" struct MaterialInfo { ~n" + ..
" vec3 Ka; ~n" + ..
" vec3 Kd; ~n" + ..
" vec3 Ks; ~n" + ..
" float Shininess; ~n" + ..
" }; ~n" + ..
" uniform LightInfo Lights[7]; ~n" + ..
" uniform MaterialInfo Material; ~n" + ..
" //LIGHTING ~n" + ..
" ~n" + ..
" uniform vec3 LightPositions[7]; ~n" + ..
" uniform int LightCount; ~n" + ..
" ~n" + ..
" varying vec3 vertex_normal; ~n" + ..
" varying vec3 Position; ~n" + ..
" ~n" + ..
" //SHADOW VARIABLES ~n" + ..
" uniform bool EnableShadow; ~n" + ..
" uniform mat4 ModelMatrix; ~n" + ..
" uniform mat4 ShadowMatrix; ~n" + ..
" uniform mat4 Bias; ~n" + ..
" uniform mat4 ShadowProjection; ~n" + ..
" uniform mat4 ShadowModelView; ~n" + ..
" varying vec4 ShadowCoord; ~n" + ..
" //SHADOW VARIABLES ~n" + ..
" ~n" + ..
" //NORMAL MAPPING ~n" + ..
" uniform bool EnableNormalMap; ~n" + ..
" varying vec3 LightDir[7]; ~n" + ..
" varying vec3 ViewDir[7]; ~n" + ..
" //NORMAL MAPPING ~n" + ..
" ~n" + ..
" void main( void ) { ~n" + ..
" vertex_normal = normalize(gl_NormalMatrix * gl_Normal); ~n" + ..
" Position = vec3(gl_ModelViewMatrix * gl_Vertex); ~n" + ..
" if (EnableShadow) ~n" + ..
" { ~n" + ..
" ShadowCoord = Bias * ShadowProjection * ShadowModelView * ModelMatrix * gl_Vertex; ~n" + ..
" } ~n" + ..
" ~n" + ..
" if (EnableNormalMap) ~n" + ..
" { ~n" + ..
" vec3 vertex_tangent = normalize(gl_NormalMatrix * vec3(gl_Color)); ~n" + ..
" vec3 vertex_binormal = normalize(cross(vertex_normal,vertex_tangent)) * gl_Color.w; ~n" + ..
" //vec3 vertex_binormal = normalize(cross(vertex_tangent,vertex_normal)) * gl_Color.w; ~n" + ..
" mat3 toObjectLocal = mat3( vertex_tangent.x,vertex_binormal.x,vertex_normal.x, ~n" + ..
" vertex_tangent.y,vertex_binormal.y,vertex_normal.y, ~n" + ..
" vertex_tangent.z,vertex_binormal.z,vertex_normal.z); ~n" + ..
" ~n" + ..
" for( int i = 0; i < LightCount; i++ ) ~n" + ..
" { ~n" + ..
" LightDir[i] = normalize(toObjectLocal * (Lights[i].Position - Position)); ~n" + ..
" ViewDir[i] = toObjectLocal * normalize(-Position); ~n" + ..
" } ~n" + ..
" } ~n" + ..
" ~n" + ..
" gl_FrontColor = vec4(1.0,1.0,1.0,1.0); ~n" + ..
" gl_TexCoord[0] = gl_MultiTexCoord0 * vec4(TexUVScale,1.0,1.0); ~n" + ..
" gl_Position = ftransform(); ~n" + ..
" } ~n"
Global DiffuseFrag:String = " #version 120 ~n" + ..
" ~n" + ..
" uniform vec3 EntityColor; ~n" + ..
" uniform float EntityAlpha; ~n" + ..
" uniform bool FullBright; ~n" + ..
" ~n" + ..
" varying vec3 vertex_normal; ~n" + ..
" varying vec3 Position; ~n" + ..
" ~n" + ..
" //FOG VARIABLES ~n" + ..
" uniform bool EnableFog; ~n" + ..
" uniform vec3 FogColor; ~n" + ..
" uniform float FogStart; ~n" + ..
" uniform float FogEnd; ~n" + ..
" //FOG VARIABLES ~n" + ..
" ~n" + ..
" ~n" + ..
" //SHADOW VARIABLES ~n" + ..
" uniform bool EnableShadow; ~n" + ..
" uniform sampler2DShadow ShadowMap; ~n" + ..
" uniform int ShadowMapSize; ~n" + ..
" uniform float ShadowLightness; ~n" + ..
" varying vec4 ShadowCoord; ~n" + ..
" float xPixelOffset = 0.001; ~n" + ..
" float yPixelOffset = 0.001; ~n" + ..
" //SHADOW VARIABLES ~n" + ..
" ~n" + ..
" //DIFFUSE ~n" + ..
" uniform bool EnableDiffuseMap; ~n" + ..
" uniform sampler2D texture_diffuse; ~n" + ..
" //DIFFUSE ~n" + ..
" ~n" + ..
" //NORMAL MAPPING ~n" + ..
" uniform bool EnableNormalMap; ~n" + ..
" uniform sampler2D texture_normal; ~n" + ..
" varying vec3 ViewDir[7]; ~n" + ..
" varying vec3 LightDir[7]; ~n" + ..
" //NORMAL MAPPING ~n" + ..
" ~n" + ..
" ~n" + ..
" //LIGHTING ~n" + ..
" struct LightInfo { ~n" + ..
" vec3 Position; ~n" + ..
" vec3 Intensity; ~n" + ..
" vec3 La; ~n" + ..
" vec3 Ld; ~n" + ..
" vec3 Ls; ~n" + ..
" }; ~n" + ..
" ~n" + ..
" struct MaterialInfo { ~n" + ..
" vec3 Ka; ~n" + ..
" vec3 Kd; ~n" + ..
" vec3 Ks; ~n" + ..
" float Shininess; ~n" + ..
" }; ~n" + ..
" uniform int LightCount; ~n" + ..
" uniform LightInfo Lights[7]; ~n" + ..
" uniform vec3 LightPositions[7]; ~n" + ..
" uniform MaterialInfo Material; ~n" + ..
" //LIGHTING ~n" + ..
" ~n" + ..
" ~n" + ..
" vec3 refl( vec3 s, vec3 n) ~n" + ..
" { ~n" + ..
" return -s + 2 * (dot(s,n)) * n; ~n" + ..
" //return 2 * (dot(s,n))* n - s; ~n" + ..
" } ~n" + ..
" ~n" + ..
" vec3 ads( int LightIndex ) ~n" + ..
" { ~n" + ..
" vec3 n = normalize(vertex_normal); ~n" + ..
" vec3 s = normalize(Lights[LightIndex].Position - vec3(Position)); ~n" + ..
" vec3 v = normalize(vec3(-Position)); ~n" + ..
" vec3 h = refl(-s,n);//normalize(v+s); ~n" + ..
" ~n" + ..
" return Lights[LightIndex].Intensity * ((Lights[LightIndex].La * Material.Ka) + (Lights[LightIndex].Ld * Material.Kd) * max(dot(s,n),0.0) + (Lights[LightIndex].Ls * Material.Ks) * pow(max(dot(h,n),0.0),Material.Shininess)); ~n" + ..
" } ~n" + ..
" ~n" + ..
" vec3 adsn( vec3 norm, vec3 diffR, int LightIndex ) ~n" + ..
" { ~n" + ..
" vec3 n = normalize(norm); ~n" + ..
" vec3 s = normalize(Lights[LightIndex].Position - vec3(Position)); ~n" + ..
" vec3 v = normalize(vec3(-Position)); ~n" + ..
" vec3 h = refl(-LightDir[LightIndex],norm); ~n" + ..
" return Lights[LightIndex].Intensity * ((Lights[LightIndex].La * Material.Ka) + (Lights[LightIndex].Ld * Material.Kd) * max(dot(LightDir[LightIndex],n),0.0) + (Lights[LightIndex].Ls * Material.Ks) * pow(max(dot(h,ViewDir[LightIndex]),0.0),Material.Shininess)); ~n" + ..
" } ~n" + ..
" ~n" + ..
" float lookup( vec2 offSet) ~n" + ..
" { ~n" + ..
" return shadow2DProj(ShadowMap, ShadowCoord + vec4(offSet.x * xPixelOffset * ShadowCoord.w, offSet.y * yPixelOffset * ShadowCoord.w, 0.000025, 0.0) ).w; ~n" + ..
" } ~n" + ..
" ~n" + ..
" void main(void) { ~n" + ..
" ~n" + ..
" vec4 tex = vec4(0.0); ~n" + ..
" if (EnableDiffuseMap) ~n" + ..
" { ~n" + ..
" tex = texture2D(texture_diffuse, gl_TexCoord[0].st).rgba; ~n" + ..
" } else { ~n" + ..
" tex = vec4(EntityColor.rgb,1.0); ~n" + ..
" } ~n" + ..
" ~n" + ..
" vec3 lcolor = vec3(0.0); ~n" + ..
" if (FullBright) ~n" + ..
" { ~n" + ..
" lcolor = tex.rgb; ~n" + ..
" } else { ~n" + ..
" if (EnableNormalMap) ~n" + ..
" { ~n" + ..
" for( int i = 0; i < LightCount; i++ ) ~n" + ..
" lcolor += adsn(texture2D(texture_normal, gl_TexCoord[0].st).rgb,tex.rgb,i); ~n" + ..
" } else { ~n" + ..
" for( int i = 0; i < LightCount; i++ ) ~n" + ..
" lcolor += ads(i); ~n" + ..
" } ~n" + ..
" } ~n" + ..
" ~n" + ..
" ~n" + ..
" float shadow; ~n" + ..
" if (EnableShadow) ~n" + ..
" { ~n" + ..
" // Avoid counter shadow ~n" + ..
" if (ShadowCoord.w > 1.0) ~n" + ..
" { ~n" + ..
" float x,y; ~n" + ..
" for (y = -1.5 ; y <=1.5 ; y+=1.50) ~n" + ..
" for (x = -1.5 ; x <=1.5 ; x+=1.50) ~n" + ..
" shadow += lookup(vec2(x,y)); ~n" + ..
" ~n" + ..
" shadow /= 9.0 ; ~n" + ..
" } ~n" + ..
" } else { ~n" + ..
" shadow = 0.8; ~n" + ..
" } ~n" + ..
" ~n" + ..
" lcolor = (shadow+ShadowLightness) * (lcolor * tex.rgb); ~n" + ..
" ~n" + ..
" if (EnableFog) ~n" + ..
" { ~n" + ..
" float dist = abs(Position.z); ~n" + ..
" float fogFactor = (FogEnd - dist) / (FogEnd - FogStart); ~n" + ..
" fogFactor = clamp(fogFactor,0.0,1.0); ~n" + ..
" lcolor = mix(FogColor,lcolor,fogFactor); ~n" + ..
" } ~n" + ..
" ~n" + ..
" if (tex.a < 0.15) ~n" + ..
" { ~n" + ..
" discard; ~n" + ..
" } else { ~n" + ..
" gl_FragColor = vec4(lcolor,EntityAlpha); ~n" + ..
" } ~n" + ..
" } ~n"


Global ShadowVert:String = " #version 120 ~n" + ..
" ~n" + ..
" //SHADOW VARIABLES ~n" + ..
" uniform bool EnableShadow; ~n" + ..
" uniform mat4 ModelMatrix; ~n" + ..
" uniform mat4 ShadowMatrix; ~n" + ..
" uniform mat4 Bias; ~n" + ..
" uniform mat4 ShadowProjection; ~n" + ..
" uniform mat4 ShadowModelView; ~n" + ..
" varying vec4 ShadowCoord; ~n" + ..
" //SHADOW VARIABLES ~n" + ..
" ~n" + ..
" varying vec3 vertex_normal; ~n" + ..
" varying vec3 Position; ~n" + ..
" ~n" + ..
" void main( void ) { ~n" + ..
" vertex_normal = normalize(gl_NormalMatrix * gl_Normal); ~n" + ..
" Position = vec3(gl_ModelViewMatrix * gl_Vertex); ~n" + ..
" if (EnableShadow) ~n" + ..
" { ~n" + ..
" ShadowCoord = Bias * ShadowProjection * ShadowModelView * ModelMatrix * gl_Vertex; ~n" + ..
" } ~n" + ..
" gl_FrontColor = vec4(1.0,1.0,1.0,1.0); ~n" + ..
" gl_TexCoord[0] = gl_MultiTexCoord0; ~n" + ..
" gl_Position = ftransform(); ~n" + ..
" } ~n"

Global ShadowFrag:String = " #version 120 ~n" + ..
" ~n" + ..
" varying vec3 vertex_normal; ~n" + ..
" varying vec3 Position; ~n" + ..
" ~n" + ..
" ~n" + ..
" //SHADOW VARIABLES ~n" + ..
" uniform bool EnableShadow; ~n" + ..
" uniform sampler2DShadow ShadowMap; ~n" + ..
" uniform int ShadowMapSize; ~n" + ..
" uniform float ShadowLightness; ~n" + ..
" varying vec4 ShadowCoord; ~n" + ..
" float xPixelOffset = 0.001; ~n" + ..
" float yPixelOffset = 0.001; ~n" + ..
" //SHADOW VARIABLES ~n" + ..
" ~n" + ..
" float lookup( vec2 offSet) ~n" + ..
" { ~n" + ..
" return shadow2DProj(ShadowMap, ShadowCoord + vec4(offSet.x * xPixelOffset * ShadowCoord.w, offSet.y * yPixelOffset * ShadowCoord.w, 0.000025, 0.0) ).w; ~n" + ..
" } ~n" + ..
" ~n" + ..
" void main(void) { ~n" + ..
" vec3 lcolor = vec3(0.0); ~n" + ..
" ~n" + ..
" float shadow; ~n" + ..
" if (EnableShadow) ~n" + ..
" { ~n" + ..
" // Avoid counter shadow ~n" + ..
" if (ShadowCoord.w > 1.0) ~n" + ..
" { ~n" + ..
" float x,y; ~n" + ..
" for (y = -1.5 ; y <=1.5 ; y+=1.50) ~n" + ..
" for (x = -1.5 ; x <=1.5 ; x+=1.50) ~n" + ..
" shadow += lookup(vec2(x,y)); ~n" + ..
" ~n" + ..
" shadow /= 9.0 ; ~n" + ..
" } ~n" + ..
" } else { ~n" + ..
" shadow = 0.8; ~n" + ..
" } ~n" + ..
" ~n" + ..
" lcolor = (shadow+ShadowLightness) * (lcolor); ~n" + ..
" gl_FragColor = vec4(lcolor,1.0); ~n" + ..
" ~n" + ..
" } ~n"

Global LightVert:String = " #version 120 ~n" + ..
" ~n" + ..
" //LIGHTING ~n" + ..
" struct LightInfo { ~n" + ..
" vec3 Position; ~n" + ..
" vec3 Intensity; ~n" + ..
" vec3 La; ~n" + ..
" vec3 Ld; ~n" + ..
" vec3 Ls; ~n" + ..
" }; ~n" + ..
" ~n" + ..
" struct MaterialInfo { ~n" + ..
" vec3 Ka; ~n" + ..
" vec3 Kd; ~n" + ..
" vec3 Ks; ~n" + ..
" float Shininess; ~n" + ..
" }; ~n" + ..
" uniform LightInfo Lights[7]; ~n" + ..
" uniform MaterialInfo Material; ~n" + ..
" //LIGHTING ~n" + ..
" ~n" + ..
" uniform vec3 LightPositions[7]; ~n" + ..
" uniform int LightCount; ~n" + ..
" ~n" + ..
" varying vec3 vertex_normal; ~n" + ..
" varying vec3 Position; ~n" + ..
" ~n" + ..
" void main( void ) { ~n" + ..
" ~n" + ..
" vertex_normal = normalize(gl_NormalMatrix * gl_Normal); ~n" + ..
" Position = vec3(gl_ModelViewMatrix * gl_Vertex); ~n" + ..
" gl_FrontColor = vec4(1.0,1.0,1.0,1.0); ~n" + ..
" gl_TexCoord[0] = gl_MultiTexCoord0; ~n" + ..
" gl_Position = ftransform(); ~n" + ..
" } ~n"

Global LightFrag:String = " #version 120 ~n" + ..
" ~n" + ..
" varying vec3 vertex_normal; ~n" + ..
" varying vec3 Position; ~n" + ..
" ~n" + ..
" //LIGHTING ~n" + ..
" struct LightInfo { ~n" + ..
" vec3 Position; ~n" + ..
" vec3 Intensity; ~n" + ..
" vec3 La; ~n" + ..
" vec3 Ld; ~n" + ..
" vec3 Ls; ~n" + ..
" }; ~n" + ..
" ~n" + ..
" struct MaterialInfo { ~n" + ..
" vec3 Ka; ~n" + ..
" vec3 Kd; ~n" + ..
" vec3 Ks; ~n" + ..
" float Shininess; ~n" + ..
" }; ~n" + ..
" uniform int LightCount; ~n" + ..
" uniform LightInfo Lights[7]; ~n" + ..
" uniform vec3 LightPositions[7]; ~n" + ..
" uniform MaterialInfo Material; ~n" + ..
" //LIGHTING ~n" + ..
" ~n" + ..
" vec3 refl( vec3 s, vec3 n) ~n" + ..
" { ~n" + ..
" return -s + 2 * (dot(s,n)) * n; ~n" + ..
" } ~n" + ..
" ~n" + ..
" vec3 ads( int LightIndex ) ~n" + ..
" { ~n" + ..
" vec3 n = normalize(vertex_normal); ~n" + ..
" vec3 s = normalize(Lights[LightIndex].Position - vec3(Position)); ~n" + ..
" vec3 v = normalize(vec3(-Position)); ~n" + ..
" vec3 h = refl(-s,n);//normalize(v+s); ~n" + ..
" ~n" + ..
" return Lights[LightIndex].Intensity * ((Lights[LightIndex].La * Material.Ka) + (Lights[LightIndex].Ld * Material.Kd) * max(dot(s,n),0.0) + (Lights[LightIndex].Ls * Material.Ks) * pow(max(dot(h,n),0.0),Material.Shininess)); ~n" + ..
" } ~n" + ..
" ~n" + ..
" void main(void) { ~n" + ..
" ~n" + ..
" vec3 lcolor = vec3(0.0); ~n" + ..
" ~n" + ..
" for( int i = 0; i < LightCount; i++ ) ~n" + ..
" lcolor += ads(i); ~n" + ..
" ~n" + ..
" gl_FragColor = vec4(lcolor,1.0); ~n" + ..
" ~n" + ..
" } ~n"

Global NormalVert:String = " #version 120 ~n" + ..
" ~n" + ..
" //LIGHTING ~n" + ..
" struct LightInfo { ~n" + ..
" vec3 Position; ~n" + ..
" vec3 Intensity; ~n" + ..
" vec3 La; ~n" + ..
" vec3 Ld; ~n" + ..
" vec3 Ls; ~n" + ..
" }; ~n" + ..
" ~n" + ..
" struct MaterialInfo { ~n" + ..
" vec3 Ka; ~n" + ..
" vec3 Kd; ~n" + ..
" vec3 Ks; ~n" + ..
" float Shininess; ~n" + ..
" }; ~n" + ..
" uniform LightInfo Lights[7]; ~n" + ..
" uniform MaterialInfo Material; ~n" + ..
" //LIGHTING ~n" + ..
" ~n" + ..
" uniform vec3 LightPositions[7]; ~n" + ..
" uniform int LightCount; ~n" + ..
" ~n" + ..
" varying vec3 vertex_normal; ~n" + ..
" varying vec3 Position; ~n" + ..
" ~n" + ..
" //NORMAL MAPPING ~n" + ..
" uniform bool EnableNormalMap; ~n" + ..
" varying vec3 LightDir[7]; ~n" + ..
" varying vec3 ViewDir[7]; ~n" + ..
" //NORMAL MAPPING ~n" + ..
" ~n" + ..
" void main( void ) { ~n" + ..
" vertex_normal = normalize(gl_NormalMatrix * gl_Normal); ~n" + ..
" Position = vec3(gl_ModelViewMatrix * gl_Vertex); ~n" + ..
" ~n" + ..
" if (EnableNormalMap) ~n" + ..
" { ~n" + ..
" vec3 vertex_tangent = normalize(gl_NormalMatrix * vec3(gl_Color)); ~n" + ..
" vec3 vertex_binormal = normalize(cross(vertex_normal,vertex_tangent)) * gl_Color.w; ~n" + ..
" //vec3 vertex_binormal = normalize(cross(vertex_tangent,vertex_normal)) * gl_Color.w; ~n" + ..
" mat3 toObjectLocal = mat3( vertex_tangent.x,vertex_binormal.x,vertex_normal.x, ~n" + ..
" vertex_tangent.y,vertex_binormal.y,vertex_normal.y, ~n" + ..
" vertex_tangent.z,vertex_binormal.z,vertex_normal.z); ~n" + ..
" ~n" + ..
" for( int i = 0; i < LightCount; i++ ) ~n" + ..
" { ~n" + ..
" LightDir[i] = normalize(toObjectLocal * (Lights[i].Position - Position)); ~n" + ..
" ViewDir[i] = toObjectLocal * normalize(-Position); ~n" + ..
" } ~n" + ..
" } ~n" + ..
" ~n" + ..
" gl_FrontColor = vec4(1.0,1.0,1.0,1.0); ~n" + ..
" gl_TexCoord[0] = gl_MultiTexCoord0; ~n" + ..
" gl_Position = ftransform(); ~n" + ..
" } ~n"

Global NormalFrag:String = " #version 120 ~n" + ..
" ~n" + ..
" varying vec3 vertex_normal; ~n" + ..
" varying vec3 Position; ~n" + ..
" ~n" + ..
" //NORMAL MAPPING ~n" + ..
" uniform bool EnableNormalMap; ~n" + ..
" uniform sampler2D texture_normal; ~n" + ..
" varying vec3 ViewDir[7]; ~n" + ..
" varying vec3 LightDir[7]; ~n" + ..
" //NORMAL MAPPING ~n" + ..
" ~n" + ..
" //LIGHTING ~n" + ..
" struct LightInfo { ~n" + ..
" vec3 Position; ~n" + ..
" vec3 Intensity; ~n" + ..
" vec3 La; ~n" + ..
" vec3 Ld; ~n" + ..
" vec3 Ls; ~n" + ..
" }; ~n" + ..
" ~n" + ..
" struct MaterialInfo { ~n" + ..
" vec3 Ka; ~n" + ..
" vec3 Kd; ~n" + ..
" vec3 Ks; ~n" + ..
" float Shininess; ~n" + ..
" }; ~n" + ..
" uniform int LightCount; ~n" + ..
" uniform LightInfo Lights[7]; ~n" + ..
" uniform vec3 LightPositions[7]; ~n" + ..
" uniform MaterialInfo Material; ~n" + ..
" //LIGHTING ~n" + ..
" ~n" + ..
" vec3 refl( vec3 s, vec3 n) ~n" + ..
" { ~n" + ..
" return -s + 2 * (dot(s,n)) * n; ~n" + ..
" } ~n" + ..
" ~n" + ..
" vec3 adsn( vec3 norm, vec3 diffR, int LightIndex ) ~n" + ..
" { ~n" + ..
" vec3 n = normalize(norm); ~n" + ..
" vec3 s = normalize(Lights[LightIndex].Position - vec3(Position)); ~n" + ..
" vec3 v = normalize(vec3(-Position)); ~n" + ..
" vec3 h = refl(-LightDir[LightIndex],norm); ~n" + ..
" return Lights[LightIndex].Intensity * ((Lights[LightIndex].La * Material.Ka) + (Lights[LightIndex].Ld * Material.Kd) * max(dot(LightDir[LightIndex],n),0.0) + (Lights[LightIndex].Ls * Material.Ks) * pow(max(dot(h,ViewDir[LightIndex]),0.0),Material.Shininess)); ~n" + ..
" } ~n" + ..
" ~n" + ..
" ~n" + ..
" void main(void) { ~n" + ..
" ~n" + ..
" vec4 tex = vec4(0.0); ~n" + ..
" vec3 lcolor = vec3(0.0); ~n" + ..
" if (EnableNormalMap) ~n" + ..
" { ~n" + ..
" for( int i = 0; i < LightCount; i++ ) ~n" + ..
" lcolor += adsn(texture2D(texture_normal, gl_TexCoord[0].st).rgb,tex.rgb,i); ~n" + ..
" } ~n" + ..
" gl_FragColor = vec4(lcolor,1.0); ~n" + ..
" } ~n"

Graphics3D(800,600,0,2)
TShader.CheckCompatibility()
Local shad1:TShader = New TShader.Create(DiffuseVert,DiffuseFrag)
If shad1.Compiled Then Print "Full Shader Successfully Compiled" Else Print "Full Shader Failed To Compile"
Local shad2:TShader = New TShader.Create(ShadowVert,ShadowFrag)
If shad2.Compiled Then Print "Shadow Shader Successfully Compiled" Else Print "Shadow Shader Failed To Compile"
Local shad3:TShader = New TShader.Create(LightVert,LightFrag)
If shad3.Compiled Then Print "Light Shader Successfully Compiled" Else Print "Light Shader Failed To Compile"
Local shad4:TShader = New TShader.Create(NormalVert,NormalFrag)
If shad4.Compiled Then Print "Normal Map Shader Successfully Compiled" Else Print "Normal Map Shader Failed To Compile"




Print "Done"

Type TShader

Field ProgramObject:Int

Field Active:Byte = True

Field Compiled:Byte = False

Method Load:TShader(VertexPath:String, FragmentPath:String)

Local VertexCode:String, FragmentCode:String
Try
VertexCode = LoadText(VertexPath)
FragmentCode = LoadText(FragmentPath)
Catch Dummy:Object
DebugLog "Failed to Load Shader : " + VertexPath + " - " + FragmentPath
Return Null
EndTry

Create(VertexCode, FragmentCode)


Return Self
End Method

Method Create:TShader(VertexCode:String, FragmentCode:String)
If Not ProgramObject Then ProgramObject = glCreateProgram()

Local VertexShader :Int = glCreateShader(GL_VERTEX_SHADER)
Local FragmentShader:Int = glCreateShader(GL_FRAGMENT_SHADER)

Local ErrorMessage:String

_LoadShader(VertexCode, VertexShader)
glCompileShader(VertexShader)

If _CheckForErrors(VertexShader, ErrorMessage) Then
glDeleteShader(VertexShader)

Throw ErrorMessage
Return Self
EndIf

_LoadShader(FragmentCode, FragmentShader)
glCompileShader(FragmentShader)

If _CheckForErrors(FragmentShader, ErrorMessage) Then
glDeleteShader(VertexShader)
glDeleteShader(FragmentShader)

Throw ErrorMessage
Return Self
EndIf

glAttachShader(ProgramObject, VertexShader)
glAttachShader(ProgramObject, FragmentShader)



glDeleteShader(VertexShader)
glDeleteShader(FragmentShader)

glLinkProgram(ProgramObject)
If _CheckForErrors(ProgramObject, ErrorMessage, False)
Throw ErrorMessage
Return Self
EndIf



glValidateProgram(ProgramObject)

Local validated:Int
glGetProgramiv(ProgramObject, GL_VALIDATE_STATUS, Varptr validated)
If (validated)
DebugLog("Shader Validation Succeeded")
Else
DebugLog("Shader Failed to Validate")
_CheckForErrors(ProgramObject,ErrorMessage,True,False)
DebugLog("Validation Error: " + ErrorMessage)
EndIf

Compiled = True
Return Self
End Method


Method Enable()
glUseProgram(ProgramObject)
End Method

Method Disable()
glUseProgram(0)
End Method

Method Activate()
Self.Active = True
End Method

Method DeActivate()
Self.Active = False
End Method

Method GetUniformLocation:Int(Name:String)
Return glGetUniformLocationARB(ProgramObject, Name)
End Method

Method Delete()
glDeleteObjectARB(ProgramObject)
End Method

Function _LoadShader(ShaderCode:String, ShaderObject:Int)
Local ShaderCodeC:Byte Ptr = ShaderCode.ToCString()
Local ShaderCodeLen:Int = ShaderCode.Length

glShaderSource(ShaderObject, 1, Varptr ShaderCodeC, Varptr ShaderCodeLen)

MemFree(ShaderCodeC)
End Function

Function _CheckForErrors:Int(ShaderObject:Int, ErrorString:String Var, Compiled:Int = True, Validated:Int = True)
Local Successful:Int

If Compiled Then
glGetShaderiv(ShaderObject, GL_COMPILE_STATUS, Varptr Successful)
Else
glGetProgramiv(ShaderObject, GL_LINK_STATUS, Varptr Successful)
EndIf

If Not Validated Then
glGetProgramiv(ShaderObject, GL_VALIDATE_STATUS, Varptr Successful)
EndIf

If Not Successful Then
Local ErrorLength:Int
'glGetObjectParameterivARB(ShaderObject, GL_OBJECT_INFO_LOG_LENGTH_ARB, Varptr ErrorLength)
glGetShaderiv(ShaderObject,GL_INFO_LOG_LENGTH,Varptr ErrorLength)
Local Message:Byte Ptr = MemAlloc(ErrorLength), Dummy:Int

glGetInfoLogARB(ShaderObject, ErrorLength, Varptr Dummy, Message)

ErrorString = String.FromCString(Message)
MemFree(Message)

Return -1
EndIf

Return 0
End Function

Function CheckCompatibility:Int()
Local Extensions:String = String.FromCString(Byte Ptr glGetString(GL_EXTENSIONS))
Local GLVersion:String = String.FromCString(Byte Ptr glGetString(GL_VERSION))
Local GLVersionInt:Int = GLVersion[.. 3].Replace(".", "").ToInt()

DebugLog "GLVersion: " + GLVersion
DebugLog "iGLVerion: " + GLVersionInt

If Extensions.Find("GL_ARB_shader_objects" ) >= 0 And ..
Extensions.Find("GL_ARB_vertex_shader" ) >= 0 And ..
Extensions.Find("GL_ARB_fragment_shader") >= 0 Or GLVersionInt >= 20 Then Return True

Return False
End Function



End Type


')


Hotshot2005(Posted 2014) [#79]
Building untitled1
Compiling:untitled1.bmx
flat assembler version 1.69.14 (1118888 kilobytes memory)
4 passes, 51056 bytes.
Linking:untitled1.debug.exe
Warning: resolving _glewInit by linking to _glewInit@0
Use --enable-stdcall-fixup to disable these warnings
Use --disable-stdcall-fixup to disable these fixups
Executing:untitled1.debug.exe
DebugLog:GLVersion: 4.2.12217 Compatibility Profile Context 12.104.0.0
DebugLog:iGLVerion: 42
DebugLog:Shader Failed to Validate
DebugLog:Validation Error: 
Full Shader Successfully Compiled
DebugLog:Shader Validation Succeeded
Shadow Shader Successfully Compiled
DebugLog:Shader Validation Succeeded
Light Shader Successfully Compiled
DebugLog:Shader Validation Succeeded
Normal Map Shader Successfully Compiled
Done

Process complete

Keep going and dont give up :)


degac(Posted 2014) [#80]
Your latest source code.

format_codebox('

Linking:untitled2.debug.exe
Warning: resolving _glewInit by linking to _glewInit@0
Use --enable-stdcall-fixup to disable these warnings
Use --disable-stdcall-fixup to disable these fixups
Executing:untitled2.debug.exe
DebugLog:GLVersion: 4.1.10834 Compatibility Profile Context
DebugLog:iGLVerion: 41
DebugLog:Shader Validation Succeeded
Full Shader Successfully Compiled
DebugLog:Shader Validation Succeeded
Shadow Shader Successfully Compiled
DebugLog:Shader Validation Succeeded
Light Shader Successfully Compiled
DebugLog:Shader Validation Succeeded
Normal Map Shader Successfully Compiled
Done

Processo completato
')
(GPU: Radeon HD5700)


Brucey(Posted 2014) [#81]
So, shaders... bit of a grey area then whether they will work or not?


Banshee(Posted 2014) [#82]
Probably a bit too soon to say that Brucey, sometimes with shader engine setups and sometimes even in shaders it's a case of doing things the way that works for all cards. That's the nature of it. A bit like web coding with different browsers. Who hasn't heard a web dev saying "%#*$¥ Internet Explorer" at some point?

Posting on mobile tonight, so can't run the code until tomorrow.


impixi(Posted 2014) [#83]

So, shaders... bit of a grey area then whether they will work or not?



http://richg42.blogspot.co.uk/2014/05/the-truth-on-opengl-driver-quality.html

Apparently the OpenGL driver landscape overall is quite "grey".


Steve Elliott(Posted 2014) [#84]
http://richg42.blogspot.co.uk/2014/05/the-truth-on-opengl-driver-quality.html

Depressing reading.


degac(Posted 2014) [#85]
format_codebox('

Linking:untitled1.debug.exe
Warning: resolving _glewInit by linking to _glewInit@0
Use --enable-stdcall-fixup to disable these warnings
Use --disable-stdcall-fixup to disable these fixups
Executing:untitled1.debug.exe
DebugLog:GLVersion: 3.3.11672 Compatibility Profile Context
DebugLog:iGLVerion: 33
DebugLog:Shader Validation Succeeded
Full Shader Successfully Compiled
DebugLog:Shader Validation Succeeded
Shadow Shader Successfully Compiled
DebugLog:Shader Validation Succeeded
Light Shader Successfully Compiled
DebugLog:Shader Validation Succeeded
Normal Map Shader Successfully Compiled
Done
')
My dad's computer (Radeon3000 integrated)


KronosUK(Posted 2014) [#86]
format_codebox('
Building untitled1
Compiling:untitled1.bmx
flat assembler version 1.69.14 (1310719 kilobytes memory)
4 passes, 51009 bytes.
Linking:untitled1.debug.exe
Warning: resolving _glewInit by linking to _glewInit@0
Use --enable-stdcall-fixup to disable these warnings
Use --disable-stdcall-fixup to disable these fixups
Executing:untitled1.debug.exe
DebugLog:GLVersion: 4.3.12618 Compatibility Profile Context 13.251.0.0
DebugLog:iGLVerion: 43
DebugLog:Shader Failed to Validate
DebugLog:Validation Error: DebugLog%"~
Full Shader Successfully Compiled
DebugLog:Shader Validation Succeeded
Shadow Shader Successfully Compiled
DebugLog:Shader Validation Succeeded
Light Shader Successfully Compiled
DebugLog:Shader Validation Succeeded
Normal Map Shader Successfully Compiled
Done

Process complete
')

radeon HD 6800 series


JoshK(Posted 2014) [#87]
There's a GL shader log function that will tell you exactly what happened if a shader fails to compile, or if it can't validate. Most likely the vertex shader is writing to a varying the fragment shader doesn't have declared, or the fragment shader is reading one the vertex shader doesn't write to.


Banshee(Posted 2014) [#88]
format_code('
Building untitled1
Compiling:untitled1.bmx
flat assembler version 1.69.14 (1048575 kilobytes memory)
4 passes, 51056 bytes.
Linking:untitled1.debug.exe
Warning: resolving _glewInit by linking to _glewInit@0
Use --enable-stdcall-fixup to disable these warnings
Use --disable-stdcall-fixup to disable these fixups
Executing:untitled1.debug.exe
DebugLog:GLVersion: 4.3.0
DebugLog:iGLVerion: 43
DebugLog:Shader Validation Succeeded
Full Shader Successfully Compiled
DebugLog:Shader Validation Succeeded
Shadow Shader Successfully Compiled
DebugLog:Shader Validation Succeeded
Light Shader Successfully Compiled
DebugLog:Shader Validation Succeeded
Normal Map Shader Successfully Compiled
Done

Process complete
')
nVidia GeForce GTX 660 Ti


Hotshot2005(Posted 2014) [#89]
have you fixed the shaders for ATI 5870? :)

I would like check it again if been fixed


BLaBZ(Posted 2014) [#90]
Not yet, my day job keeps getting in the way. I'll post something soon :)


Hotshot2005(Posted 2014) [#91]
Take your time man as I am happy to help your work when you post it :-)


degac(Posted 2014) [#92]
Hi Blabz how is going everything?


BLaBZ(Posted 2014) [#93]
I haven't forgot about this! This weekend is a long weekend so hopefully I'll be able to get this up and running :) Thanks for your patience!


BLaBZ(Posted 2014) [#94]
Here's an update! I managed to get it to work on my ATI computer.

http://infotread.com/downloads/blabz.mod.zip


degac(Posted 2014) [#95]
Sorry to report bad news... but downloaded your latest Mod (re-installed Glew/OpenGL mod as you stated below)... your basic example (the cube) doesnt' work.
A black screen with Test123...
format_codebox('
untitled4.debug.exe
Warning: resolving _glewInit by linking to _glewInit@0
Use --enable-stdcall-fixup to disable these warnings
Use --disable-stdcall-fixup to disable these fixups
Executing:untitled4.debug.exe
DebugLog:Shader Validation Succeeded
DebugLog:Shader Validation Succeeded
DebugLog:Shader Validation Succeeded
DebugLog:Shader Validation Succeeded
DebugLog:Shader Validation Succeeded
DebugLog:Shader Validation Succeeded

Processo completato
')


KronosUK(Posted 2014) [#96]
Same result for me as before ie demo with cube works but when I add animated mesh I can only see its shadow.

If I rem out all the shadow and shadow camera commands I get the total black screen with 123 as described above. Program output as follows.

format_codebox('
Building blabztest
Compiling:blabztest.bmx
flat assembler version 1.69.14 (1310719 kilobytes memory)
3 passes, 7624 bytes.
Linking:blabztest.debug.exe
Warning: resolving _glewInit by linking to _glewInit@0
Use --enable-stdcall-fixup to disable these warnings
Use --disable-stdcall-fixup to disable these fixups
Executing:blabztest.debug.exe
DebugLog:Shader Validation Succeeded
DebugLog:Shader Validation Succeeded
DebugLog:Shader Failed to Validate
DebugLog:Validation Error: p0
DebugLog:Shader Validation Succeeded
DebugLog:Shader Validation Succeeded
DebugLog:Shader Validation Succeeded

Process terminated
')


Banshee(Posted 2014) [#97]
Still the same, I can run your cube demo fine but when I replace it with an animated b3d file I just get a black screen with "Test 123" in the corner regardless of using LoadMesh or LoadAnimMesh.

format_code('
Warning: resolving _glewInit by linking to _glewInit@0
Use --enable-stdcall-fixup to disable these warnings
Use --disable-stdcall-fixup to disable these fixups
Executing:shader-sample.debug.exe
DebugLog:GLVersion: 4.3.0
DebugLog:iGLVerion: 43
DebugLog:Shader Validation Succeeded
Full Shader Successfully Compiled
DebugLog:Shader Validation Succeeded
Shadow Shader Successfully Compiled
DebugLog:Shader Validation Succeeded
Light Shader Successfully Compiled
DebugLog:Shader Validation Succeeded
Normal Map Shader Successfully Compiled
Done
')


BLaBZ(Posted 2014) [#98]
Doh! Was passing some bad vertex attribute data, should work now :)

http://infotread.com/downloads/blabz.mod.zip


Brucey(Posted 2014) [#99]
Doh! Was passing some bad vertex attribute data, should work now

Did the new mod tell you that?


KronosUK(Posted 2014) [#100]
Did you mean to include all the source files in that zip Blabz?


BLaBZ(Posted 2014) [#101]
@Brucey, Nah, just something I overlooked

@KronusUK, Yah I included the source so if anyone wants to make any contributions they can.


Hotshot2005(Posted 2014) [#102]
Building untitled1
Compiling:untitled1.bmx
flat assembler version 1.69.14 (1364250 kilobytes memory)
4 passes, 51056 bytes.
Linking:untitled1.debug.exe
Warning: resolving _glewInit by linking to _glewInit@0
Use --enable-stdcall-fixup to disable these warnings
Use --disable-stdcall-fixup to disable these fixups
Executing:untitled1.debug.exe
DebugLog:GLVersion: 4.2.12217 Compatibility Profile Context 12.104.0.0
DebugLog:iGLVerion: 42
DebugLog:Shader Failed to Validate
DebugLog:Validation Error: DebugLog:iGLVeriÿ&#139;p[«¶
Full Shader Successfully Compiled
DebugLog:Shader Validation Succeeded
Shadow Shader Successfully Compiled
DebugLog:Shader Validation Succeeded
Light Shader Successfully Compiled
DebugLog:Shader Validation Succeeded
Normal Map Shader Successfully Compiled
Done


BLaBZ(Posted 2014) [#103]
@Hotshot, Try this! I didn't update the code above. :)

format_codebox('
SuperStrict

Import sidesign.minib3d

Global DiffuseVert:String = " #version 120 ~n" + ..
" ~n" + ..
" uniform bool FullBright; ~n" + ..
" uniform vec2 TexUVScale; ~n" + ..
" ~n" + ..
" ~n" + ..
" ~n" + ..
" uniform vec3 LightPositions[6]; ~n" + ..
" uniform int LightCount; ~n" + ..
" ~n" + ..
" varying vec3 vertex_normal; ~n" + ..
" varying vec3 Position; ~n" + ..
" ~n" + ..
" //SHADOW VARIABLES ~n" + ..
" uniform bool EnableShadow; ~n" + ..
" uniform mat4 ModelMatrix; ~n" + ..
" uniform mat4 ShadowMatrix; ~n" + ..
" uniform mat4 Bias; ~n" + ..
" uniform mat4 ShadowProjection; ~n" + ..
" uniform mat4 ShadowModelView; ~n" + ..
" varying vec4 ShadowCoord; ~n" + ..
" //SHADOW VARIABLES ~n" + ..
" ~n" + ..
" //NORMAL MAPPING ~n" + ..
" uniform bool EnableNormalMap; ~n" + ..
" varying vec3 LightDir[6]; ~n" + ..
" varying vec3 ViewDir[6]; ~n" + ..
" //NORMAL MAPPING ~n" + ..
" ~n" + ..
" //LIGHTING ~n" + ..
" struct LightInfo { ~n" + ..
" vec3 Position; ~n" + ..
" vec3 Intensity; ~n" + ..
" vec3 La; ~n" + ..
" vec3 Ld; ~n" + ..
" vec3 Ls; ~n" + ..
" }; ~n" + ..
" ~n" + ..
" struct MaterialInfo { ~n" + ..
" vec3 Ka; ~n" + ..
" vec3 Kd; ~n" + ..
" vec3 Ks; ~n" + ..
" float Shininess; ~n" + ..
" }; ~n" + ..
" uniform LightInfo Lights[6]; ~n" + ..
" uniform MaterialInfo Material; ~n" + ..
" //LIGHTING ~n" + ..
" ~n" + ..
" void main( void ) { ~n" + ..
" vertex_normal = normalize(gl_NormalMatrix * gl_Normal); ~n" + ..
" Position = vec3(gl_ModelViewMatrix * gl_Vertex); ~n" + ..
" if (EnableShadow) ~n" + ..
" { ~n" + ..
" ShadowCoord = Bias * ShadowProjection * ShadowModelView * ModelMatrix * gl_Vertex; ~n" + ..
" } ~n" + ..
" ~n" + ..
" if (EnableNormalMap) ~n" + ..
" { ~n" + ..
" vec3 vertex_tangent = normalize(gl_NormalMatrix * vec3(gl_Color)); ~n" + ..
" vec3 vertex_binormal = normalize(cross(vertex_normal,vertex_tangent)) * gl_Color.w; ~n" + ..
" //vec3 vertex_binormal = normalize(cross(vertex_tangent,vertex_normal)) * gl_Color.w; ~n" + ..
" mat3 toObjectLocal = mat3( vertex_tangent.x,vertex_binormal.x,vertex_normal.x, ~n" + ..
" vertex_tangent.y,vertex_binormal.y,vertex_normal.y, ~n" + ..
" vertex_tangent.z,vertex_binormal.z,vertex_normal.z); ~n" + ..
" ~n" + ..
" for( int i = 0; i < LightCount; i++ ) ~n" + ..
" { ~n" + ..
" LightDir[i] = normalize(toObjectLocal * (Lights[i].Position - Position)); ~n" + ..
" ViewDir[i] = toObjectLocal * normalize(-Position); ~n" + ..
" } ~n" + ..
" } ~n" + ..
" ~n" + ..
" gl_FrontColor = vec4(1.0f,1.0f,1.0f,1.0f); ~n" + ..
" gl_TexCoord[0] = gl_MultiTexCoord0 * vec4(TexUVScale,1.0f,1.0f); ~n" + ..
" gl_Position = ftransform(); ~n" + ..
" } ~n"

Global DiffuseFrag:String = " #version 120 ~n" + ..
" ~n" + ..
" uniform vec3 EntityColor; ~n" + ..
" uniform float EntityAlpha; ~n" + ..
" uniform bool FullBright; ~n" + ..
" ~n" + ..
" varying vec3 vertex_normal; ~n" + ..
" varying vec3 Position; ~n" + ..
" ~n" + ..
" //FOG VARIABLES ~n" + ..
" uniform bool EnableFog; ~n" + ..
" uniform vec3 FogColor; ~n" + ..
" uniform float FogStart; ~n" + ..
" uniform float FogEnd; ~n" + ..
" //FOG VARIABLES ~n" + ..
" ~n" + ..
" ~n" + ..
" //SHADOW VARIABLES ~n" + ..
" uniform bool EnableShadow; ~n" + ..
" uniform sampler2DShadow ShadowMap; ~n" + ..
" uniform int ShadowMapSize; ~n" + ..
" uniform float ShadowLightness; ~n" + ..
" varying vec4 ShadowCoord; ~n" + ..
" float xPixelOffset = 0.001f; ~n" + ..
" float yPixelOffset = 0.001f; ~n" + ..
" //SHADOW VARIABLES ~n" + ..
" ~n" + ..
" //DIFFUSE ~n" + ..
" uniform bool EnableDiffuseMap; ~n" + ..
" uniform sampler2D texture_diffuse; ~n" + ..
" //DIFFUSE ~n" + ..
" ~n" + ..
" //NORMAL MAPPING ~n" + ..
" uniform bool EnableNormalMap; ~n" + ..
" uniform sampler2D texture_normal; ~n" + ..
" varying vec3 LightDir[6]; ~n" + ..
" varying vec3 ViewDir[6]; ~n" + ..
" //NORMAL MAPPING ~n" + ..
" ~n" + ..
" ~n" + ..
" //LIGHTING ~n" + ..
" struct LightInfo { ~n" + ..
" vec3 Position; ~n" + ..
" vec3 Intensity; ~n" + ..
" vec3 La; ~n" + ..
" vec3 Ld; ~n" + ..
" vec3 Ls; ~n" + ..
" }; ~n" + ..
" ~n" + ..
" struct MaterialInfo { ~n" + ..
" vec3 Ka; ~n" + ..
" vec3 Kd; ~n" + ..
" vec3 Ks; ~n" + ..
" float Shininess; ~n" + ..
" }; ~n" + ..
" uniform int LightCount; ~n" + ..
" uniform LightInfo Lights[6]; ~n" + ..
" uniform vec3 LightPositions[6]; ~n" + ..
" uniform MaterialInfo Material; ~n" + ..
" //LIGHTING ~n" + ..
" ~n" + ..
" ~n" + ..
" vec3 refl( vec3 s, vec3 n) ~n" + ..
" { ~n" + ..
" return -s + 2 * (dot(s,n)) * n; ~n" + ..
" } ~n" + ..
" ~n" + ..
" vec3 ads( int LightIndex ) ~n" + ..
" { ~n" + ..
" vec3 n = normalize(vertex_normal); ~n" + ..
" vec3 s = normalize(Lights[LightIndex].Position - vec3(Position)); ~n" + ..
" vec3 v = normalize(vec3(-Position)); ~n" + ..
" vec3 h = refl(-s,n);//normalize(v+s); ~n" + ..
" ~n" + ..
" return Lights[LightIndex].Intensity * ((Lights[LightIndex].La * Material.Ka) + (Lights[LightIndex].Ld * Material.Kd) * max(dot(s,n),0.0f) + (Lights[LightIndex].Ls * Material.Ks) * pow(max(dot(h,n),0.0f),Material.Shininess)); ~n" + ..
" } ~n" + ..
" ~n" + ..
" vec3 adsn( vec3 norm, vec3 diffR, int LightIndex ) ~n" + ..
" { ~n" + ..
" vec3 n = normalize(norm); ~n" + ..
" vec3 s = normalize(Lights[LightIndex].Position - vec3(Position)); ~n" + ..
" vec3 v = normalize(vec3(-Position)); ~n" + ..
" vec3 h = refl(-LightDir[LightIndex],norm); ~n" + ..
" return Lights[LightIndex].Intensity * ((Lights[LightIndex].La * Material.Ka) + (Lights[LightIndex].Ld * Material.Kd) * max(dot(LightDir[LightIndex],n),0.0f) + (Lights[LightIndex].Ls * Material.Ks) * pow(max(dot(h,ViewDir[LightIndex]),0.0f),Material.Shininess)); ~n" + ..
" } ~n" + ..
" ~n" + ..
" float lookup( vec2 offSet) ~n" + ..
" { ~n" + ..
" return shadow2DProj(ShadowMap, ShadowCoord + vec4(offSet.x * xPixelOffset * ShadowCoord.w, offSet.y * yPixelOffset * ShadowCoord.w, 0.000025f, 0.0f) ).w; ~n" + ..
" } ~n" + ..
" ~n" + ..
" void main(void) { ~n" + ..
" ~n" + ..
" vec4 tex = vec4(0.0f); ~n" + ..
" if (EnableDiffuseMap) ~n" + ..
" { ~n" + ..
" tex = texture2D(texture_diffuse, gl_TexCoord[0].st).rgba; ~n" + ..
" } else { ~n" + ..
" tex = vec4(EntityColor.rgb,1.0f); ~n" + ..
" } ~n" + ..
" ~n" + ..
" vec3 lcolor = vec3(0.0f); ~n" + ..
" if (FullBright) ~n" + ..
" { ~n" + ..
" lcolor = tex.rgb; ~n" + ..
" } else { ~n" + ..
" if (EnableNormalMap) ~n" + ..
" { ~n" + ..
" for( int i = 0; i < LightCount; i++ ) ~n" + ..
" lcolor += adsn(texture2D(texture_normal, gl_TexCoord[0].st).rgb,tex.rgb,i); ~n" + ..
" } else { ~n" + ..
" for( int i = 0; i < LightCount; i++ ) ~n" + ..
" lcolor += ads(i); ~n" + ..
" } ~n" + ..
" } ~n" + ..
" ~n" + ..
" ~n" + ..
" float shadow; ~n" + ..
" if (EnableShadow) ~n" + ..
" { ~n" + ..
" // Avoid counter shadow ~n" + ..
" if (ShadowCoord.w > 1.0f) ~n" + ..
" { ~n" + ..
" float x,y; ~n" + ..
" for (y = -1.5f ; y <=1.5f ; y+=1.50f) ~n" + ..
" for (x = -1.5f ; x <=1.5f ; x+=1.50f) ~n" + ..
" shadow += lookup(vec2(x,y)); ~n" + ..
" ~n" + ..
" shadow /= 9.0f ; ~n" + ..
" } ~n" + ..
" } else { ~n" + ..
" shadow = 0.8f; ~n" + ..
" } ~n" + ..
" ~n" + ..
" lcolor = (shadow+ShadowLightness) * (lcolor * tex.rgb); ~n" + ..
" ~n" + ..
" if (EnableFog) ~n" + ..
" { ~n" + ..
" float dist = abs(Position.z); ~n" + ..
" float fogFactor = (FogEnd - dist) / (FogEnd - FogStart); ~n" + ..
" fogFactor = clamp(fogFactor,0.0f,1.0f); ~n" + ..
" lcolor = mix(FogColor,lcolor,fogFactor); ~n" + ..
" } ~n" + ..
" ~n" + ..
" if (tex.a < 0.15f) ~n" + ..
" { ~n" + ..
" discard; ~n" + ..
" } else { ~n" + ..
" gl_FragColor = vec4(lcolor,EntityAlpha); ~n" + ..
" } ~n" + ..
" } ~n"
Graphics3D(800,600,0,2)
TShader.CheckCompatibility()
Local shad1:TShader = New TShader.Create(DiffuseVert,DiffuseFrag)
If shad1.Compiled Then Print "Full Shader Successfully Compiled" Else Print "Full Shader Failed To Compile"




Print "Done"

Type TShader

Field ProgramObject:Int

Field Active:Byte = True

Field Compiled:Byte = False

Method Load:TShader(VertexPath:String, FragmentPath:String)

Local VertexCode:String, FragmentCode:String
Try
VertexCode = LoadText(VertexPath)
FragmentCode = LoadText(FragmentPath)
Catch Dummy:Object
DebugLog "Failed to Load Shader : " + VertexPath + " - " + FragmentPath
Return Null
EndTry

Create(VertexCode, FragmentCode)


Return Self
End Method

Method Create:TShader(VertexCode:String, FragmentCode:String)
If Not ProgramObject Then ProgramObject = glCreateProgram()

Local VertexShader :Int = glCreateShader(GL_VERTEX_SHADER)
Local FragmentShader:Int = glCreateShader(GL_FRAGMENT_SHADER)

Local ErrorMessage:String

_LoadShader(VertexCode, VertexShader)
glCompileShader(VertexShader)

If _CheckForErrors(VertexShader, ErrorMessage) Then
glDeleteShader(VertexShader)

Throw ErrorMessage
Return Self
EndIf

_LoadShader(FragmentCode, FragmentShader)
glCompileShader(FragmentShader)

If _CheckForErrors(FragmentShader, ErrorMessage) Then
glDeleteShader(VertexShader)
glDeleteShader(FragmentShader)

Throw ErrorMessage
Return Self
EndIf

glAttachShader(ProgramObject, VertexShader)
glAttachShader(ProgramObject, FragmentShader)



glDeleteShader(VertexShader)
glDeleteShader(FragmentShader)

glLinkProgram(ProgramObject)
If _CheckForErrors(ProgramObject, ErrorMessage, False)
Throw ErrorMessage
Return Self
EndIf



glValidateProgram(ProgramObject)

Local validated:Int
glGetProgramiv(ProgramObject, GL_VALIDATE_STATUS, Varptr validated)
If (validated)
DebugLog("Shader Validation Succeeded")
Else
DebugLog("Shader Failed to Validate")
_CheckForErrors(ProgramObject,ErrorMessage,True,False)
DebugLog("Validation Error: " + ErrorMessage)
EndIf

Compiled = True
Return Self
End Method


Method Enable()
glUseProgram(ProgramObject)
End Method

Method Disable()
glUseProgram(0)
End Method

Method Activate()
Self.Active = True
End Method

Method DeActivate()
Self.Active = False
End Method

Method GetUniformLocation:Int(Name:String)
Return glGetUniformLocationARB(ProgramObject, Name)
End Method

Method Delete()
glDeleteObjectARB(ProgramObject)
End Method

Function _LoadShader(ShaderCode:String, ShaderObject:Int)
Local ShaderCodeC:Byte Ptr = ShaderCode.ToCString()
Local ShaderCodeLen:Int = ShaderCode.Length

glShaderSource(ShaderObject, 1, Varptr ShaderCodeC, Varptr ShaderCodeLen)

MemFree(ShaderCodeC)
End Function

Function _CheckForErrors:Int(ShaderObject:Int, ErrorString:String Var, Compiled:Int = True, Validated:Int = True)
Local Successful:Int

If Compiled Then
glGetShaderiv(ShaderObject, GL_COMPILE_STATUS, Varptr Successful)
Else
glGetProgramiv(ShaderObject, GL_LINK_STATUS, Varptr Successful)
EndIf

If Not Validated Then
glGetProgramiv(ShaderObject, GL_VALIDATE_STATUS, Varptr Successful)
EndIf

If Not Successful Then
Local ErrorLength:Int
'glGetObjectParameterivARB(ShaderObject, GL_OBJECT_INFO_LOG_LENGTH_ARB, Varptr ErrorLength)
glGetShaderiv(ShaderObject,GL_INFO_LOG_LENGTH,Varptr ErrorLength)
Local Message:Byte Ptr = MemAlloc(ErrorLength), Dummy:Int

glGetInfoLogARB(ShaderObject, ErrorLength, Varptr Dummy, Message)

ErrorString = String.FromCString(Message)
MemFree(Message)

Return -1
EndIf

Return 0
End Function

Function CheckCompatibility:Int()
Local Extensions:String = String.FromCString(Byte Ptr glGetString(GL_EXTENSIONS))
Local GLVersion:String = String.FromCString(Byte Ptr glGetString(GL_VERSION))
Local GLVersionInt:Int = GLVersion[.. 3].Replace(".", "").ToInt()

DebugLog "GLVersion: " + GLVersion
DebugLog "iGLVerion: " + GLVersionInt

If Extensions.Find("GL_ARB_shader_objects" ) >= 0 And ..
Extensions.Find("GL_ARB_vertex_shader" ) >= 0 And ..
Extensions.Find("GL_ARB_fragment_shader") >= 0 Or GLVersionInt >= 20 Then Return True

Return False
End Function



End Type


')


Banshee(Posted 2014) [#104]
OMG it works it works it works!

*has a kitten*

Okay. Sticking to the plan I must do housework, but then I'm going to knock up a simple game and make sure everything works - and then and then and then.... THE WORLD!


KronosUK(Posted 2014) [#105]
"Yah I included the source so if anyone wants to make any contributions they can. "

Thanks for this. I did a clean install of Minib3d and I can now see my animated mesh although it has lost its textures somewhere. Still get the 3rd shader validation failure as well.

I'll have a little dig around in your code to see If I can see whats happening.

edit:manually adding the texture seems to work


degac(Posted 2014) [#106]
Still no luck here. Same black screen...
format_codebox('
Linking:untitled3.debug.exe
Warning: resolving _glewInit by linking to _glewInit@0
Use --enable-stdcall-fixup to disable these warnings
Use --disable-stdcall-fixup to disable these fixups
Executing:untitled3.debug.exe
DebugLog:GLVersion: 3.3.11672 Compatibility Profile Context
DebugLog:iGLVerion: 33
DebugLog:Shader Validation Succeeded
Full Shader Successfully Compiled
Done
')

:(

Anyway thanks for including source... maybe I learn something!


KronosUK(Posted 2014) [#107]
Is normal mapping switched on by default? Is that what the diffuse shader does?
I still get a validation error on the diffuse shader although everything looks like its working except I can't see any normal mapping. I have applied a colour texture and a normal map texture on slots 0 and 1 respectively.

I also notice that when you move the camera behind the wall you can still see the shadow coming through the wall.

format_codebox('
Building untitled1
Compiling:untitled1.bmx
flat assembler version 1.69.14 (1310719 kilobytes memory)
4 passes, 32704 bytes.
Linking:untitled1.debug.exe
Warning: resolving _glewInit by linking to _glewInit@0
Use --enable-stdcall-fixup to disable these warnings
Use --disable-stdcall-fixup to disable these fixups
Executing:untitled1.debug.exe
DebugLog:GLVersion: 4.3.12618 Compatibility Profile Context 13.251.0.0
DebugLog:iGLVerion: 43
DebugLog:Shader Failed to Validate
DebugLog:Validation Error: &#64555;
Full Shader Successfully Compiled
Done

Process complete
')


Ok I changed the shader checker to this
format_codebox('
If Not Successful Then
Local ErrorLength:Int
glGetObjectParameterivARB(ShaderObject, GL_OBJECT_INFO_LOG_LENGTH_ARB, Varptr ErrorLength)
'glGetShaderiv(ShaderObject,GL_INFO_LOG_LENGTH,Varptr ErrorLength)
Local Message:Byte Ptr = MemAlloc(ErrorLength), Dummy:Int

glGetInfoLogARB(ShaderObject, ErrorLength, Varptr Dummy, Message)

ErrorString = String.FromCString(Message)
MemFree(Message)

Return -1
EndIf

')

and now I get this more meaningfull message on the diffuse validation

"Different sampler types for same sample texture unit in fragment shader."

edit2:

Seems to be this bit in diffuse.frag that causes the error

format_codebox('
float lookup( vec2 offSet)
{
shadow2DProj(ShadowMap, ShadowCoord + vec4(offSet.x * xPixelOffset * ShadowCoord.w, offSet.y * yPixelOffset * ShadowCoord.w, 0.000025f, 0.0f) ).w;
}
')


Banshee(Posted 2014) [#108]
I've started working on a simple game with this engine, something I can knock up in a few weeks rather than the big monstrosity of my main project - if all goes well then I'll use it for my main project too :)

I'll post any issues I find.

Starting with: Could not create multiple cameras. So I worked around by calling RenderWorldX() twice and just moving the camera inbetween. But it made me wonder if rendering to texture would be an issue, but I've not got far enough to find out yet.


Banshee(Posted 2014) [#109]
I'm somewhat befuddled by how to set up the lighting. Firstly if I disable shadows a standard directional light seems to change direction as I turn the camera.

Then when I enable them, well I'm confused as to what I should do...



Here's some simple code, execute code/mainfile.bmx to run. The lighting setup is in scene.bmx (don't panic, they're small files :P) Use WASD keys.

http://beckyrose.com/TankedUp.zip

Note this is a special low poly mesh for test purposes. The game mesh has lots more detail and no holes in it but it's much larger and slower loading but it has the same problem - so I put a low poly one in.


Hotshot2005(Posted 2014) [#110]
Very good....500FPS !


Derron(Posted 2014) [#111]
First of all: tested on Linux Mint Petra, 64Bit.
Processor: AMD Llano - gpu builtin.


It might have a corrupt display when using a smaller resolution (800x600, wanted to have better screenshots), happened also with the given one (1024x768). During "startup" the display of the app window is flickering for some milliseconds - but only if the result is "ok" then. Without "flickering" I get those corrupt screens :

corrupt one:
format_code('
./bmk makeapp -t console -d -x "minib3dplus.mod/Test.bmx"
Compiling:Test.bmx
flat assembler version 1.68 (1048560 kilobytes memory)
4 passes, 6414 bytes.
Linking:Test
Executing:Test
DebugLog:Shader Validation Succeeded
DebugLog:Shader Validation Succeeded
DebugLog:Shader Failed to Validate
DebugLog:Validation Error:
DebugLog:Shader Validation Succeeded
DebugLog:Shader Validation Succeeded
DebugLog:Shader Validation Succeeded
Kompilierung erfolgreich beendet.
')


working one:
format_code('
./bmk makeapp -t console -d -x "minib3dplus.mod/Test.bmx"
Compiling:Test.bmx
flat assembler version 1.68 (1048560 kilobytes memory)
4 passes, 6414 bytes.
Linking:Test
Executing:Test
DebugLog:Shader Validation Succeeded
DebugLog:Shader Validation Succeeded
DebugLog:Shader Failed to Validate
DebugLog:Validation Error: 0r
\UffffffffebugLog:Shader Validation Succeeded
DebugLog:Shader Validation Succeeded
DebugLog:Shader Validation Succeeded
Kompilierung erfolgreich beendet.
')


Screenshot "okay" (I assume so):


Screenshot "broken":
(also pay attention to the "DEMO"-text being bigger than in the other ones)
...edit: ok just saw that I used the 800x600 screenshot with a wrong labeling, maybe that is why the text is bigger (did not check if you use "pixels" or "points" as size)


Screenshot "broken" with other aspect ratio (works sometimes):




As I have varying output there must be something strange happening in your code (initialization).


bye
Ron


BLaBZ(Posted 2014) [#112]
@KronusUK, If a texture is applied to slot 1 it will enable normal mapping, right now it's missing the tangent space calculations, so if you have a normal map, the mapping will look incorrect. I'm working on adding these.

The reason you may not see the mesh textured at first is because it only honors the texture mapped to slot 1.

That's a much better error message, I'm looking into it.

@Banshee, looking into it!


BLaBZ(Posted 2014) [#113]
@Derron, Very odd, I did notice there were some issues attaching the texture to the shadow FBO on my ATI card, this also looks related to what kronusUK pointed out as the shadows aren't mapping correctly.


degac(Posted 2014) [#114]
Tested on my computer (AMD HD5450).. basic test failed (black screen).
I downloaded Banshee's example... and it works*. I really dont' understand why a simple cube shows nothing... (I must disable AntiAliasing otherwise black screen)

* I mean I see the land on the screen, the sun etc. I cant' understand if 'shadows' are right or not...


degac(Posted 2014) [#115]
I just tested the 'basic' example commenting out EnableAntiAliasing... and now it works! At least I know what is the problem :D

edit

After some experiments, I noticed that

BLOOM works
AMBIENT OCCLUSION works (or I think so)
ANTIALIASING - nothing (black screen)
SHADOW - weird results...


Banshee(Posted 2014) [#116]
I mean I see the land on the screen, the sun etc. I cant' understand if 'shadows' are right or not...

They're not, and in fairness I think it is because I am doing it wrong rather than a problem with the engine - but I haven't figured out yet how it should work. Some kind of pivot to the front/side of the camera maybe orthographic camera?

The lighting however is an issue, I suspect a problem in the fragment shader with the vertex normals when a normal map is not used or something similar to that. But I've not dug into the shaders yet.

I wouldn't mind writing a splat shader, but the way the engine is setup means making shaders is going to be quite a lot of work and I suspect Blabz is planning to add better support further on so I left it for now.


BLaBZ(Posted 2014) [#117]
@Banshee, is there a texture in slot 1? If there is it won't interpret the lighting properly.


Banshee(Posted 2014) [#118]
I threw a mid-grey pixel on to texture slot 1 just to get something on there and it looked much the same. I'll try making a proper normal map next session when I have my other computer to hand (all I got on this one is MS Paint!).


BLaBZ(Posted 2014) [#119]
My recent discovery is that the sampler2dShadow uniforms aren't being recognized by the compiler and are "optimized" out, making the shadow uniforms inactive.

My only solution is to query the shader for active uniforms and if doesn't find the "ShadowMap" uniform to disable shadows.

Very odd and frustrating. Wish I knew of a better solution.


LT(Posted 2014) [#120]
Shadow mapping can be done without using sampler2dShadow. You have to do a bit more with the shaders, though.


degac(Posted 2014) [#121]
Question:
I'm looking at the source code of Tminib3dplus.bmx
format_codebox('
Function RenderWorld()
'Render shadows first
For Local cam:TCamera=EachIn TCamera.cam_list
'If cam.parent_hidden=True Or cam.hidden=True Then Continue
If cam.Hidden()=True Then Continue
Local ce:TCameraExtension = TCameraExtension.GetExtension(cam)
'if camera doesn't have extension create it and continue
If ce = Null
TCameraExtension.CreateExtension(cam)
Continue
EndIf
If ce.IsShadow
ce.Update()'<---- in RenderCamera
RenderCamera(ce)
EndIf
Next

'Render scene
For Local cam:TCamera=EachIn TCamera.cam_list
'If cam.parent_hidden=True Or cam.hidden=True Then Continue
If cam.Hidden()=True Then Continue
Local ce:TCameraExtension = TCameraExtension.GetExtension(cam)
If ce.IsShadow = False
ce.Update() '<---- in RenderCamera
RenderCamera(ce)
EndIf
Next

')
To me it seems there is a double call to the method Update() - I just commented it out and nothing is 'break' in normal rendering
(by the way I cant' see shadows, and with this change a get 'different' visual errors now - all the mesh are covered by 'black points'...)


BLaBZ(Posted 2014) [#122]
@degac, there's only 1 render call to each camera, first the shadow cameras need to render then the non-shadow cameras.

I've put a fix in place to correct the shadow issues you'r seeing, I'll be uploading it soon.


Derron(Posted 2014) [#123]
Think the question about the need of multiple loops is valid:

shouldnt it be possible to sort the lists by "shadow" or "not shadow" (shadow comes first)
If possible, this skips:
- need to allocate "ce:TCameraExtension" multiple times.
- need to check "Hidden()" multiple times
- "if isShadow"-checks

Of course this does not work as soon as something within the "handle shadow cameras"-loop could change the visibility of other cameras.

All it needs is a helping function (TCamera.Add(cam)) which adds the given cam to a list and sorts this list then. TCamera just needs a custom compare method so they sort by "isShadow" and/or other values.


bye
Ron


BLaBZ(Posted 2014) [#124]
Valid point! I'll add this. :)

If you see anything else let me know!


BLaBZ(Posted 2014) [#125]
Sorry for the delay! Lots of fixes in this update,

Fixed multiple camera and CameraViewport issues
Screen Space Ambient Occlusion renders a quarter of the screen and then blurs, improving performance and quality
Fixed Normal Map rendering by adding tangent calculations
Improved performance of shadow render by only rendering depth
Fixed shadow issues where ATI cards weren't recognizing sampler2DShadow as an active uniform by creating a fallback shader
Fixed Anti aliasing showing black screen by querying for max number of samples and setting it to 8 if possible.

Let me know if you guys see any further issues! Thanks for your patience :)

http://infotread.com/downloads/blabz.mod.zip


xlsior(Posted 2014) [#126]
note sure what I'm missing:


Compiling:minib3dplus.bmx
Compile Error: Identifier 'GL_TEXTURE_2D_MULTISAMPLE' not found
[c:/Code/Blitzmax/mod/blabz.mod/minib3dplus.mod/TCameraExtension.bmx;347;4]
Build Error: failed to compile c:/Code/Blitzmax/mod/blabz.mod/minib3dplus.mod/minib3dplus.bmx




BLaBZ(Posted 2014) [#127]
You need the latest version of glew and opengl -

http://infotread.com/downloads/pub.mod.zip


xlsior(Posted 2014) [#128]
You need the latest version of glew and opengl -

http://infotread.com/downloads/pub.mod.zip


Thanks


degac(Posted 2014) [#129]
Yea!
It works on my ATI card (HD5750)
Well done! :D


degac(Posted 2014) [#130]
I did some experiments with you mod on my computer.
I found a way (dont' know if 'right'...) to have 'smoother' shadow's border.
I replaced (with 2 uniform PassMax and StepPass) in the frag shader

format_codebox('
if (ShadowCoord.w > 1.0f)
{
float x,y;
for (y = -1.5f ; y <=1.5f ; y+=steppass)
for (x = -1.5f ; x <=1.5f ; x+=steppass)
shadow += lookup2(vec2(x,y));

shadow /= maxpass;
}

')
Your value was stepPass 1.5, MaxPass=9 (to have a middle value).
I changed CameraShadow() function to pass different values (and put it in TcameraExtension as field of cam_shad).
So with stepPass 0.5 and MaxPass 27 (3x) I get a very smooth shadows border, but all the image seems to be 'lighter' than before.

But I have another problem: shadows are not always shown... just 'clipped'

format_codebox('
SuperStrict

Import sidesign.minib3d
Import blabz.minib3dplus


'Graphics3D(1024,768,16,2)
Graphics3D 800,600,32,2
CreateWorld()

Local cam:TCamera = CreateCamera()
PositionEntity(cam,5,5,-5)

Local shad:TCamera = CreateCamera()
PositionEntity(shad,0,20,-30)
CameraShadow(shad,True)',1,27.0)

Local light:TLight = CreateLight()
PositionEntity(light,0,20,-30)

Local pivot:Tentity=CreatePivot()
Local pivot_dummy:Tentity=CreateCube()
EntityParent pivot_dummy,pivot
PositionEntity pivot,0,20,-30
MoveEntity pivot_dummy,0,-5,0
ScaleEntity pivot,.2,.2,.2


Local cube:TMesh = CreateCube()
PositionEntity(cube,0,0,10)
EntityColor(cube,255,0,0)
PointEntity(cam,cube)
PointEntity(shad,cube)


Local txt_d:Ttexture=LoadTexture("res/bricks.jpg")
Local txt_n:Ttexture=LoadTexture("res/bricks_bump.jpg")

EntityTexture cube,txt_d,0,0
EntityTexture cube,txt_n,0,1



Local ground:TMesh = CreateCube()
PositionEntity(ground,0,-5,0)
ScaleEntity(ground,20,0.5,20)

Local wall:TMesh = CreateCube()
PositionEntity(wall,0,0,20)
ScaleEntity(wall,20,10,0.5)
'EntityColor(wall,0,0,255)

EntityTexture wall,txt_d,0,0
EntityTexture wall,txt_n,0,1


wall=CreateCube()
ScaleEntity(wall,20,10,0.5)
RotateEntity wall,0,90,0
PositionEntity wall,20,0,0
EntityTexture wall,txt_d,0,0
EntityTexture wall,txt_n,0,1

wall=CreateCube()
ScaleEntity(wall,20,10,0.5)
RotateEntity wall,0,90,0
PositionEntity wall,-20,0,0
EntityTexture wall,txt_d,0,0
EntityTexture wall,txt_n,0,1


wall=CreateCube()
ScaleEntity(wall,5,3,5)
PositionEntity wall,0,-4,-5
EntityTexture wall,txt_d,0,0
EntityTexture wall,txt_n,0,1






Local c1:Tmesh
For Local ss:Int=1 To 10

c1=CreateCube()
PositionEntity c1,ss-5,5+Float(ss)*.1,5
ScaleEntity c1,.25,2.15,.55
EntityColor c1,200+ss*10,200,100

Next

Local col:tmesh[4]

col[0]=CreateCylinder()
col[1]=CreateCylinder()
col[2]=CreateCylinder()
col[3]=CreateCylinder()


ScaleEntity col[0],1.0,5,1.0
ScaleEntity col[1],1.0,5,1.0
ScaleEntity col[2],1.0,5,1.0
ScaleEntity col[3],1.0,5,1.0

PositionEntity col[0],-10,0,5
PositionEntity col[1],10,0,5
PositionEntity col[2],-10,0,-15
PositionEntity col[3],10,0,-15

For Local n:Int=0 To 3
EntityTexture col[n],txt_d,0,0
EntityTexture col[n],txt_n,0,1
Next






Local lastTime:Int , time:Int , fps:Int
Global delta:Float


Local txt_specular:Ttexture= LoadTexture("res/Road_Specular.png")
Local txt_diffuse:Ttexture= LoadTexture("res/Road_diffuse.png")

TextureBlend txt_specular,3

EntityTexture ground,txt_d,0,0
EntityTexture ground,txt_n,0,1
'EntityFX ground,32

Local mxs:Float,mys:Float
Local fx_state:Int[4]

Local ly:Float=0,dly:Float=0.05,light_move:Int=1
Local t:Int=MilliSecs()
While Not KeyHit(KEY_ESCAPE)

TurnEntity(cube,0.1,0.1,0.1)
mxs#=mxs#+(MouseXSpeed()/5.0)
mys#=mys#+(MouseYSpeed()/5.0)
RotateEntity cam,mys#,-mxs#,0
MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
MouseXSpeed() ;' flush
MouseYSpeed() ;' flush

MoveEntity cam , KeyDown(KEY_D) - KeyDown(KEY_A) , 0 , KeyDown(KEY_W) - KeyDown(KEY_S)

If KeyHit(KEY_F1) fx_state[0]=1-fx_state[0]
If KeyHit(KEY_F2) fx_state[1]=1-fx_state[1]
If KeyHit(KEY_F3) fx_state[2]=1-fx_state[2]
If KeyHit(KEY_F4) fx_state[3]=1-fx_state[3]

If KeyHit(KEY_SPACE) light_move=1-light_move

If fx_state[0]=1
EnableAntiAliasing()
Else
DisableAntiAliasing()
End If

If fx_state[1]=1
EnableBloom()
Else
DisableBloom()
End If

If fx_state[2]=1
EnableShadows()
Else
DisableShadows()
End If

If fx_state[3]=1
EnableAmbientOcclusion()
Else
DisableAmbientOcclusion()
End If
If light_move=1
MoveEntity light,dly,0,0',ly,0
MoveEntity pivot,dly,0,0'0,ly,0
MoveEntity shad,dly,0,0
ly=ly+dly

If ly<-50 dly=.05
If ly>50 dly=-.05
End If
RenderWorldX()

BeginMax2d()
DrawText("f1: AntiAliasing : "+fx_state[0],0,0)
DrawText("f2: Bloom : "+fx_state[1],0,10)
DrawText("f3: Shadows : "+fx_state[2],0,20)
DrawText("f4: AmbientOcclusion : "+fx_state[3],0,30)
DrawText "FPS: "+fps,300,0

EndMax2d()

Flip
Cls

time = MilliSecs()
delta = time - lastTime
lastTime = time

If( delta > 0 ) Then fps = 1000.0 / delta


Wend
')

You can enable/disable FX with Function keys (1..4) and stop/run the light's movement with SPACE

You need 2 texture (diffuse+normal) otherwise I think you get some errors.

ps: the 'bump' fx works correctly? it seems to be a little bit too much reflective...

pps:
I think it will be useful to change some value you can pass to the .frag shader (like ShadowMap size). Dont' know the 'best' way to do it (too much commands maybe!)


Krischan(Posted 2014) [#131]
Hmm nice. But I have a problem with alpha textures in my current project testing your module extension. The example from degac works fine. I've just recompiled the module and added the extension commands like that (shortened).

With RenderworldX() I'm getting a "alphaless" overbright scene, with Renderworld() I see the vanilla minib3d without any changes, please take a look at the screenshots:

Vanilla miniB3D as it should look like
MiniB3D Plus looks like alpha is being lost

My Code Structure:
format_code('SuperStrict

Framework sidesign.minib3d
Import blabz.minib3dplus

Graphics3D 2560, 1440, 32, 1
CreateWorld()

[...]

EnableBloom()

RenderWorldX()

BeginMax2D()

EndMax2D()

Flip')

Nothing else has been changed in my project. The planet consists of a spherified cube with FX 2 and five additional meshes with alpha flag 2+32 and applied different detail textures (base layer, detail1, detail2) to each of them. The milkyway Background has alpha flag 2+32 and some detail textures, with Entityorder.


degac(Posted 2014) [#132]
I take a screenshot to show:

1. bump-fx... strange
2. shadow clipping




degac(Posted 2014) [#133]
Ok, I think I found the (my) problem.
I forget to use EntityFx and TextureBlend to setup correctly the textures.



Btw everything seems very 'dark' and I still dont' understand if there is (or not) the 'bump fx' on the texture...

But the 'shadow clipping' problem is still here.

format_codebox('
SuperStrict

Import sidesign.minib3d
Import blabz.minib3dplus


'Graphics3D(1024,768,16,2)
Graphics3D 800,600,32,2
CreateWorld()

Local cam:TCamera = CreateCamera()
PositionEntity(cam,5,5,-5)

Local shad:TCamera = CreateCamera()
PositionEntity(shad,0,20,-30)
CameraShadow(shad,True)',1,27.0)

Local light:TLight = CreateLight()
PositionEntity(light,0,20,-30)

Local pivot:Tentity=CreatePivot()
Local pivot_dummy:Tentity=CreateCube()
EntityParent pivot_dummy,pivot
PositionEntity pivot,0,20,-30
MoveEntity pivot_dummy,0,-5,0
ScaleEntity pivot,.2,.2,.2


Local cube:TMesh = CreateCube()
PositionEntity(cube,0,0,10)
EntityColor(cube,255,0,0)
PointEntity(cam,cube)
PointEntity(shad,cube)


Local txt_d:Ttexture=LoadTexture("res/bricks.jpg")
Local txt_n:Ttexture=LoadTexture("res/bricks_bump.jpg")

TextureBlend txt_d,2
TextureBlend txt_n,4

EntityTexture cube,txt_d,0,0
EntityTexture cube,txt_n,0,1



Local ground:TMesh = CreateCube()
PositionEntity(ground,0,-5,0)
ScaleEntity(ground,20,0.5,20)
EntityFX ground,1
EntityTexture ground,txt_d,0,0
EntityTexture ground,txt_n,0,1

Local wall:TMesh = CreateCube()
PositionEntity(wall,0,0,20)
ScaleEntity(wall,20,10,0.5)
'EntityColor(wall,0,0,255)
EntityFX wall,1

EntityTexture wall,txt_d,0,0
EntityTexture wall,txt_n,0,1


wall=CreateCube()
ScaleEntity(wall,20,10,0.5)
RotateEntity wall,0,90,0
PositionEntity wall,20,0,0
EntityFX wall,1
EntityTexture wall,txt_d,0,0
EntityTexture wall,txt_n,0,1

wall=CreateCube()
ScaleEntity(wall,20,10,0.5)
RotateEntity wall,0,90,0
EntityFX wall,1
PositionEntity wall,-20,0,0
EntityTexture wall,txt_d,0,0
EntityTexture wall,txt_n,0,1


wall=CreateCube()
ScaleEntity(wall,5,3,5)
PositionEntity wall,0,-4,-5
EntityFX wall,1
EntityTexture wall,txt_d,0,0
EntityTexture wall,txt_n,0,1






Local c1:Tmesh
For Local ss:Int=1 To 10

c1=CreateCube()
PositionEntity c1,ss-5,5+Float(ss)*.1,5
ScaleEntity c1,.25,2.15,.55
EntityColor c1,200+ss*10,200,100

Next

Local col:tmesh[4]

col[0]=CreateCylinder()
col[1]=CreateCylinder()
col[2]=CreateCylinder()
col[3]=CreateCylinder()


ScaleEntity col[0],1.0,5,1.0
ScaleEntity col[1],1.0,5,1.0
ScaleEntity col[2],1.0,5,1.0
ScaleEntity col[3],1.0,5,1.0

PositionEntity col[0],-10,0,5
PositionEntity col[1],10,0,5
PositionEntity col[2],-10,0,-15
PositionEntity col[3],10,0,-15

For Local n:Int=0 To 3
EntityFX col[n],1
EntityTexture col[n],txt_d,0,0
EntityTexture col[n],txt_n,0,1

Next






Local lastTime:Int , time:Int , fps:Int
Global delta:Float
Local mxs:Float,mys:Float
Local fx_state:Int[4]

Local ly:Float=0,dly:Float=0.05,light_move:Int=1
Local t:Int=MilliSecs()
While Not KeyHit(KEY_ESCAPE)

TurnEntity(cube,0.1,0.1,0.1)
mxs#=mxs#+(MouseXSpeed()/5.0)
mys#=mys#+(MouseYSpeed()/5.0)
RotateEntity cam,mys#,-mxs#,0
MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
MouseXSpeed() ;' flush
MouseYSpeed() ;' flush

MoveEntity cam , KeyDown(KEY_D) - KeyDown(KEY_A) , 0 , KeyDown(KEY_W) - KeyDown(KEY_S)

If KeyHit(KEY_F1) fx_state[0]=1-fx_state[0]
If KeyHit(KEY_F2) fx_state[1]=1-fx_state[1]
If KeyHit(KEY_F3) fx_state[2]=1-fx_state[2]
If KeyHit(KEY_F4) fx_state[3]=1-fx_state[3]

If KeyHit(KEY_SPACE) light_move=1-light_move

If fx_state[0]=1
EnableAntiAliasing()
Else
DisableAntiAliasing()
End If

If fx_state[1]=1
EnableBloom()
Else
DisableBloom()
End If

If fx_state[2]=1
EnableShadows()
Else
DisableShadows()
End If

If fx_state[3]=1
EnableAmbientOcclusion()
Else
DisableAmbientOcclusion()
End If
If light_move=1
MoveEntity light,dly,0,0',ly,0
MoveEntity pivot,dly,0,0'0,ly,0
MoveEntity shad,dly,0,0
ly=ly+dly

If ly<-50 dly=.05
If ly>50 dly=-.05
End If
RenderWorldX()

BeginMax2d()
DrawText("f1: AntiAliasing : "+fx_state[0],0,0)
DrawText("f2: Bloom : "+fx_state[1],0,10)
DrawText("f3: Shadows : "+fx_state[2],0,20)
DrawText("f4: AmbientOcclusion : "+fx_state[3],0,30)
DrawText "FPS: "+fps,300,0

EndMax2d()

Flip
Cls

time = MilliSecs()
delta = time - lastTime
lastTime = time

If( delta > 0 ) Then fps = 1000.0 / delta


Wend
')


BLaBZ(Posted 2014) [#134]
@Krischan sorry for the delay, try to enable HDR and lower the HDR Exposure, or Change your lights Intensity

format_code('
EnableHDR()
HDRExposure(0.6)


')


Krischan(Posted 2014) [#135]
BLaBZ, it doesnt work. Perhaps you should investigate my project - I created a smaller version for you, the textures have been resized and you can switch with "R" between vanilla and plus version.

Download


RustyKristi(Posted 2015) [#136]
hey guys, I hope it's not too late but I did try this minib3dplus mod and it works. I copied the updated glew files with the link provided and rebuild it.

Any minib3d app now shows this warning:


Warning: resolving _glewInit by linking to _glewInit@0
Use --enable-stdcall-fixup to disable these warnings
Use --disable-stdcall-fixup to disable these fixups



the first example did compile and run only in IDE but running the standalone always quickly exits.

Any ideas?


Streaksy(Posted 2016) [#137]
This has blown me away... but I can't use it in my main project because it treats vertex-coloured meshes as if every vertex is black.

Also, programs work from IDE but just instantly exit if you run the EXE.

Also, it has a big obnoxious "DEMO" on the screen. :P

Would have loved to have used the ambient occlusion. It looks great in test programs.


Streaksy(Posted 2016) [#138]
Oh, and the closer I am to geometry, the darker it is. I really have to stand WAY back from the map to stop everything being weirdly dim. And I may be mistaken but there's no fog...