Object displaying no visible illumination

Recently, I've been experimenting with this project, and after some trial and error, I've managed to get things working to some extent. As a novice in JavaScript, I'm unsure if the issue I'm facing has a simple solution. The problem is that I can't seem to get the light effects on the moon to appear as they do in the original version.

Here's what I've accomplished so far:

<script type="text/javascript" id="mainCode">

var container, 
    renderer, 
    scene, 
    camera, 
    mesh,
    light = {
       speed: 0.1,
       distance: 1000,
       position: new THREE.Vector3(0, 0, 0),
       orbit: function (center, time) {
            this.position.x =
                (center.x + this.distance) * Math.sin(time * -this.speed);

            this.position.z =
                (center.z + this.distance) * Math.cos(time * this.speed);
        }
    },
    clock,
    controls;


        init();

        function init() {

        // selecting the container element from the DOM
        container = document.getElementById( "container" );


        scene = new THREE.Scene();

        var fov = 35,
        aspect = window.innerWidth / window.innerHeight,
        near = 1,
        far = 65536;

        renderer = new THREE.WebGLRenderer({antialias: true, preserveDrawingBuffer: true});   
        renderer.setClearColor(0x000000, 1);
        renderer.setSize(window.innerWidth, window.innerHeight);
        container.appendChild( renderer.domElement );

        camera = new THREE.PerspectiveCamera(fov, aspect, near, far);
        camera.position.set(0, 0, 800);

        scene.add(camera);

        controls = new THREE.TrackballControls(camera);
        controls.rotateSpeed = 0.5;
        controls.dynamicDampingFactor = 0.5;

        clock = new THREE.Clock();

        var radius = 100;
        var xSegments = 50;
        var ySegments = 50;
        var geo = new THREE.SphereGeometry(radius, xSegments, ySegments);

        var mat = new THREE.ShaderMaterial({
            uniforms: {
                lightPosition: {
                    type: 'v3',
                    value: light.position
                },
                textureMap: {
                    type: 't',
                    value: THREE.ImageUtils.loadTexture( "img/maps/moon.jpg" )
                },
                normalMap: {
                    type: 't',
                    value: THREE.ImageUtils.loadTexture( "img/maps/normal.jpg" )
                },
                uvScale: {
                    type: 'v2',
                    value: new THREE.Vector2(1.0, 1.0)

                }


            },
            vertexShader:document.getElementById('vertexShader').textContent,
            fragmentShader:document.getElementById('fragmentShader').textContent

        });

          mesh = new THREE.Mesh(geo, mat);     
          mesh.geometry.computeTangents();
          mesh.position.set(0, 0, 0);
          mesh.rotation.set(0, 180, 0);
          scene.add(mesh);


    }

    function onWindowResize() {
        renderer.setSize(window.innerWidth, window.innerHeight);
        camera.aspect = window.innerWidth / window.innerHeight;
        camera.updateProjectionMatrix();
    }

    function animate() {
        requestAnimationFrame(animate);
        light.orbit(mesh.position, clock.getElapsedTime());
        controls.update(camera);
        renderer.render(scene, camera);

    }
    animate();

    window.addEventListener('resize', onWindowResize, false);


</script>

Answer №1

Your scene currently lacks any lighting elements. The moon example utilizes a custom shader that may be more complex than necessary for your needs at the moment. Consider adding a standard Three light to your scene instead by visiting the following link:

var light = new THREE.PointLight( 0xff0000, 1, 100 );
light.position.set( 50, 50, 50 );
scene.add( light );

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Encountering an issue with Next.js React SSR using styled-jsx: unable to access the 'state' property as

I've come across a problem that I can't seem to figure out. Despite my attempts to search for a solution here, I haven't been able to help myself. I'm new to javascript and react, so please bear with me. Issue: I'm using React (1 ...

Creating a multi-level signup page in Angular 4 using Bootstrap

Currently, I am working with angular 4 and bootstrap 4 to create a multi-level sign-up page. One of the challenges I am encountering is how to properly include a JavaScript file into my angular project. import '../../../assets/js/js/multiform.js&apo ...

What causes the scrollbar to not extend to the bottom when connected to another scrollbar via a JavaScript equation?

I have been working on a code that involves multiple scrollbars that are all linked together. When you move one scrollbar, the other two will move proportionally. However, due to differences in width, the scroller doesn't always reach the end of the s ...

Using jQuery Datatables fnReloadAjax successfully triggers a reload of the data, however, it

In my jQuery datatable, I am utilizing the code below to refresh the data: $(".unread-rows").click( function(e) { e.preventDefault(); message_table.fnReloadAjax("/letters/ajax/inbox/1"); message_table.fnDraw(); $(this).addClass("active").s ...

Is javascript or ajax the best choice for updating a database in asp.net mvc?

I need help with updating a row in my database based on a change event from a dropdown list. I am not sure whether to use javascript or ajax for this purpose as I want to avoid page refresh. Any recommendations on which method is best and where I can find ...

The Angular $rootScope.user.userMessage throws an error stating that it is not an object

I am encountering an issue: Error: The object '$rootScope.user.userMessage' is not defined. (evaluating 'typeof $rootScope.user.userMessage') This error arises from the following code snippet: if (typeof($rootScope.user.userMessage ...

Avoid inputting various symbols into the select2 field

I recently upgraded my select input to use select2: <select id="indivCitizen" multiple="multiple"> <option value=""></option> </select> To fetch data dynamically and enhance user experience: $(doc ...

Activate the jQuery UI datepicker with a trigger

Within my code, I have a span element that displays a date in the format mm/dd/yyyy. <span class="editableDateTxt">06/10/2014</span> My goal is to have an inline editable date popup or utilize jQuery UI's datepicker when this span elemen ...

How to delete the final element in a stack trace string using Javascript

Currently, I am working on a Javascript logger that includes the stack trace in error messages. The implementation looks like this: function logMessage(logMessage) { let stackTrace = new Error().stack; logMessage.stackTrace = stackTrace; ... } Whi ...

The Route.go function is ineffective when used in form submission

Hey there! I'm new to the world of meteor and javascript, currently working on a fun little app project. My tool of choice is meteor with ionic. Here's a snippet from my simple form: <form> .... <label class="item item- ...

The specified class is not found in the type 'ILineOptions' for fabricjs

Attempting to incorporate the solution provided in this answer for typescript, , regarding creating a Line. The code snippet from the answer includes the following options: var line = new fabric.Line(points, { strokeWidth: 2, fill: '#999999', ...

How to interact with the parent controller when including HTML using ng-include

I am trying to call a function in a controller from an ng-included HTML file that includes a directive with its own template. For example, the parent HTML template has this controller: <div ng-controller="profileCtrl"> <div ng-include src="p ...

The ng-repeat track by function is not functioning as expected, displaying slow performance and continuing to create $$hashKey

In my code, I have an ng-repeat setup like this: ng-repeat="article in main[main.mode].primary | orderBy: main[main.mode].primary.filter.order track by article.url" The main[main.mode].primary array contains the data and the .filter.order string is used ...

Is it possible to implement a setInterval on the socket.io function within the componentDidMount or componentDidUpdate methods

I'm currently working on a website where I display the number of online users. However, I've encountered an issue with the online user counter not refreshing automatically. When I open the site in a new tab, the counter increases in the new tab b ...

Execute a single test from a particular test suite using Jest

Within my file named "test-file-1", I have several describes (test suites) with distinct names, each containing tests that may share similar names across different test suites. In order to run a single test suite or test, I enter the following command: n ...

Unable to access an element using jquery

This is an example of an HTML file: <div id ="main"> </div> Here is the JavaScript code: //creating a new div element var divElem = $('<div class="divText"></div>'); //creating an input element inside the div var i ...

Is there a way to retrieve an audio file using npm request in a Node.js environment?

I'm dealing with a piece of code that retrieves raw data for me requestPromisePost(options) { return new Promise((resolve, reject) => { request(options, function (error, response,dfdf) { if (error) return ...

Comparing partial strings using Mongodb aggregation techniques

After populating my MongoDB database with around 5000 questions, I am now looking to group questions together that are partially similar, ranging from 70% to 80% similarity, and then send them to the frontend. I attempted to achieve this using the pipelin ...

Widget Issue: Problem with Setting jQuery Datepicker Format to European Style

I could really use some assistance with this issue. My goal is to display the check-in and check-out dates in European format (dd/mm/yy) within the input field on this specific page: (username: 'numberone' ; pass: 'num270514'). When t ...

The implementation of LightMap in three.js consistently results in a dimming effect on

Have you ever noticed that when adding a light map to a material, it always seems to make it darker? This seems to happen even with a completely white texture. Is there a way around this? Perhaps there is a way to darken only the pixels underneath the gr ...