fenomas / noa

Experimental voxel game engine.
MIT License
619 stars 91 forks source link

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

Open ghost opened 3 years ago

ghost commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

warpspeed

GUYS NOA ENGINE NEEDS THIS UPDATE BEFORE 2021

sourcerose commented 3 years ago

Could this help? https://doc.babylonjs.com/advanced_topics/introToShaders/shaderCodeInBjs

sourcerose commented 3 years ago

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 commented 3 years ago

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

ghost commented 3 years ago

Thank lol check it out

sourcerose commented 3 years ago

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

sourcerose commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

sourcerose commented 3 years ago

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 commented 3 years ago

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

ghost commented 3 years ago

Operation warp speed underway lol

JonJon565 commented 9 months ago

Operation warp speed underway lol

Hi Ghost ;)