Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Has anyone tried ChatGPT to write AGK code yet?

Author
Message
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 1st Feb 2023 20:57 Edited at: 1st Feb 2023 22:27
So I've been messing around with ChatGPT, and it does a worryingly good job of AppGameKit code, though it favours the C version.

However tonight I decided to try it with some shaders and it was.....better than expected. The bold sentences below are exactly what I typed....

write me a glsl shader for version 1.0 that does 3d projection shadows for a point light
Here's an example of a GLSL shader for version 1.0 that implements 3D projection shadows for a point light:


In this shader, the lightPosition uniform variable is the position of the point light in world space. The shadowMap uniform variable is a 2D texture that stores the shadow map for the point light. The shadowStrength uniform variable is a scaler that determines the strength of the shadows. The ShadowCoord varying variable holds the shadow coordinate for the current fragment, which is used to sample the shadow map.

In the main function, the shadow coordinate is divided by its w component to get the texture coordinate. The distanceFromLight variable holds the distance from the light to the surface stored in the shadow map for the current fragment. The shadow variable is then calculated by comparing the distance from the light to the surface with the depth value stored in the shadow map. If the distance is greater than the depth, the shadow strength is set to 0.5, otherwise it is set to 1.0.

Finally, the diffuse lighting is calculated by multiplying the shadow strength by the shadowStrength uniform variable and the resulting color is set as the output color for the fragment.




Comment the code to explain what each line does
Here's a commented version of the code for the 3D projection shadow shader:




add in soft shadows
Here's an example of a GLSL shader for version 1.0 that implements soft 3D projection shadows for a point light:


In this version of the shader, a new uniform variable shadowSmoothness has been added. This variable determines the smoothness of the transition from lit to shadowed. The shadow strength is now calculated by subtracting the difference between the distanceFromLight and shadowCoordinateWdivide.z from 1.0 and clamping the result between 0.0 and 1.0. The result is then multiplied by shadowStrength to determine the final diffuse lighting for the fragment.


how can that code be made faster?
Here are a few ways to optimize the code for better performance:

Reduce texture lookups: You can reduce the number of texture lookups by using a higher-resolution shadow map or implementing a variance shadow map instead of a traditional shadow map. This will help reduce the amount of aliasing and reduce the number of times you need to sample the shadow map.

Use a lower-precision texture format: If your GPU supports it, you can use a lower-precision texture format (such as GL_R16F or GL_R32F) for the shadow map, which will reduce the amount of memory bandwidth required to sample the shadow map.

Use an efficient shadow sampling algorithm: Instead of using a simple texture2D lookup to sample the shadow map, you can use more advanced techniques such as percentage-closer filtering (PCF) or an exponential variance shadow map (EVSM) to improve the quality of the shadows and reduce the number of required texture lookups.

Use hardware-accelerated depth comparisons: If your GPU supports it, you can use the shadow2DProj function to perform hardware-accelerated depth comparisons between the light's depth and the depth stored in the shadow map, which can be faster than performing the depth comparison in the fragment shader.

Use the right data type: Use the right data type for your uniform variables. For example, use float instead of vec3 when possible, and use int instead of float when an integer value is sufficient.

By implementing these optimizations, you can improve the performance of your shader and achieve smoother and more accurate shadows.


can you write me a pbr shader for glsl version 1.0 that includes the shadow shader from above
Here's an example of a PBR (physically based rendering) shader for GLSL version 1.0 that includes the shadow shader from above:


In this shader, the light direction, view direction, and halfway direction vectors are calculated based on the fragment's position, normal, and the camera and light positions. The diffuse, specular, and ambient contributions are then calculated using the light direction, normal, albedo, metallic, roughness, and AO (ambient occlusion)
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 1st Feb 2023 22:20 Edited at: 1st Feb 2023 22:21
only skimmed your post sp far (as it's a bit of a "wall of text" without code tag usage) but i do appreciate the notion of using it for shaders which i hadn't considered.

otherwise, limited experience with ChatGPT + AppGameKit and i wasn't impressed @ first glance while intending to continue exploring the combination.

still, looking forward to learning how it can further (& augment) my current AppGameKit prowess. and, i'll re-read (and test) the above when i have time.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 1st Feb 2023 22:26
I've not had much luck, it keeps referencing back to the C T2 code, and the mvp matrix. I understand the mvp is the Model-View-Projection matrix, however I have no idea how to do that in AppGameKit, using T1. Or even using T2.

I tried using agk_World * agk_Proj * agk_View but no luck.

It's good for C code and giving you pointers, but it's certainly not going to replace an AppGameKit coder anytime soon.

Any thoughts on an mpv matrix in an AppGameKit shader?
James H
16
Years of Service
User Offline
Joined: 21st Apr 2007
Location: St Helens
Posted: 2nd Feb 2023 00:21 Edited at: 2nd Feb 2023 00:57
Okay so I have next to zero clue about actually writing shaders but have noticed some MPV matrix/vector stuff in the static/animated vertex shader files in the community shadow shader which is ultimately a directional light of which 6 would make up a point light? https://forum.thegamecreators.com/thread/217568
Might help, might not, might be a case of you lot facepalming at my words lol

Edit: I know this is classic board but if you happen to use studio for any reason then don't forget to add #renderer"Basic" as needs inverting for vulkan and prefer best is default in studio - I mention as you have mentioned PBR which there is a demo of in studio using lightmaps
Win 10 Home 64, Intel(R) Core(TM) i5-10300H, 8GB DDR4, NVidia GeForce GTX 1650 4GB GDDR6
smerf
19
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 6th Feb 2023 17:10
ive tried it it references alot of dbpro commands, at best i think it could write a simple loop and build a type. that said u can ask for code in other language that are similiar for advanced maths ect and convert it easy enough

Login to post a reply

Server time is: 2024-04-16 14:11:07
Your offset time is: 2024-04-16 14:11:07