Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operation Warp speed , NOA ENGINE give me my christmas present before 2021 #139

Open
ghost opened this issue Dec 8, 2020 · 16 comments
Open

Comments

@ghost
Copy link

ghost commented Dec 8, 2020

Guys all users of Noa Engine , WE NEED cave shadows !!!!!!!!!!!!

cave

as per this youtube channel https://www.youtube.com/watch?v=aY3yP3T1vzU&list=PLVsTSlfj0qsWEJ-5eMtXsYp03Y9yF1dEn&index=15

we need SHADER not a light , guys I dont know how to make a shader in babylonjs , Noa community please unite and tackle this challenge before 2021 , can someone help me with a light SHADER . NOA community lets unite .

@ghost
Copy link
Author

ghost commented Dec 8, 2020

heres the shader code

Shader "Minecraft/Blocks" {

Properties {
	_MainTex ("Block Texture Atlas", 2D) = "white" {}
}

SubShader {
	
	Tags {"RenderType"="Opaque"}
	LOD 100
	Lighting Off

	Pass {
	
		CGPROGRAM
			#pragma vertex vertFunction
			#pragma fragment fragFunction
			#pragma target 2.0

			#include "UnityCG.cginc"

			struct appdata {
			
				float4 vertex : POSITION;
				float2 uv : TEXCOORD0;
				float4 color : COLOR;

			};

			struct v2f {
			
				float4 vertex : SV_POSITION;
				float2 uv : TEXCOORD0;
				float4 color : COLOR;

			};

			sampler2D _MainTex;
			float GlobalLightLevel;
			float minGlobalLightLevel;
			float maxGlobalLightLevel;

			v2f vertFunction (appdata v) {
			
				v2f o;

				o.vertex = UnityObjectToClipPos(v.vertex);
				o.uv = v.uv;
				o.color = v.color;

				return o;

			}

			fixed4 fragFunction (v2f i) : SV_Target {
			
				fixed4 col = tex2D (_MainTex, i.uv);

				float shade = (maxGlobalLightLevel - minGlobalLightLevel) * GlobalLightLevel + minGlobalLightLevel;
				shade *= i.color.a;
				shade = clamp (1 - shade, minGlobalLightLevel, maxGlobalLightLevel);

				//clip(col.a - 1);
				col = lerp(col, float4(0, 0, 0, 1), shade);

				return col;

			}

			ENDCG

	}


}

}

@ghost
Copy link
Author

ghost commented Dec 8, 2020

other chader code : Shader "Minecraft/Transparent Blocks" {

Properties {
	_MainTex ("Block Texture Atlas", 2D) = "white" {}
}

SubShader {
	
	Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
	LOD 100
	Lighting Off

	Pass {
	
		CGPROGRAM
			#pragma vertex vertFunction
			#pragma fragment fragFunction
			#pragma target 2.0

			#include "UnityCG.cginc"

			struct appdata {
			
				float4 vertex : POSITION;
				float2 uv : TEXCOORD0;
				float4 color : COLOR;

			};

			struct v2f {
			
				float4 vertex : SV_POSITION;
				float2 uv : TEXCOORD0;
				float4 color : COLOR;

			};

			sampler2D _MainTex;
			float GlobalLightLevel;
			float minGlobalLightLevel;
			float maxGlobalLightLevel;

			v2f vertFunction (appdata v) {
			
				v2f o;

				o.vertex = UnityObjectToClipPos(v.vertex);
				o.uv = v.uv;
				o.color = v.color;

				return o;

			}

			fixed4 fragFunction (v2f i) : SV_Target {
			
				fixed4 col = tex2D (_MainTex, i.uv);

				float shade = (maxGlobalLightLevel - minGlobalLightLevel) * GlobalLightLevel + minGlobalLightLevel;
				shade *= i.color.a;
				shade = clamp (1 - shade, minGlobalLightLevel, maxGlobalLightLevel);

				clip(col.a - 1);
				col = lerp(col, float4(0, 0, 0, 1), shade);

				return col;

			}

			ENDCG

	}


}

}

@ghost
Copy link
Author

ghost commented Dec 8, 2020

warpspeed

GUYS NOA ENGINE NEEDS THIS UPDATE BEFORE 2021

@sourcerose
Copy link

@sourcerose
Copy link

Or maybe something like this? Pretty sure MC uses GLSL shader code so it would be pretty easy. https://github.com/saaratrix/glsl-babylonshader

@sourcerose
Copy link

This is also seems really useful:
https://forum.unity.com/threads/export-glsl-shader.377982/

@ghost
Copy link
Author

ghost commented Dec 18, 2020

Thank lol check it out

@sourcerose
Copy link

Ok, I was able to make a basic white shader. However, I'm not experienced enough to develop Useful Shader Code.
image

@sourcerose
Copy link

I dont think you should try to use shaders to acomplish this. Something like https://doc.babylonjs.com/divingDeeper/lights/shadows will make it easier

@ghost
Copy link
Author

ghost commented Dec 18, 2020

Can you make a black shader then , global illumination is in the bag , the black color will be controlled by a float inside the game , send me the code I'll try to help

@ghost
Copy link
Author

ghost commented Dec 18, 2020

Here's were I got the info on wath kind of shader we need https://www.youtube.com/watch?v=u85U0wVkN0Y&list=PLVsTSlfj0qsWEJ-5eMtXsYp03Y9yF1dEn&index=16

@sourcerose
Copy link

sourcerose commented Dec 18, 2020

As I said, I'm not very experienced with Shader Code. However, I can try

@sourcerose
Copy link

sourcerose commented Dec 18, 2020

Ok,
Here's what I got:

BABYLON.Effect.ShadersStore["customVertexShader"] = "precision highp float;\r\n" +

"// Attributes\r\n" +
    "attribute vec3 position;\r\n" +
    "attribute vec2 uv;\r\n" +

"// Uniforms\r\n" +
    "uniform mat4 worldViewProjection;\r\n" +

"// Varying\r\n" +
    "varying vec2 vUV;\r\n" +

"void main(void) {\r\n" +
    "    gl_Position = worldViewProjection * vec4(position, 1.0);\r\n" +

"    vUV = uv;\r\n" +
    "}\r\n";

BABYLON.Effect.ShadersStore["customFragmentShader"] = "precision highp float;\r\n" +

"varying vec2 vUV;\r\n" +

"uniform sampler2D textureSampler;\r\n" +

"void main(void) {\r\n" +
    "    gl_FragColor = vec4(0,0,0, 1.0);\r\n" +
    "}\r\n";


// Compile
var shaderMaterial = new BABYLON.ShaderMaterial("shader", scene, {
    vertex: "custom",
    fragment: "custom",
}, {
    attributes: ["position", "normal", "uv"],
    uniforms: ["world", "worldView", "worldViewProjection", "view", "projection"]
});

shaderMaterial.setFloat("time", 0);
shaderMaterial.setVector3("cameraPosition", BABYLON.Vector3.Zero());
shaderMaterial.backFaceCulling = false;
var meshes = noa.rendering.getScene().meshes;
for (var index = 0; index < meshes.length; index++) {
    var mesh = meshes[index];
    mesh.material = shaderMaterial;
}

try typing that in console of your game

@ghost
Copy link
Author

ghost commented Dec 18, 2020

Thank you , Im in Canada it's 2 am have to sleep now , thank you for the first step :)

@ghost
Copy link
Author

ghost commented Dec 18, 2020

Operation warp speed underway lol

@JonJon565
Copy link

Operation warp speed underway lol

Hi Ghost ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants